Search in sources :

Example 1 with ResourceType

use of org.alfresco.service.cmr.invitation.Invitation.ResourceType in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method approveSiteMembershipRequest.

@Override
public void approveSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipApproval siteMembershipApproval) {
    SiteInfo siteInfo = sites.validateSite(siteId);
    if (siteInfo == null) {
        throw new EntityNotFoundException(siteId);
    }
    // Set the site id to the short name (to deal with case sensitivity issues with
    // using the siteId from the url)
    siteId = siteInfo.getShortName();
    // Validate invitation.
    Invitation invitation = getSiteInvitation(inviteeId, siteId);
    if (invitation == null || !(invitation instanceof ModeratedInvitation)) {
        throw new RelationshipResourceNotFoundException(siteId, inviteeId);
    }
    ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
    ResourceType resourceType = moderatedInvitation.getResourceType();
    if (!resourceType.equals(ResourceType.WEB_SITE) || !SiteVisibility.MODERATED.equals(siteInfo.getVisibility())) {
        // note: security, no indication that this has a different visibility
        throw new RelationshipResourceNotFoundException(siteId, inviteeId);
    }
    try {
        invitationService.approve(invitation.getInviteId(), "");
    } catch (InvitationExceptionForbidden ex) {
        throw new PermissionDeniedException();
    }
    // approval role differs from default one.
    if (siteMembershipApproval != null && !(siteMembershipApproval.getRole() == null || siteMembershipApproval.getRole().isEmpty())) {
        String role = siteMembershipApproval.getRole();
        // Check if role chosen by moderator differs from the invite role.
        if (!moderatedInvitation.getRoleName().equals(role)) {
            String currentUserId = AuthenticationUtil.getFullyAuthenticatedUser();
            // Update invitation with new role.
            try {
                addSiteMembership(invitation.getInviteeUserName(), siteId, role, currentUserId);
            } catch (UnknownAuthorityException e) {
                logger.debug("addSiteMember:  UnknownAuthorityException " + siteId + " person " + invitation.getInviteId() + " role " + role);
                throw new InvalidArgumentException("Unknown role '" + role + "'");
            }
        }
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) InvitationExceptionForbidden(org.alfresco.service.cmr.invitation.InvitationExceptionForbidden) ResourceType(org.alfresco.service.cmr.invitation.Invitation.ResourceType) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException)

Example 2 with ResourceType

use of org.alfresco.service.cmr.invitation.Invitation.ResourceType in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method getSiteMembershipRequest.

private SiteMembershipRequest getSiteMembershipRequest(ModeratedInvitation moderatedInvitation, boolean includePersonDetails) {
    SiteMembershipRequest siteMembershipRequest = null;
    ResourceType resourceType = moderatedInvitation.getResourceType();
    if (resourceType.equals(ResourceType.WEB_SITE)) {
        final String siteId = moderatedInvitation.getResourceName();
        SiteInfo siteInfo = AuthenticationUtil.runAsSystem(new RunAsWork<SiteInfo>() {

            @Override
            public SiteInfo doWork() throws Exception {
                SiteInfo siteInfo = sites.validateSite(siteId);
                return siteInfo;
            }
        });
        if (siteInfo == null) {
            // site does not exist
            throw new EntityNotFoundException(siteId);
        }
        if (siteInfo.getVisibility().equals(SiteVisibility.MODERATED)) {
            // return a site membership request only if this is a moderated site
            siteMembershipRequest = new SiteMembershipRequest();
            String title = siteInfo.getTitle();
            siteMembershipRequest.setTitle(title);
            siteMembershipRequest.setId(siteId);
            siteMembershipRequest.setMessage(moderatedInvitation.getInviteeComments());
            siteMembershipRequest.setCreatedAt(moderatedInvitation.getCreatedAt());
            siteMembershipRequest.setModifiedAt(moderatedInvitation.getModifiedAt());
            if (includePersonDetails) {
                Person person = people.getPerson(moderatedInvitation.getInviteeUserName());
                siteMembershipRequest.setPerson(person);
            }
        }
    } else {
        logger.warn("Unexpected resource type " + resourceType + " for site membership request");
    }
    return siteMembershipRequest;
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ResourceType(org.alfresco.service.cmr.invitation.Invitation.ResourceType) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest) Person(org.alfresco.rest.api.model.Person) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)

Example 3 with ResourceType

use of org.alfresco.service.cmr.invitation.Invitation.ResourceType in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method rejectSiteMembershipRequest.

@Override
public void rejectSiteMembershipRequest(String siteId, String inviteeId, SiteMembershipRejection siteMembershipRejection) {
    SiteInfo siteInfo = sites.validateSite(siteId);
    if (siteInfo == null) {
        throw new EntityNotFoundException(siteId);
    }
    // set the site id to the short name (to deal with case sensitivity issues with
    // using the siteId from the url)
    siteId = siteInfo.getShortName();
    // Validate invitation.
    Invitation invitation = getSiteInvitation(inviteeId, siteId);
    if (invitation == null || !(invitation instanceof ModeratedInvitation)) {
        throw new RelationshipResourceNotFoundException(siteId, inviteeId);
    }
    ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
    ResourceType resourceType = moderatedInvitation.getResourceType();
    if (!resourceType.equals(ResourceType.WEB_SITE) || !SiteVisibility.MODERATED.equals(siteInfo.getVisibility())) {
        // note: security, no indication that this has a different visibility
        throw new RelationshipResourceNotFoundException(siteId, inviteeId);
    }
    String reason = null;
    if (siteMembershipRejection != null && !(siteMembershipRejection.getComment() == null || siteMembershipRejection.getComment().isEmpty())) {
        reason = siteMembershipRejection.getComment();
    }
    try {
        invitationService.reject(invitation.getInviteId(), reason);
    } catch (InvitationExceptionForbidden ex) {
        throw new PermissionDeniedException();
    }
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) InvitationExceptionForbidden(org.alfresco.service.cmr.invitation.InvitationExceptionForbidden) ResourceType(org.alfresco.service.cmr.invitation.Invitation.ResourceType) PermissionDeniedException(org.alfresco.rest.framework.core.exceptions.PermissionDeniedException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)

Aggregations

EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)3 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)3 ResourceType (org.alfresco.service.cmr.invitation.Invitation.ResourceType)3 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)3 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 Invitation (org.alfresco.service.cmr.invitation.Invitation)2 InvitationExceptionForbidden (org.alfresco.service.cmr.invitation.InvitationExceptionForbidden)2 ModeratedInvitation (org.alfresco.service.cmr.invitation.ModeratedInvitation)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 Person (org.alfresco.rest.api.model.Person)1 SiteMembershipRequest (org.alfresco.rest.api.model.SiteMembershipRequest)1