Search in sources :

Example 1 with SiteMembershipRequest

use of org.alfresco.rest.api.model.SiteMembershipRequest in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method inviteToPublicSite.

private SiteMembershipRequest inviteToPublicSite(final SiteInfo siteInfo, final String message, final String inviteeId, final String inviteeRole) {
    SiteMembershipRequest siteMembershipRequest = null;
    final String siteId = siteInfo.getShortName();
    NodeRef siteNodeRef = siteInfo.getNodeRef();
    String siteCreator = (String) nodeService.getProperty(siteNodeRef, ContentModel.PROP_CREATOR);
    final String siteNetwork = networksService.getUserDefaultNetwork(siteCreator);
    if (StringUtils.isNotEmpty(siteNetwork)) {
        // MT
        siteMembershipRequest = TenantUtil.runAsUserTenant(new TenantRunAsWork<SiteMembershipRequest>() {

            @Override
            public SiteMembershipRequest doWork() throws Exception {
                return inviteToSite(siteId, inviteeId, inviteeRole, message);
            }
        }, siteCreator, siteNetwork);
    } else {
        siteMembershipRequest = AuthenticationUtil.runAs(new RunAsWork<SiteMembershipRequest>() {

            @Override
            public SiteMembershipRequest doWork() throws Exception {
                return inviteToSite(siteId, inviteeId, inviteeRole, message);
            }
        }, siteCreator);
    }
    return siteMembershipRequest;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) RunAsWork(org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) TenantRunAsWork(org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest)

Example 2 with SiteMembershipRequest

use of org.alfresco.rest.api.model.SiteMembershipRequest in project alfresco-remote-api by Alfresco.

the class SiteMembershipRequestsImpl method createSiteMembershipRequest.

@Override
public SiteMembershipRequest createSiteMembershipRequest(String inviteeId, final SiteMembershipRequest siteInvite) {
    SiteMembershipRequest request = null;
    inviteeId = people.validatePerson(inviteeId, true);
    // Note that the order of error checking is important. The server first needs to check for the status 404
    // conditions before checking for status 400 conditions. Otherwise the server is open to a probing attack.
    String siteId = siteInvite.getId();
    final 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();
    final SiteVisibility siteVisibility = siteInfo.getVisibility();
    if (siteVisibility.equals(SiteVisibility.PRIVATE)) {
        // note: security, no indication that this is a private site
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    // Is the invitee already a member of the site?
    boolean isMember = siteService.isMember(siteId, inviteeId);
    if (isMember) {
        // yes
        throw new InvalidArgumentException(inviteeId + " is already a member of site " + siteId);
    }
    // Is there an outstanding site invite request for the (invitee, site)?
    Invitation invitation = getSiteInvitation(inviteeId, siteId);
    if (invitation != null) {
        // yes
        throw new InvalidArgumentException(inviteeId + " is already invited to site " + siteId);
    }
    final String inviteeRole = DEFAULT_ROLE;
    String message = siteInvite.getMessage();
    if (message == null) {
        // the invitation service ignores null messages so convert to an empty message.
        message = "";
    }
    if (siteVisibility.equals(SiteVisibility.MODERATED)) {
        request = inviteToModeratedSite(message, inviteeId, siteId, inviteeRole);
    } else if (siteVisibility.equals(SiteVisibility.PUBLIC)) {
        request = inviteToPublicSite(siteInfo, message, inviteeId, inviteeRole);
    } else {
        // note: security, no indication that this is a private site
        throw new RelationshipResourceNotFoundException(inviteeId, siteId);
    }
    return request;
}
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) SiteMembershipRequest(org.alfresco.rest.api.model.SiteMembershipRequest) SiteVisibility(org.alfresco.service.cmr.site.SiteVisibility)

Example 3 with SiteMembershipRequest

use of org.alfresco.rest.api.model.SiteMembershipRequest 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 4 with SiteMembershipRequest

use of org.alfresco.rest.api.model.SiteMembershipRequest 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 5 with SiteMembershipRequest

use of org.alfresco.rest.api.model.SiteMembershipRequest 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)

Aggregations

SiteMembershipRequest (org.alfresco.rest.api.model.SiteMembershipRequest)9 ModeratedInvitation (org.alfresco.service.cmr.invitation.ModeratedInvitation)5 RelationshipResourceNotFoundException (org.alfresco.rest.framework.core.exceptions.RelationshipResourceNotFoundException)4 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)4 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)3 Invitation (org.alfresco.service.cmr.invitation.Invitation)3 ArrayList (java.util.ArrayList)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)2 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)2 PermissionDeniedException (org.alfresco.rest.framework.core.exceptions.PermissionDeniedException)2 Date (java.util.Date)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 TenantRunAsWork (org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork)1 Person (org.alfresco.rest.api.model.Person)1 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)1 ResourceType (org.alfresco.service.cmr.invitation.Invitation.ResourceType)1 InvitationExceptionNotFound (org.alfresco.service.cmr.invitation.InvitationExceptionNotFound)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 SiteVisibility (org.alfresco.service.cmr.site.SiteVisibility)1