Search in sources :

Example 1 with ModeratedInvitation

use of org.alfresco.service.cmr.invitation.ModeratedInvitation 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 ModeratedInvitation

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

the class SiteMembershipRequestsImpl method getSiteMembershipRequest.

public SiteMembershipRequest getSiteMembershipRequest(String inviteeId, final String siteId) {
    inviteeId = people.validatePerson(inviteeId);
    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 RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    if (siteInfo.getVisibility().equals(SiteVisibility.MODERATED)) {
        // set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
        String normalizedSiteId = siteInfo.getShortName();
        Invitation invitation = getSiteInvitation(inviteeId, normalizedSiteId);
        if (invitation == null) {
            // no such invitation
            throw new RelationshipResourceNotFoundException(inviteeId, normalizedSiteId);
        }
        if (invitation instanceof ModeratedInvitation) {
            ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
            SiteMembershipRequest siteInvite = getSiteMembershipRequest(moderatedInvitation);
            return siteInvite;
        } else {
            throw new InvalidArgumentException("Expected moderated invitation");
        }
    } else {
        // non-moderated sites cannot appear in a site membership request, so throw an exception
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
}
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) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest) 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 ModeratedInvitation

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

the class SiteMembershipRequestsImpl method updateSiteMembershipRequest.

@Override
public SiteMembershipRequest updateSiteMembershipRequest(String inviteeId, final SiteMembershipRequest siteInvite) {
    SiteMembershipRequest updatedSiteInvite = null;
    inviteeId = people.validatePerson(inviteeId, true);
    String siteId = siteInvite.getId();
    SiteInfo siteInfo = sites.validateSite(siteId);
    if (siteInfo == null) {
        // site does not exist
        throw new RelationshipResourceNotFoundException(inviteeId, 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();
    String message = siteInvite.getMessage();
    if (message == null) {
        // the invitation service ignores null messages so convert to an empty message.
        message = "";
    }
    try {
        ModeratedInvitation updatedInvitation = invitationService.updateModeratedInvitation(inviteeId, siteId, message);
        if (updatedInvitation == null) {
            throw new RelationshipResourceNotFoundException(inviteeId, siteId);
        }
        updatedSiteInvite = getSiteMembershipRequest(updatedInvitation);
    } catch (InvitationExceptionNotFound e) {
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    if (updatedSiteInvite == null) {
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    return updatedSiteInvite;
}
Also used : RelationshipResourceNotFoundException(org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) InvitationExceptionNotFound(org.alfresco.service.cmr.invitation.InvitationExceptionNotFound) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest)

Example 4 with ModeratedInvitation

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

the class SiteMembershipRequestsImpl method toSiteMembershipRequests.

private List<SiteMembershipRequest> toSiteMembershipRequests(List<Invitation> invitations, boolean includePersonDetails) {
    List<SiteMembershipRequest> siteMembershipRequests = new ArrayList<SiteMembershipRequest>(invitations.size());
    for (Invitation invitation : invitations) {
        if (invitation instanceof ModeratedInvitation) {
            ModeratedInvitation moderatedInvitation = (ModeratedInvitation) invitation;
            SiteMembershipRequest siteMembershipRequest = getSiteMembershipRequest(moderatedInvitation, includePersonDetails);
            if (siteMembershipRequest != null) {
                // note: siteMembershipRequest may be null if the site is now no longer a moderated site
                // or if the invitation is malformed and does not refer to a site.
                siteMembershipRequests.add(siteMembershipRequest);
            }
        } else {
        // just ignore, shouldn't happen because getSiteInvitations filters by ModeratedInvitation
        }
    }
    return siteMembershipRequests;
}
Also used : ArrayList(java.util.ArrayList) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) Invitation(org.alfresco.service.cmr.invitation.Invitation) ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest)

Example 5 with ModeratedInvitation

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

the class SiteMembershipRequestsImpl method inviteToModeratedSite.

private SiteMembershipRequest inviteToModeratedSite(final String message, final String inviteeId, final String siteId, final String inviteeRole) {
    ModeratedInvitation invitation = invitationService.inviteModerated(message, inviteeId, ResourceType.WEB_SITE, siteId, inviteeRole);
    SiteMembershipRequest ret = new SiteMembershipRequest();
    ret.setId(siteId);
    ret.setMessage(message);
    ret.setCreatedAt(invitation.getCreatedAt());
    return ret;
}
Also used : ModeratedInvitation(org.alfresco.service.cmr.invitation.ModeratedInvitation) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest)

Aggregations

ModeratedInvitation (org.alfresco.service.cmr.invitation.ModeratedInvitation)7 Invitation (org.alfresco.service.cmr.invitation.Invitation)5 SiteMembershipRequest (org.alfresco.rest.api.model.SiteMembershipRequest)4 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)4 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)3 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)3 ArrayList (java.util.ArrayList)2 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 ResourceType (org.alfresco.service.cmr.invitation.Invitation.ResourceType)2 InvitationExceptionForbidden (org.alfresco.service.cmr.invitation.InvitationExceptionForbidden)2 ParseException (java.text.ParseException)1 List (java.util.List)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 TestSite (org.alfresco.rest.api.tests.RepoService.TestSite)1 ListResponse (org.alfresco.rest.api.tests.client.PublicApiClient.ListResponse)1 Paging (org.alfresco.rest.api.tests.client.PublicApiClient.Paging)1 PublicApiException (org.alfresco.rest.api.tests.client.PublicApiException)1