diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index bd011ee..59bba3d 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -51,14 +51,14 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C // Logger private static final org.slf4j.Logger logger = LoggerFactory.getLogger(CKANPublisherServicesImpl.class); - + public static final String TEST_SCOPE = "/gcube/devsec/devVRE"; public static final String CKAN_TOKEN_KEY = "ckanToken"; - + // library util instance private CKanUtilsImpl instance; - + @Override public void init(){ // discover the library @@ -106,17 +106,17 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C ASLSession session = getASLSession(); String username = session.getUsername(); logger.debug("User in session is " + username); - + String token = null; if(this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY) != null) token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY); else{ - + token = instance.getApiKeyFromUsername(username); this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token); logger.debug("Ckan token has been set for user " + username); } - + logger.debug("Found ckan token " + token + " for user " + username); return token; @@ -124,29 +124,37 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C /** * Retrieve the list of organizations in which the user can publish (roles ADMIN, EDITOR) + * If he is a SYSADMIN, he can publish everywhere * @param username * @return the list of organizations */ private List getUserOrganizationsList(String username) { logger.debug("Request for user " + username + " organizations list"); - - // We need to retrieve orgs in which the user has the roles ADMIN, EDITOR - List rolesToMatch = new ArrayList(); - rolesToMatch.add(RolesIntoOrganization.EDITOR); - rolesToMatch.add(RolesIntoOrganization.ADMIN); - List orgsName = new ArrayList(); - Map> orgsAndRoles = instance.getGroupsAndRolesByUser(username, rolesToMatch); - Iterator>> iterator = orgsAndRoles.entrySet().iterator(); - // get the names - while (iterator.hasNext()) { - Map.Entry> entry = (Map.Entry>) iterator - .next(); - orgsName.add(entry.getKey()); + if(instance.isSysAdmin(username, getUserCKanTokenFromSession())){ + + logger.debug("The user " + username + " is a sysadmin. He can publish everywhere"); + orgsName = instance.getOrganizationsNames(); + + }else{ + + // We need to retrieve orgs in which the user has the roles ADMIN, EDITOR + List rolesToMatch = new ArrayList(); + rolesToMatch.add(RolesIntoOrganization.EDITOR); + rolesToMatch.add(RolesIntoOrganization.ADMIN); + + Map> orgsAndRoles = instance.getGroupsAndRolesByUser(username, rolesToMatch); + Iterator>> iterator = orgsAndRoles.entrySet().iterator(); + + // get the names + while (iterator.hasNext()) { + Map.Entry> entry = (Map.Entry>) iterator + .next(); + orgsName.add(entry.getKey()); + } } - return orgsName; }