Applying "Community Admin XMLUI: Delegated Admins Patch" (DS-228). This adds delegated Admin capabilities and specifically a Community Administrator role. See Jira issue DS-228 for more specific details, including documentation on the permissions of a System Admin vs. Community Admin vs. Collection Admin. [WARNING:] This patch adds a database_schema_15-16.sql (as it requires a new "admin" column on the 'collection' table). This patch also currently only fully works for the XMLUI (but should not break anything with JSPUI) - Andrea Bollini is working on porting it over to JSPUI.

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@3980 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Tim Donohue
2009-06-26 17:07:25 +00:00
parent fd2be53602
commit 1c7affd37a
16 changed files with 939 additions and 56 deletions

View File

@@ -94,6 +94,9 @@ public class Community extends DSpaceObject
/** Flag set when metadata is modified, for events */
private boolean modifiedMetadata;
/** The default group of administrators */
private Group admins;
/**
* Construct a community object from a database row.
*
@@ -125,6 +128,9 @@ public class Community extends DSpaceObject
context.cache(this, row.getIntColumn("community_id"));
modified = modifiedMetadata = false;
admins = groupFromColumn("admin");
clearDetails();
}
@@ -507,6 +513,78 @@ public class Community extends DSpaceObject
}
}
/**
* Create a default administrators group if one does not already exist.
* Returns either the newly created group or the previously existing one.
* Note that other groups may also be administrators.
*
* @return the default group of editors associated with this community
* @throws SQLException
* @throws AuthorizeException
*/
public Group createAdministrators() throws SQLException, AuthorizeException
{
// Check authorisation - Must be an Admin to create more Admins
AuthorizeManager.authorizeAction(ourContext, this, Constants.ADMIN);
if (admins == null)
{
//turn off authorization so that Community Admins can create Sub-Community Admins
ourContext.turnOffAuthorisationSystem();
admins = Group.create(ourContext);
ourContext.restoreAuthSystemState();
admins.setName("COMMUNITY_" + getID() + "_ADMIN");
admins.update();
}
AuthorizeManager.addPolicy(ourContext, this, Constants.ADMIN, admins);
// register this as the admin group
communityRow.setColumn("admin", admins.getID());
modified = true;
return admins;
}
/**
* Remove the administrators group, if no group has already been created
* then return without error. This will merely dereference the current
* administrators group from the community so that it may be deleted
* without violating database constraints.
*/
public void removeAdministrators() throws SQLException, AuthorizeException
{
// Check authorisation - Must be an Admin to delete Admin group
AuthorizeManager.authorizeAction(ourContext, this, Constants.ADMIN);
// just return if there is no administrative group.
if (admins == null)
return;
// Remove the link to the community table.
communityRow.setColumnNull("admin");
admins = null;
modified = true;
}
/**
* Get the default group of administrators, if there is one. Note that the
* authorization system may allow others to be administrators for the
* community.
* <P>
* The default group of administrators for community 100 is the one called
* <code>community_100_admin</code>.
*
* @return group of administrators, or <code>null</code> if there is no
* default group.
*/
public Group getAdministrators()
{
return admins;
}
/**
* Get the collections in this community. Throws an SQLException because
* creating a community object won't load in all collections.
@@ -999,6 +1077,14 @@ public class Community extends DSpaceObject
// Delete community row
DatabaseManager.delete(ourContext, communityRow);
// Remove administrators group - must happen after deleting community
Group g = getAdministrators();
if (g != null)
{
g.delete();
}
}
/**
@@ -1021,6 +1107,25 @@ public class Community extends DSpaceObject
return (getID() == ((Community) other).getID());
}
/**
* Utility method for reading in a group from a group ID in a column. If the
* column is null, null is returned.
*
* @param col
* the column name to read
* @return the group referred to by that column, or null
* @throws SQLException
*/
private Group groupFromColumn(String col) throws SQLException
{
if (communityRow.isColumnNull(col))
{
return null;
}
return Group.find(ourContext, communityRow.getIntColumn(col));
}
/**
* return type found in Constants
*/