Skip to content

Commit

Permalink
SAK-32584 Entity broker configurable so props updateable by non-admin… (
Browse files Browse the repository at this point in the history
sakaiproject#4464)

* SAK-32584 Entity broker configurable so props updateable by non-admin users.

* SAK-32584 Changes following feedback.

* SAK-32584 Add default fields that can be updated.
  • Loading branch information
RebeccaMiller-Which authored and ern committed Jun 27, 2017
1 parent c2ee129 commit 4b00036
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2968,6 +2968,11 @@
# DEFAULT: 500
# site.entity.pagesize.maximum=200

# Set the site entity broker properties that can be updated by a user with site update permission.
# Only works for single value properties, not multivalued.
# DEFAULT: contact-email, contact-name
# site.entity.updateable.props=contact-email, contact-name

# Show the menu option for duplicate site
# SAK-27908: disabled this option by default because it is not run in a separate thread like Import from Site
# DEFAULT: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public String getEntityPrefix() {
* a property of "site.entity.pagesize.maximum".
*/
private int maxPageSize = 500;

private static String[] updateableSiteProps;

public void init() {
int dps = serverConfigurationService.getInt(
Expand All @@ -174,6 +176,12 @@ public void init() {
} else {
maxPageSize = defaultPageSize;
}

updateableSiteProps = serverConfigurationService.getStrings("site.entity.updateable.props");
// Set defaults as these are the same values that can be changed through the UI.
if (updateableSiteProps == null) {
updateableSiteProps = new String [] {"contact-email", "contact-name"};
}
}

// ACTIONS
Expand Down Expand Up @@ -903,10 +911,19 @@ public void updateEntity(EntityReference ref, Object entity, Map<String, Object>
s.setSkin(site.getSkin());
s.setTitle(site.getTitle());

// put in properties if admin, otherwise ignore
// put in properties if admin, otherwise allow update of specific configurable fields.
if (admin) {
ResourcePropertiesEdit rpe = s.getPropertiesEdit();
rpe.set(site.getProperties());
} else {
if (updateableSiteProps != null && updateableSiteProps.length != 0) {
ResourcePropertiesEdit rpe = s.getPropertiesEdit();
for (String prop : updateableSiteProps) {
if (site.getProperties().getProperty(prop) != null) {
rpe.addProperty(prop, site.getProperties().getProperty(prop));
}
}
}
}

// set the new publish status
Expand Down Expand Up @@ -949,13 +966,25 @@ public void updateEntity(EntityReference ref, Object entity, Map<String, Object>
if (site.getInfoUrl() != null)
s.setInfoUrl(site.getInfoUrl());

// put in properties if admin, otherwise ignore
// put in properties if admin, otherwise allow update of specific configurable fields.
if (admin) {
ResourcePropertiesEdit rpe = s.getPropertiesEdit();
for (String key : site.getProps().keySet()) {
String value = site.getProps().get(key);
rpe.addProperty(key, value);
}
} else {
if (updateableSiteProps != null && updateableSiteProps.length != 0) {
ResourcePropertiesEdit rpe = s.getPropertiesEdit();
for (String prop: updateableSiteProps) {
for (String key : site.getProps().keySet()) {
if (prop.equals(key)) {
String value = site.getProps().get(key);
rpe.addProperty(key, value);
}
}
}
}
}

// attempt to set the owner as requested
Expand Down

0 comments on commit 4b00036

Please sign in to comment.