NIHVIVO-3523 Add DefaultPermissionSetForNewUsers to the User Accounts Model, with a property in PermissionSet and a test in UserAccountsDaoJenaTest.
This commit is contained in:
parent
7d7503fc22
commit
a9c7b3fead
6 changed files with 32 additions and 11 deletions
|
@ -18,6 +18,8 @@ public class PermissionSet {
|
|||
/** This may be empty, but it should never be null. */
|
||||
private String label = "";
|
||||
|
||||
private boolean defaultForNewUsers;
|
||||
|
||||
/** This may be empty, but it should never be null. */
|
||||
private Set<String> permissionUris = Collections.emptySet();
|
||||
|
||||
|
@ -37,6 +39,15 @@ public class PermissionSet {
|
|||
this.label = (label == null) ? "" : label;
|
||||
}
|
||||
|
||||
public boolean isDefaultForNewUsers() {
|
||||
return defaultForNewUsers;
|
||||
}
|
||||
|
||||
public void setDefaultForNewUsers(Boolean defaultForNewUsers) {
|
||||
this.defaultForNewUsers = (defaultForNewUsers == null) ? false
|
||||
: defaultForNewUsers.booleanValue();
|
||||
}
|
||||
|
||||
public Set<String> getPermissionUris() {
|
||||
return permissionUris;
|
||||
}
|
||||
|
|
|
@ -169,6 +169,7 @@ public class VitroVocabulary {
|
|||
|
||||
public static final String PERMISSIONSET = VITRO_AUTH + "PermissionSet";
|
||||
public static final String PERMISSIONSET_HAS_PERMISSION = VITRO_AUTH + "hasPermission";
|
||||
public static final String DEFAULT_PERMISSION_SET_FOR_NEW_USERS = VITRO_AUTH + "DefaultPermissionSetForNewUsers";
|
||||
|
||||
public static final String PERMISSION = VITRO_AUTH + "Permission";
|
||||
|
||||
|
|
|
@ -142,6 +142,7 @@ public class JenaBaseDaoCon {
|
|||
protected ObjectProperty USERACCOUNT_PROXY_EDITOR_FOR = _constModel.createObjectProperty(VitroVocabulary.USERACCOUNT_PROXY_EDITOR_FOR);
|
||||
|
||||
protected OntClass PERMISSIONSET = _constModel.createClass(VitroVocabulary.PERMISSIONSET);
|
||||
protected OntClass DEFAULT_PERMISSION_SET_FOR_NEW_USERS = _constModel.createClass(VitroVocabulary.DEFAULT_PERMISSION_SET_FOR_NEW_USERS);
|
||||
protected ObjectProperty PERMISSIONSET_HAS_PERMISSION = _constModel.createObjectProperty(VitroVocabulary.PERMISSIONSET_HAS_PERMISSION);
|
||||
|
||||
protected OntClass PERMISSION = _constModel.createClass(VitroVocabulary.PERMISSION);
|
||||
|
|
|
@ -382,7 +382,7 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
|||
Resource s = getOntModel().createResource(uri);
|
||||
getOntModel().remove(s, p, o);
|
||||
}
|
||||
for (String uri: addThese) {
|
||||
for (String uri : addThese) {
|
||||
Resource s = getOntModel().createResource(uri);
|
||||
getOntModel().add(s, p, o);
|
||||
}
|
||||
|
@ -410,6 +410,8 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
|||
PermissionSet ps = new PermissionSet();
|
||||
ps.setUri(uri);
|
||||
ps.setLabel(getPropertyStringValue(r, RDFS.label));
|
||||
ps.setDefaultForNewUsers(isResourceOfType(r,
|
||||
DEFAULT_PERMISSION_SET_FOR_NEW_USERS));
|
||||
ps.setPermissionUris(getPropertyResourceURIValues(r,
|
||||
PERMISSIONSET_HAS_PERMISSION));
|
||||
return ps;
|
||||
|
@ -434,6 +436,8 @@ public class UserAccountsDaoJena extends JenaBaseDao implements UserAccountsDao
|
|||
PermissionSet ps = new PermissionSet();
|
||||
ps.setUri(r.getURI());
|
||||
ps.setLabel(getPropertyStringValue(r, RDFS.label));
|
||||
ps.setDefaultForNewUsers(isResourceOfType(r,
|
||||
DEFAULT_PERMISSION_SET_FOR_NEW_USERS));
|
||||
ps.setPermissionUris(getPropertyResourceURIValues(r,
|
||||
PERMISSIONSET_HAS_PERMISSION));
|
||||
list.add(ps);
|
||||
|
|
|
@ -358,6 +358,7 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
|||
PermissionSet ps2 = new PermissionSet();
|
||||
ps2.setUri(URI_ROLE2);
|
||||
ps2.setLabel("Role 2");
|
||||
ps2.setDefaultForNewUsers(true);
|
||||
expected.add(ps2);
|
||||
|
||||
assertCorrectPermissionSets(expected, dao.getAllPermissionSets());
|
||||
|
@ -450,25 +451,26 @@ public class UserAccountsDaoJenaTest extends AbstractTestClass {
|
|||
Collection<PermissionSet> actual) {
|
||||
Set<Map<String, Object>> expectedMaps = new HashSet<Map<String, Object>>();
|
||||
for (PermissionSet ps : expected) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("uri", ps.getUri());
|
||||
map.put("label", ps.getLabel());
|
||||
map.put("permissions", ps.getPermissionUris());
|
||||
expectedMaps.add(map);
|
||||
expectedMaps.add(buildMapFromPermissionSet(ps));
|
||||
}
|
||||
|
||||
Set<Map<String, Object>> actualMaps = new HashSet<Map<String, Object>>();
|
||||
for (PermissionSet ps : actual) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("uri", ps.getUri());
|
||||
map.put("label", ps.getLabel());
|
||||
map.put("permissions", ps.getPermissionUris());
|
||||
actualMaps.add(map);
|
||||
actualMaps.add(buildMapFromPermissionSet(ps));
|
||||
}
|
||||
|
||||
assertEquals("all permission sets", expectedMaps, actualMaps);
|
||||
}
|
||||
|
||||
private Map<String, Object> buildMapFromPermissionSet(PermissionSet ps) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("uri", ps.getUri());
|
||||
map.put("label", ps.getLabel());
|
||||
map.put("permissions", ps.getPermissionUris());
|
||||
map.put("defaultForNewUsers", ps.isDefaultForNewUsers());
|
||||
return map;
|
||||
}
|
||||
|
||||
private void assertExpectedAccountUris(String label,
|
||||
Set<UserAccount> expectedUserAccounts,
|
||||
Collection<UserAccount> actualUserAccounts) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
|
||||
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
|
||||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
|
||||
@prefix owl: <http://www.w3.org/2002/07/owl#> .
|
||||
@prefix auth: <http://vitro.mannlib.cornell.edu/ns/vitro/authorization#> .
|
||||
@prefix mydomain: <http://vivo.mydomain.edu/individual/> .
|
||||
|
@ -30,6 +31,7 @@ mydomain:role1
|
|||
|
||||
mydomain:role2
|
||||
a auth:PermissionSet ;
|
||||
a auth:DefaultPermissionSetForNewUsers ;
|
||||
rdfs:label "Role 2" ;
|
||||
.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue