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 + "'");
}
}
}
}
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;
}
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();
}
}
Aggregations