use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class Organization method isRegistryMaintainer.
/**
* @param org
* @return If the current user is part of the registry admin role for the
* given organization
*/
public static boolean isRegistryMaintainer(Organization org) {
if (new RolePermissionService().isSRA()) {
return true;
}
final SessionIF session = Session.getCurrentSession();
if (session != null) {
Map<String, ServerGeoObjectType> types = org.getGeoObjectTypes();
Set<Entry<String, ServerGeoObjectType>> entries = types.entrySet();
for (Entry<String, ServerGeoObjectType> entry : entries) {
String roleName = RegistryRole.Type.getRM_RoleName(org.getCode(), entry.getKey());
boolean hasRole = session.userHasRole(roleName);
if (hasRole) {
return true;
}
}
return false;
}
return true;
}
use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class ChangeRequestPermissionService method getPermissions.
public Set<ChangeRequestPermissionAction> getPermissions(ChangeRequest cr) {
final RolePermissionService perms = ServiceFactory.getRolePermissionService();
final String orgCode = cr.getOrganizationCode();
final String gotCode = cr.getGeoObjectTypeCode();
ServerGeoObjectType type = null;
if (gotCode != null) {
type = ServerGeoObjectType.get(gotCode, true);
}
HashSet<ChangeRequestPermissionAction> actions = new HashSet<ChangeRequestPermissionAction>();
final AllGovernanceStatus status = cr.getGovernanceStatus();
if (perms.isSRA()) {
actions.addAll(Arrays.asList(ChangeRequestPermissionAction.values()));
actions.remove(ChangeRequestPermissionAction.DELETE);
actions.remove(ChangeRequestPermissionAction.WRITE_CONTRIBUTOR_NOTES);
actions.remove(ChangeRequestPermissionAction.WRITE_DETAILS);
if (status.equals(AllGovernanceStatus.ACCEPTED)) {
actions.remove(ChangeRequestPermissionAction.EXECUTE);
actions.remove(ChangeRequestPermissionAction.WRITE_MAINTAINER_NOTES);
}
} else if (perms.isRA(orgCode)) {
actions.addAll(Arrays.asList(ChangeRequestPermissionAction.values()));
actions.remove(ChangeRequestPermissionAction.DELETE);
actions.remove(ChangeRequestPermissionAction.WRITE_CONTRIBUTOR_NOTES);
actions.remove(ChangeRequestPermissionAction.WRITE_DETAILS);
if (status.equals(AllGovernanceStatus.ACCEPTED)) {
actions.remove(ChangeRequestPermissionAction.EXECUTE);
actions.remove(ChangeRequestPermissionAction.WRITE_MAINTAINER_NOTES);
}
} else if (perms.isRM(orgCode, type)) {
actions.addAll(Arrays.asList(ChangeRequestPermissionAction.values()));
actions.remove(ChangeRequestPermissionAction.DELETE);
actions.remove(ChangeRequestPermissionAction.WRITE_CONTRIBUTOR_NOTES);
actions.remove(ChangeRequestPermissionAction.WRITE_DETAILS);
if (status.equals(AllGovernanceStatus.ACCEPTED)) {
actions.remove(ChangeRequestPermissionAction.EXECUTE);
actions.remove(ChangeRequestPermissionAction.WRITE_MAINTAINER_NOTES);
}
} else if (perms.isRC(orgCode, type) || perms.isAC(orgCode, type)) {
actions.addAll(Arrays.asList(ChangeRequestPermissionAction.READ, ChangeRequestPermissionAction.WRITE, ChangeRequestPermissionAction.READ_APPROVAL_STATUS, ChangeRequestPermissionAction.READ_DETAILS, ChangeRequestPermissionAction.WRITE_DETAILS, ChangeRequestPermissionAction.READ_DOCUMENTS, ChangeRequestPermissionAction.WRITE_DOCUMENTS, ChangeRequestPermissionAction.READ_MAINTAINER_NOTES, ChangeRequestPermissionAction.READ_CONTRIBUTOR_NOTES, ChangeRequestPermissionAction.WRITE_CONTRIBUTOR_NOTES, ChangeRequestPermissionAction.SUBMIT, ChangeRequestPermissionAction.DELETE));
SessionIF session = Session.getCurrentSession();
if (session == null || session.getUser() == null || cr.getCreatedBy() == null || !cr.getCreatedBy().getOid().equals(session.getUser().getOid())) {
actions.remove(ChangeRequestPermissionAction.DELETE);
}
if (status.equals(AllGovernanceStatus.ACCEPTED) || status.equals(AllGovernanceStatus.REJECTED) || status.equals(AllGovernanceStatus.INVALID) || status.equals(AllGovernanceStatus.PARTIAL)) {
actions.remove(ChangeRequestPermissionAction.WRITE_CONTRIBUTOR_NOTES);
actions.remove(ChangeRequestPermissionAction.WRITE_DETAILS);
actions.remove(ChangeRequestPermissionAction.DELETE);
}
}
if (orgCode == null || gotCode == null) {
actions.removeAll(Arrays.asList(ChangeRequestPermissionAction.EXECUTE, ChangeRequestPermissionAction.WRITE_APPROVAL_STATUS, ChangeRequestPermissionAction.WRITE_DETAILS));
if (gotCode == null) {
actions.remove(ChangeRequestPermissionAction.READ_DETAILS);
}
if (perms.isSRA() || perms.isRA() || perms.isRM()) {
actions.add(ChangeRequestPermissionAction.DELETE);
}
}
return actions;
}
use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class ListCurationJob method startInTrans.
@Transaction
private JobHistoryRecord startInTrans(ListTypeVersion version) {
final ListType listType = version.getListType();
final ServerGeoObjectType type = listType.getGeoObjectType();
final Organization org = listType.getOrganization();
RolePermissionService perms = ServiceFactory.getRolePermissionService();
if (perms.isRA()) {
perms.enforceRA(org.getCode());
} else if (perms.isRM()) {
perms.enforceRM(org.getCode(), type);
} else {
perms.enforceRM();
}
ListCurationHistory history = (ListCurationHistory) this.createNewHistory();
history.appLock();
history.setVersion(version);
history.apply();
JobHistoryRecord record = new JobHistoryRecord(this, history);
record.apply();
return record;
}
use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class ServerGeoObjectService method createGeoObjectInTrans.
@Transaction
public JsonObject createGeoObjectInTrans(String sPtn, String sTimeGo, String masterListId, String notes) {
GeoObjectOverTime timeGO = GeoObjectOverTime.fromJSON(ServiceFactory.getAdapter(), sTimeGo);
ServerGeoObjectType serverGOT = ServerGeoObjectType.get(timeGO.getType());
RolePermissionService perms = ServiceFactory.getRolePermissionService();
final String orgCode = serverGOT.getOrganization().getCode();
if (perms.isSRA() || perms.isRA(orgCode) || perms.isRM(orgCode, serverGOT)) {
ServerGeoObjectService service = new ServerGeoObjectService();
ServerGeoObjectIF serverGO = service.apply(timeGO, true, false);
final ServerGeoObjectType type = serverGO.getType();
if (sPtn != null) {
ServerParentTreeNodeOverTime ptnOt = ServerParentTreeNodeOverTime.fromJSON(type, sPtn);
serverGO.setParents(ptnOt);
}
// Update the master list record
if (masterListId != null) {
ListTypeVersion.get(masterListId).publishRecord(serverGO);
}
JsonObject resp = new JsonObject();
resp.addProperty("isChangeRequest", false);
resp.add("geoObject", serverGO.toGeoObjectOverTime().toJSON(ServiceFactory.getRegistryService().serializer(Session.getCurrentSession().getOid())));
return resp;
} else if (ServiceFactory.getRolePermissionService().isRC(orgCode, serverGOT)) {
Instant base = Instant.now();
int sequence = 0;
ChangeRequest request = new ChangeRequest();
request.addApprovalStatus(AllGovernanceStatus.PENDING);
request.setContributorNotes(notes);
request.setGeoObjectCode(timeGO.getCode());
request.setGeoObjectTypeCode(timeGO.getType().getCode());
request.setOrganizationCode(orgCode);
request.apply();
CreateGeoObjectAction action = new CreateGeoObjectAction();
action.addApprovalStatus(AllGovernanceStatus.PENDING);
action.setCreateActionDate(Date.from(base.plus(sequence++, ChronoUnit.MINUTES)));
action.setGeoObjectJson(sTimeGo);
action.setParentJson(sPtn);
action.setApiVersion(CGRAdapterProperties.getApiVersion());
action.setContributorNotes(notes);
action.apply();
request.addAction(action).apply();
JsonObject resp = new JsonObject();
resp.addProperty("isChangeRequest", true);
resp.addProperty("changeRequestId", request.getOid());
return resp;
} else {
throw new CGRPermissionException();
}
}
use of net.geoprism.registry.permission.RolePermissionService in project geoprism-registry by terraframe.
the class HierarchyService method getHierarchyGroupedTypes.
@Request(RequestType.SESSION)
public JsonArray getHierarchyGroupedTypes(String sessionId) {
final HierarchyTypePermissionServiceIF hierarchyPermissions = ServiceFactory.getHierarchyPermissionService();
final GeoObjectTypePermissionServiceIF typePermissions = ServiceFactory.getGeoObjectTypePermissionService();
final RolePermissionService rps = ServiceFactory.getRolePermissionService();
final boolean isSRA = rps.isSRA();
JsonArray allHiers = new JsonArray();
List<ServerHierarchyType> shts = ServiceFactory.getMetadataCache().getAllHierarchyTypes();
for (ServerHierarchyType sht : shts) {
final String htOrgCode = sht.getOrganizationCode();
if (hierarchyPermissions.canRead(htOrgCode) && (isSRA || rps.isRA(htOrgCode) || rps.isRM(htOrgCode))) {
JsonObject hierView = new JsonObject();
hierView.addProperty("code", sht.getCode());
hierView.addProperty("label", sht.getDisplayLabel().getValue());
hierView.addProperty("orgCode", sht.getOrganizationCode());
JsonArray allHierTypes = new JsonArray();
List<ServerGeoObjectType> types = sht.getAllTypes();
for (ServerGeoObjectType type : types) {
final String gotOrgCode = type.getOrganizationCode();
if (typePermissions.canRead(gotOrgCode, type, type.getIsPrivate()) && (isSRA || rps.isRA(gotOrgCode) || rps.isRM(gotOrgCode, type))) {
if (type.getIsAbstract()) {
JsonObject superView = new JsonObject();
superView.addProperty("code", type.getCode());
superView.addProperty("label", type.getLabel().getValue());
superView.addProperty("orgCode", type.getOrganizationCode());
superView.addProperty("isAbstract", true);
List<ServerGeoObjectType> subtypes = type.getSubtypes();
for (ServerGeoObjectType subtype : subtypes) {
JsonObject typeView = new JsonObject();
typeView.addProperty("code", subtype.getCode());
typeView.addProperty("label", subtype.getLabel().getValue());
typeView.addProperty("orgCode", subtype.getOrganization().getCode());
typeView.add("super", superView);
allHierTypes.add(typeView);
}
} else {
JsonObject typeView = new JsonObject();
typeView.addProperty("code", type.getCode());
typeView.addProperty("label", type.getLabel().getValue());
typeView.addProperty("orgCode", type.getOrganizationCode());
allHierTypes.add(typeView);
}
}
}
hierView.add("types", allHierTypes);
allHiers.add(hierView);
}
}
return allHiers;
}
Aggregations