use of org.alfresco.service.cmr.security.AuthorityType in project acs-community-packaging by Alfresco.
the class BaseInviteUsersWizard method finishImpl.
/**
* @see org.alfresco.web.bean.dialog.BaseDialogBean#finishImpl(javax.faces.context.FacesContext, java.lang.String)
*/
@Override
protected String finishImpl(FacesContext context, String outcome) throws Exception {
User user = Application.getCurrentUser(context);
String from = (String) this.getNodeService().getProperty(user.getPerson(), ContentModel.PROP_EMAIL);
if (from == null || from.length() == 0) {
// if the user does not have an email address get the default one from the config service
from = Application.getClientConfig(context).getFromEmailAddress();
}
// get the Space to apply changes too
NodeRef nodeRef = this.getNode().getNodeRef();
// set permissions for each user and send them a mail
for (int i = 0; i < this.userGroupRoles.size(); i++) {
UserGroupRole userGroupRole = this.userGroupRoles.get(i);
String authority = userGroupRole.getAuthority();
// find the selected permission ref from it's name and apply for the specified user
Set<String> perms = getPermissionsForType();
for (String permission : perms) {
if (userGroupRole.getRole().equals(permission)) {
this.getPermissionService().setPermission(nodeRef, authority, permission, true);
break;
}
}
// Create the mail message for sending to each User
if (NOTIFY_YES.equals(this.notify)) {
// if User, email then, else if Group get all members and email them
AuthorityType authType = AuthorityType.getAuthorityType(authority);
if (authType.equals(AuthorityType.USER)) {
if (this.getPersonService().personExists(authority) == true) {
this.mailHelper.notifyUser(this.getPersonService().getPerson(authority), nodeRef, from, userGroupRole.getRole());
}
} else if (authType.equals(AuthorityType.GROUP)) {
// else notify all members of the group
Set<String> users = this.getAuthorityService().getContainedAuthorities(AuthorityType.USER, authority, false);
for (String userAuth : users) {
if (this.getPersonService().personExists(userAuth) == true) {
this.mailHelper.notifyUser(this.getPersonService().getPerson(userAuth), nodeRef, from, userGroupRole.getRole());
}
}
}
}
}
// reset max users flag
this.maxUsersReturned = false;
return outcome;
}
use of org.alfresco.service.cmr.security.AuthorityType in project alfresco-remote-api by Alfresco.
the class GroupsImpl method getAuthoritiesInfo.
private PagingResults<AuthorityInfo> getAuthoritiesInfo(AuthorityType authorityType, Boolean isRootParam, String zoneFilter, Set<String> rootAuthorities, Pair<String, Boolean> sortProp, Paging paging) {
PagingResults<AuthorityInfo> pagingResult;
if (isRootParam != null) {
List<AuthorityInfo> groupList;
if (isRootParam) {
// Limit the post processing work by using the already loaded
// list of root authorities.
List<AuthorityInfo> authorities = rootAuthorities.stream().map(this::getAuthorityInfo).filter(auth -> zonePredicate(auth.getAuthorityName(), zoneFilter)).collect(Collectors.toList());
groupList = new ArrayList<>(rootAuthorities.size());
groupList.addAll(authorities);
// Post process sorting - this should be moved to service
// layer. It is done here because sorting is not supported at
// service layer.
AuthorityInfoComparator authorityComparator = new AuthorityInfoComparator(sortProp.getFirst(), sortProp.getSecond());
Collections.sort(groupList, authorityComparator);
} else {
PagingRequest pagingNoMaxItems = new PagingRequest(CannedQueryPageDetails.DEFAULT_PAGE_SIZE);
// Get authorities using canned query but without using
// the requested paginating now because we need to filter out
// the root authorities.
PagingResults<AuthorityInfo> nonPagingResult = authorityService.getAuthoritiesInfo(authorityType, zoneFilter, null, sortProp.getFirst(), sortProp.getSecond(), pagingNoMaxItems);
// Post process filtering - this should be moved to service
// layer. It is done here because filtering by "isRoot" is not
// supported at service layer.
groupList = nonPagingResult.getPage();
if (groupList != null) {
for (Iterator<AuthorityInfo> i = groupList.iterator(); i.hasNext(); ) {
AuthorityInfo authorityInfo = i.next();
if (!isRootParam.equals(isRootAuthority(rootAuthorities, authorityInfo.getAuthorityName()))) {
i.remove();
}
}
}
}
// Post process paging - this should be moved to service layer.
pagingResult = Util.wrapPagingResults(paging, groupList);
} else {
PagingRequest pagingRequest = Util.getPagingRequest(paging);
// Get authorities using canned query.
pagingResult = authorityService.getAuthoritiesInfo(authorityType, zoneFilter, null, sortProp.getFirst(), sortProp.getSecond(), pagingRequest);
}
return pagingResult;
}
use of org.alfresco.service.cmr.security.AuthorityType in project alfresco-remote-api by Alfresco.
the class GroupsImpl method getGroupMember.
private GroupMember getGroupMember(AuthorityInfo authorityInfo) {
if (authorityInfo == null) {
return null;
}
GroupMember groupMember = new GroupMember();
groupMember.setId(authorityInfo.getAuthorityName());
String authorityDisplayName = authorityInfo.getAuthorityDisplayName();
if (authorityDisplayName == null || authorityDisplayName.isEmpty()) {
authorityDisplayName = authorityService.getAuthorityDisplayName(authorityInfo.getAuthorityName());
}
groupMember.setDisplayName(authorityDisplayName);
String memberType = null;
AuthorityType authorityType = AuthorityType.getAuthorityType(authorityInfo.getAuthorityName());
switch(authorityType) {
case GROUP:
memberType = PARAM_MEMBER_TYPE_GROUP;
break;
case USER:
memberType = PARAM_MEMBER_TYPE_PERSON;
break;
default:
}
groupMember.setMemberType(memberType);
return groupMember;
}
use of org.alfresco.service.cmr.security.AuthorityType in project alfresco-remote-api by Alfresco.
the class GroupsImpl method getGroupMembers.
public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters) {
validateGroupId(groupId, false);
// Not allowed to list all members.
if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
throw new UnsupportedResourceOperationException();
}
Paging paging = parameters.getPaging();
// Retrieve sort column. This is limited for now to sort column due to
// v0 api implementation. Should be improved in the future.
Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
AuthorityType authorityType = null;
// Parse where clause properties.
Query q = parameters.getQuery();
if (q != null) {
MapBasedQueryWalkerOrSupported propertyWalker = new MapBasedQueryWalkerOrSupported(LIST_GROUP_MEMBERS_QUERY_PROPERTIES, null);
QueryHelper.walk(q, propertyWalker);
String memberTypeStr = propertyWalker.getProperty(PARAM_MEMBER_TYPE, WhereClauseParser.EQUALS, String.class);
authorityType = getAuthorityType(memberTypeStr);
}
PagingResults<AuthorityInfo> pagingResult = getAuthoritiesInfo(authorityType, groupId, sortProp, paging);
// Create response.
final List<AuthorityInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
List<GroupMember> groupMembers = new AbstractList<GroupMember>() {
@Override
public GroupMember get(int index) {
AuthorityInfo authorityInfo = page.get(index);
return getGroupMember(authorityInfo);
}
@Override
public int size() {
return page.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, groupMembers, pagingResult.hasMoreItems(), totalItems);
}
Aggregations