Search in sources :

Example 1 with SessionIF

use of com.runwaysdk.session.SessionIF 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;
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) Entry(java.util.Map.Entry) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) SessionIF(com.runwaysdk.session.SessionIF)

Example 2 with SessionIF

use of com.runwaysdk.session.SessionIF in project geoprism-registry by terraframe.

the class SynchronizationConfig method apply.

@Override
@Transaction
public void apply() {
    SessionIF session = Session.getCurrentSession();
    Organization organization = this.getOrganization();
    if (session != null && organization != null) {
        ServiceFactory.getRolePermissionService().enforceRA(organization.getCode());
    }
    super.apply();
    if (this.isNew()) {
        DataExportJob job = new DataExportJob();
        job.setConfig(this);
        job.apply();
    }
}
Also used : DataExportJob(net.geoprism.registry.etl.export.DataExportJob) SessionIF(com.runwaysdk.session.SessionIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Example 3 with SessionIF

use of com.runwaysdk.session.SessionIF 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;
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) ServerGeoObjectType(net.geoprism.registry.model.ServerGeoObjectType) HashSet(java.util.HashSet) SessionIF(com.runwaysdk.session.SessionIF)

Example 4 with SessionIF

use of com.runwaysdk.session.SessionIF in project geoprism-registry by terraframe.

the class Organization method isRegistryAdmin.

/**
 * @param org
 * @return If the current user is part of the registry admin role for the
 *         given organization
 */
public static boolean isRegistryAdmin(Organization org) {
    if (new RolePermissionService().isSRA()) {
        return true;
    }
    String roleName = RegistryRole.Type.getRA_RoleName((org.getCode()));
    final SessionIF session = Session.getCurrentSession();
    if (session != null) {
        return session.userHasRole(roleName);
    }
    return true;
}
Also used : RolePermissionService(net.geoprism.registry.permission.RolePermissionService) SessionIF(com.runwaysdk.session.SessionIF)

Example 5 with SessionIF

use of com.runwaysdk.session.SessionIF in project geoprism-registry by terraframe.

the class ExternalSystem method apply.

@Override
@Transaction
public void apply() {
    Organization organization = this.getOrganization();
    if (organization != null) {
        SessionIF session = Session.getCurrentSession();
        if (session != null) {
            ServiceFactory.getRolePermissionService().enforceRA(organization.getCode());
        }
    }
    super.apply();
}
Also used : Organization(net.geoprism.registry.Organization) SessionIF(com.runwaysdk.session.SessionIF) Transaction(com.runwaysdk.dataaccess.transaction.Transaction)

Aggregations

SessionIF (com.runwaysdk.session.SessionIF)5 RolePermissionService (net.geoprism.registry.permission.RolePermissionService)3 Transaction (com.runwaysdk.dataaccess.transaction.Transaction)2 ServerGeoObjectType (net.geoprism.registry.model.ServerGeoObjectType)2 HashSet (java.util.HashSet)1 Entry (java.util.Map.Entry)1 Organization (net.geoprism.registry.Organization)1 DataExportJob (net.geoprism.registry.etl.export.DataExportJob)1