Changeset 5368
- Timestamp:
- Jun 22, 2010, 2:51:41 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/src/docbook/developerdoc/api_overview.xml
r5100 r5368 471 471 472 472 <sect3 id="data_api.authentication.groups"> 473 <title>Groups, roles and projects</title>473 <title>Groups, roles, projects and permission template</title> 474 474 475 475 <para> … … 481 481 project. No matter what permission an item has been shared with the 482 482 user will not get higher permission. Groups may be members of other groups and 483 also in projects. 483 also in projects. A <classname docapi="net.sf.basedb.core.data">PermissionTemplateData</classname> 484 is just a holder for permissions that users can use when sharing items. The 485 template is never part of the actual permission control mechanism. 484 486 </para> 485 487 … … 488 490 one project at a time to be use, this is the <emphasis>active project</emphasis>. 489 491 When a project is active new items that are created are automatically 490 added to that project with the permission given by the 491 <varname>autoPermission</varname> property. 492 </para> 493 492 shared according to the settings for the project. There are two cases. 493 If the project has a permission template, the new item is given the same 494 permissions as the template has. If the project doesn't have a permission 495 template, the new item is shared to the active project with the permission 496 given by the <varname>autoPermission</varname> property. Note that in the 497 first case the new item may or may not be shared to the active project 498 depending on if the template is shared to the project or not. 499 </para> 500 501 <para> 502 Note that the permission template is only used (by the core) when creating 503 new items. The permissions held by the template are copied and when the new item 504 has been saved to the database there is no longer any reference back to 505 the template that was used to create it. This means that changes to the 506 template does not affect already existing items and that the template 507 can be deleted without problems. 508 </para> 494 509 </sect3> 495 510 -
trunk/src/clients/web/net/sf/basedb/clients/web/PermissionUtil.java
r5360 r5368 217 217 Item.FILESERVER, Item.FILE, Item.DIRECTORY, Item.PROJECT, Item.MESSAGE, 218 218 Item.PLUGINTYPE, Item.PLUGINDEFINITION, Item.PLUGINCONFIGURATION, Item.JOB, 219 Item.JOBAGENT, Item.CHANGEHISTORY 219 Item.JOBAGENT, Item.CHANGEHISTORY, Item.PERMISSIONTEMPLATE 220 220 }) 221 221 ); -
trunk/src/core/common-queries.xml
r5360 r5368 3837 3837 </description> 3838 3838 </query> 3839 <query id="GET_PROJECTS_FOR_PERMISSION_TEMPLATE" type="HQL"> 3840 <sql> 3841 SELECT {1} 3842 FROM ProjectData prj 3843 WHERE prj.permissionTemplate = :permissionTemplate 3844 </sql> 3845 <description> 3846 A HQL query that gets the projects that are using a given permission 3847 template. 3848 </description> 3849 </query> 3839 3850 3840 3851 </predefined-queries> -
trunk/src/core/net/sf/basedb/core/GroupPermissions.java
r4889 r5368 79 79 80 80 /** 81 Merge the permissions for all groups from the given item key with the permissions 82 in this object. If the item key contains permissions for a group that already 83 has permissions in this object the permissions are combined (added) to create 84 a new permission. 85 86 @param itemKey An item key (if null, this method simply returns) 87 @since 2.16 88 */ 89 public void merge(ItemKey itemKey) 90 { 91 if (itemKey == null) return; 92 for (Map.Entry<GroupData, Integer> entry : itemKey.getData().getGroups().entrySet()) 93 { 94 GroupData group = entry.getKey(); 95 int permissions = IntegerUtil.getInt(entry.getValue()); 96 int current = IntegerUtil.getInt(groupPermissions.get(group)); 97 groupPermissions.put(group, current | permissions); 98 } 99 } 100 101 102 /** 81 103 Grant permissions to a group. Use an empty <code>Set</code> or null 82 104 to remove all permissions for the group. -
trunk/src/core/net/sf/basedb/core/Install.java
r5364 r5368 116 116 method. 117 117 */ 118 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(8 1).intValue();118 public static final int NEW_SCHEMA_VERSION = Integer.valueOf(82).intValue(); 119 119 120 120 public static synchronized void createTables(boolean update, final ProgressReporter progress) … … 329 329 createRoleKey(Item.USER, "Users", "Gives access to users.", administrators_all); 330 330 createRoleKey(Item.PROJECT, "Projects", "Gives access to projects.", users_create); 331 createRoleKey(Item.PERMISSIONTEMPLATE, "Permission templates", "Gives access to permission templates.", users_create); 331 332 332 333 // Files, directories and quota -
trunk/src/core/net/sf/basedb/core/Item.java
r5360 r5368 77 77 */ 78 78 ITEMKEY(25, "Item key", "ik", ItemKey.class, ItemKeyData.class, null, 79 13 00),79 1310), 80 80 /** 81 81 The item is a {@link ProjectKey}. 82 82 */ 83 83 PROJECTKEY(26, "Project key", "pk", ProjectKey.class, ProjectKeyData.class, null, 84 13 10),84 1320), 85 85 /** 86 86 The item is a {@link RoleKey}. 87 87 */ 88 88 ROLEKEY(27, "Role key", "rk", RoleKey.class, RoleKeyData.class, null, 89 1320), 89 1330), 90 /** 91 The item is a {@link PermissionTemplate}. 92 */ 93 PERMISSIONTEMPLATE(28, "Permission template", "pt", PermissionTemplate.class, PermissionTemplateData.class, 94 DefinedPermissions.shareable, 1300), 95 90 96 91 97 /** -
trunk/src/core/net/sf/basedb/core/Project.java
r5167 r5368 288 288 The permissions to use when automatically sharing new items to 289 289 the project when it is the active project. The default is READ, 290 USE, WRITE and DELETE. 290 USE, WRITE and DELETE. Note that this setting is ignored when 291 a permission template is used ({@link #getPermissionTemplate()}). 291 292 @since 2.10 292 293 */ … … 298 299 /** 299 300 Set the default permissions to use when automatically sharing 300 new item the project when it is the active project. 301 new item the project when it is the active project. Note that 302 this setting is ignored when a permission template is used 303 ({@link #getPermissionTemplate()}). 301 304 @param permissions The permissions, must not be null or empty 302 305 @throws PermissionDeniedException If the logged in user doesn't … … 316 319 } 317 320 321 /** 322 Get the permission template that is used to share new items when this project 323 is active. Note that if a permission template is used the new items are only 324 shared to the active project if the project is part of the template. 325 @return A permission template or null if no template has been specified 326 @since 2.16 327 */ 328 public PermissionTemplate getPermissionTemplate() 329 { 330 return getDbControl().getItem(PermissionTemplate.class, getData().getPermissionTemplate()); 331 } 332 333 /** 334 Set the permission template that should be used to share new items when 335 this project is active. 336 @param template A permission template, or null to not use any template 337 @since 2.16 338 */ 339 public void setPermissionTemplate(PermissionTemplate template) 340 { 341 checkPermission(Permission.WRITE); 342 getData().setPermissionTemplate(template == null ? null : template.getData()); 343 } 344 318 345 /** 319 346 Grant a user permissions to this project. Use an empty <code>Set</code> or null -
trunk/src/core/net/sf/basedb/core/ProjectPermissions.java
r4889 r5368 81 81 82 82 /** 83 Merge the permissions for all projects from the given project key with the permissions 84 in this object. If the project key contains permissions for a project that already 85 has permissions in this object the permissions are combined (added) to create 86 a new permission. 87 88 @param projectKey A project key (if null, this method simply returns) 89 @since 2.16 90 */ 91 public void merge(ProjectKey projectKey) 92 { 93 if (projectKey == null) return; 94 for (Map.Entry<ProjectData, Integer> entry : projectKey.getData().getProjects().entrySet()) 95 { 96 ProjectData project = entry.getKey(); 97 int permissions = IntegerUtil.getInt(entry.getValue()); 98 int current = IntegerUtil.getInt(projectPermissions.get(project)); 99 projectPermissions.put(project, current | permissions); 100 } 101 } 102 103 104 /** 83 105 Grant permissions to a project. Use an empty <code>Set</code> or null 84 106 to remove all permissions for the project. -
trunk/src/core/net/sf/basedb/core/SessionControl.java
r5319 r5368 25 25 26 26 import net.sf.basedb.core.data.OwnableData; 27 import net.sf.basedb.core.data.PermissionTemplateData; 27 28 import net.sf.basedb.core.data.UserData; 28 29 import net.sf.basedb.core.data.PasswordData; … … 897 898 loginInfo.activeProjectId = 0; 898 899 loginInfo.projectKeyId = 0; 900 loginInfo.itemKeyId = 0; 899 901 } 900 902 else … … 905 907 if (project.hasPermission(Permission.USE)) 906 908 { 907 ProjectPermissions pp = new ProjectPermissions(); 908 pp.setPermissions(project, project.getAutoPermission()); 909 loginInfo.projectKeyId = ProjectKey.getNewOrExistingId(null, pp.getProjectPermissions()); 909 PermissionTemplateData template = project.getData().getPermissionTemplate(); 910 if (template != null) 911 { 912 org.hibernate.Session session = null; 913 org.hibernate.Transaction tx = null; 914 try 915 { 916 if (project.isDetached()) 917 { 918 // Make sure that we can load the template's item and project keys 919 session = HibernateUtil.newSession(); 920 tx = HibernateUtil.newTransaction(session); 921 template = HibernateUtil.loadData(session, PermissionTemplateData.class, template.getId()); 922 } 923 ProjectKeyData pk = template.getProjectKey(); 924 ItemKeyData ik = template.getItemKey(); 925 loginInfo.projectKeyId = pk == null ? 0 : pk.getId(); 926 loginInfo.itemKeyId = ik == null ? 0 : ik.getId(); 927 } 928 finally 929 { 930 if (tx != null) HibernateUtil.commit(tx); 931 if (session != null) HibernateUtil.close(session); 932 } 933 } 934 else 935 { 936 ProjectPermissions pp = new ProjectPermissions(); 937 pp.setPermissions(project, project.getAutoPermission()); 938 loginInfo.projectKeyId = ProjectKey.getNewOrExistingId(null, pp.getProjectPermissions()); 939 loginInfo.itemKeyId = 0; 940 } 910 941 } 911 942 else 912 943 { 913 944 loginInfo.projectKeyId = 0; 945 loginInfo.itemKeyId = 0; 914 946 } 915 947 } … … 940 972 { 941 973 return loginInfo == null ? 0 : loginInfo.projectKeyId; 974 } 975 976 /** 977 Get the id of the {@link ItemKey} that new items should be shared to 978 according to the settings in the currently active project. If no 979 project is active or if the projects doesn't share to any item 980 key, 0 is returned. 981 Use {@link ItemKey#getById(DbControl, int)} to get the {@link ItemKey} object. 982 @see #getActiveProjectId() 983 @see #setActiveProject(Project) 984 @see #getProjectKeyId() 985 @since 2.16 986 */ 987 public int getItemKeyId() 988 { 989 return loginInfo == null ? 0 : loginInfo.itemKeyId; 942 990 } 943 991 … … 2105 2153 2106 2154 /** 2107 The id of the {@link ProjectKeyData} object that shares an item with2108 full permission to the active project.2155 The id of the {@link ProjectKeyData} object that new items should 2156 be shared to. 2109 2157 */ 2110 2158 private int projectKeyId; 2159 2160 /** 2161 The id of the {@link ItemKeyData} object that new items should be 2162 shared to. 2163 */ 2164 private int itemKeyId; 2111 2165 2112 2166 /** -
trunk/src/core/net/sf/basedb/core/ShareableUtil.java
r5060 r5368 28 28 import net.sf.basedb.core.data.GroupData; 29 29 import net.sf.basedb.core.data.ItemKeyData; 30 import net.sf.basedb.core.data.ProjectData;31 30 import net.sf.basedb.core.data.ProjectKeyData; 32 31 import net.sf.basedb.core.data.ShareableData; … … 161 160 is shared to the 'EVERYONE' group, but the logged in user lacks 162 161 the {@link Permission#SHARE_TO_EVERYONE} permission, the share to 163 everyone is removed. If the 'to' item is a new item ,a project164 is active and the 'from' item isn't already shared to the project,165 the 'to' item will be shared to the project.162 everyone is removed. If the 'to' item is a new item and a project 163 is active the new item is also shared with the settings from 164 the project. 166 165 167 166 @param from The item to copy permissions from … … 179 178 ProjectKey projectKey = from.getProjectKey(); 180 179 180 GroupPermissions newGroupPermissions = null; 181 UserPermissions newUserPermissions = null; 182 ProjectPermissions newProjectPermissions = null; 183 184 // If 'to' is a new item we may need to merge permission from the active project 185 if (to.getId() == 0) 186 { 187 // Merge with item key permissions from active project 188 if (sc.getItemKeyId() != 0 && itemKey != null) 189 { 190 ItemKey activeKey = ItemKey.getById(dc, sc.getItemKeyId()); 191 newUserPermissions = new UserPermissions(itemKey); 192 newUserPermissions.merge(activeKey); 193 newGroupPermissions = new GroupPermissions(itemKey); 194 newGroupPermissions.merge(activeKey); 195 } 196 if (sc.getProjectKeyId() != 0 && projectKey != null) 197 { 198 newProjectPermissions = new ProjectPermissions(projectKey); 199 newProjectPermissions.merge(ProjectKey.getById(dc, sc.getProjectKeyId())); 200 } 201 } 202 181 203 // Check if we need to remove permissions for the EVERYONE group 182 204 if (itemKey != null && !sc.hasSystemPermission(Permission.SHARE_TO_EVERYONE)) … … 185 207 SystemItems.getId(Group.EVERYONE)); 186 208 187 if (itemKey.getData().getGroups().containsKey(everyone)) 209 if (itemKey.getData().getGroups().containsKey(everyone) || 210 (newGroupPermissions != null && newGroupPermissions.getGroupPermissions().containsKey(everyone))) 188 211 { 189 212 // Remove the EVERYONE grup 190 GroupPermissions gp = new GroupPermissions(itemKey); 191 gp.getGroupPermissions().remove(everyone); 192 193 UserPermissions up = new UserPermissions(itemKey); 194 if (up.size() == 0 && gp.size() == 0) 195 { 196 itemKey = null; 197 } 198 else 199 { 200 itemKey = ItemKey.getNewOrExisting(dc, up, gp); 201 } 202 } 203 } 204 205 // Check if we need to add permissions for the current project 206 if (projectKey != null && sc.getProjectKeyId() != 0 && to.getId() == 0) 207 { 208 ProjectData project = HibernateUtil.loadData(dc.getHibernateSession(), 209 ProjectData.class, sc.getActiveProjectId()); 210 211 if (!projectKey.getData().getProjects().containsKey(project)) 212 { 213 // Add the current project 214 ProjectKey activeKey = ProjectKey.getById(dc, sc.getProjectKeyId()); 215 ProjectPermissions pp = new ProjectPermissions(projectKey); 216 pp.getProjectPermissions().put(project, activeKey.getData().getProjects().get(project)); 217 projectKey = ProjectKey.getNewOrExisting(dc, pp); 213 if (newGroupPermissions == null) newGroupPermissions = new GroupPermissions(itemKey); 214 if (newUserPermissions == null) newUserPermissions = new UserPermissions(itemKey); 215 newGroupPermissions.getGroupPermissions().remove(everyone); 216 } 217 } 218 219 if (newUserPermissions != null || newGroupPermissions != null) 220 { 221 if (newUserPermissions.size() == 0 && newGroupPermissions.size() == 0) 222 { 223 itemKey = null; 224 } 225 else 226 { 227 itemKey = ItemKey.getNewOrExisting(dc, newUserPermissions, newGroupPermissions); 228 } 229 } 230 if (newProjectPermissions != null) 231 { 232 if (newProjectPermissions.size() == 0) 233 { 234 projectKey = null; 235 } 236 else 237 { 238 projectKey = ProjectKey.getNewOrExisting(dc, newProjectPermissions); 218 239 } 219 240 } -
trunk/src/core/net/sf/basedb/core/SharedItem.java
r4889 r5368 23 23 package net.sf.basedb.core; 24 24 25 import net.sf.basedb.core.data.ItemKeyData; 25 26 import net.sf.basedb.core.data.SharedData; 26 27 import net.sf.basedb.core.data.ProjectKeyData; … … 44 45 45 46 private boolean projectKeySet = false; 47 private boolean itemKeySet = false; 46 48 47 49 SharedItem(D sharedData) … … 64 66 checkPermission(Permission.SET_PERMISSION); 65 67 ShareableUtil.setItemKey(getDbControl(), getData(), itemKey); 68 itemKeySet = true; 66 69 } 67 70 public ProjectKey getProjectKey() … … 88 91 */ 89 92 /** 90 If a project is active, automatically share the new item to that project 91 unless a project key has been explicitely set (including null). 93 If a project is active, automatically share the new item according to 94 the settings of that project, unless a project or item key has been 95 explicitely set (including null). 92 96 @throws BaseException If there is another error 93 97 */ … … 96 100 { 97 101 super.onBeforeCommit(action); 98 if (action == Transactional.Action.CREATE && !projectKeySet)102 if (action == Transactional.Action.CREATE) 99 103 { 104 org.hibernate.Session session = getDbControl().getHibernateSession(); 100 105 int activeProjectKeyId = getSessionControl().getProjectKeyId(); 101 if (activeProjectKeyId != 0 )106 if (activeProjectKeyId != 0 && !projectKeySet) 102 107 { 103 org.hibernate.Session session = getDbControl().getHibernateSession();104 108 getData().setProjectKey(HibernateUtil.loadData(session, ProjectKeyData.class, activeProjectKeyId)); 109 } 110 int activeItemKeyId = getSessionControl().getItemKeyId(); 111 if (activeItemKeyId != 0 && !itemKeySet) 112 { 113 getData().setItemKey(HibernateUtil.loadData(session, ItemKeyData.class, activeItemKeyId)); 105 114 } 106 115 } -
trunk/src/core/net/sf/basedb/core/Update.java
r5360 r5368 51 51 import net.sf.basedb.core.data.JobData; 52 52 import net.sf.basedb.core.data.MeasuredBioMaterialData; 53 import net.sf.basedb.core.data.PermissionTemplateData; 53 54 import net.sf.basedb.core.data.PlateData; 54 55 import net.sf.basedb.core.data.PlateMappingData; … … 890 891 <td> 891 892 Added {@link FileData#getUrl()} and {@link FileServer}. 893 No special update is needed. Only increase the schema version. 894 </td> 895 </tr> 896 <tr> 897 <td>82</td> 898 <td> 899 Added {@link PermissionTemplateData} and {@link ProjectData#getPermissionTemplate()}. 900 No special update is needed. Only increase the schema version. 892 901 </td> 893 902 </tr> … … 1216 1225 } 1217 1226 1218 // Schemaversion 81 only updates the version number1219 if (schemaVersion < 8 1)1220 { 1221 if (progress != null) progress.display((int)(8 0*progress_factor), "--Updating schema version: " + schemaVersion + " -> 81...");1222 schemaVersion = setSchemaVersionInTransaction(session, 8 1);1227 // Schemaversion 81-82 only updates the version number 1228 if (schemaVersion < 82) 1229 { 1230 if (progress != null) progress.display((int)(81*progress_factor), "--Updating schema version: " + schemaVersion + " -> 82..."); 1231 schemaVersion = setSchemaVersionInTransaction(session, 82); 1223 1232 } 1224 1233 -
trunk/src/core/net/sf/basedb/core/UserPermissions.java
r4889 r5368 80 80 81 81 /** 82 Merge the permissions for all users from the given item key with the permissions 83 in this object. If the item key contains permissions for a user that already 84 has permissions in this object the permissions are combined (added) to create 85 a new permission. 86 87 @param itemKey An item key (if null, this method simply returns) 88 @since 2.16 89 */ 90 public void merge(ItemKey itemKey) 91 { 92 if (itemKey == null) return; 93 for (Map.Entry<UserData, Integer> entry : itemKey.getData().getUsers().entrySet()) 94 { 95 UserData user = entry.getKey(); 96 int permissions = IntegerUtil.getInt(entry.getValue()); 97 int current = IntegerUtil.getInt(userPermissions.get(user)); 98 userPermissions.put(user, current | permissions); 99 } 100 } 101 102 /** 82 103 Grant permissions to a user. Use an empty <code>Set</code> or null 83 104 to remove all permissions for the user. -
trunk/src/core/net/sf/basedb/core/data/ProjectData.java
r4889 r5368 114 114 } 115 115 116 private PermissionTemplateData permissionTemplate; 117 /** 118 A permission template can be used to set default permissions 119 when this project is active. 120 @return A permission template or null 121 @since 2.16 122 @hibernate.many-to-one column="`permissiontemplate_id`" not-null="false" 123 */ 124 public PermissionTemplateData getPermissionTemplate() 125 { 126 return permissionTemplate; 127 } 128 public void setPermissionTemplate(PermissionTemplateData permissionTemplate) 129 { 130 this.permissionTemplate = permissionTemplate; 131 } 132 116 133 private Map<UserData,Integer> users; 117 134 /** -
trunk/src/test/TestAll.java
r5360 r5368 44 44 results.put("TestProjectKey", TestProjectKey.test_all()); 45 45 results.put("TestItemKey", TestItemKey.test_all()); 46 results.put("TestPermissionTemplate", TestPermissionTemplate.test_all()); 46 47 47 48 // Settings, sessions and client -
trunk/src/test/TestGroup.java
r5340 r5368 66 66 67 67 // Extra tests: add, list and remove projects 68 int projectId = TestProject.test_create( true);68 int projectId = TestProject.test_create("Group project", true); 69 69 test_listprojects(id, 0); 70 70 TestProject.test_addgroup(projectId, id, EnumSet.of(Permission.WRITE)); -
trunk/src/test/TestItemKey.java
r5024 r5368 137 137 numDeleted + "; expected " + expected); 138 138 } 139 write("--Delete unused item keys OK (" + expected + ")");139 write("--Delete unused item keys OK (" + numDeleted + ")"); 140 140 } 141 141 catch (Throwable ex) -
trunk/src/test/TestProject.java
r5340 r5368 46 46 write_header(); 47 47 // Standard tests: create, load, list 48 int id = test_create( true);49 int id2 = test_create( false);48 int id = test_create("Test project #1", true); 49 int id2 = test_create("Test project #2", false); 50 50 test_load(id); 51 51 test_list(-1); … … 126 126 } 127 127 128 static int test_create( boolean setAll)128 static int test_create(String name, boolean setAll) 129 129 { 130 130 if (!TestUtil.hasPermission(Permission.CREATE, Item.PROJECT)) return 0; … … 135 135 dc = TestUtil.getDbControl(); 136 136 Project p = Project.getNew(dc); 137 p.setName(name); 137 138 if (setAll) 138 139 { 139 p.setName("Test project");140 140 p.setDescription("Added at "+new Date()); 141 141 } -
trunk/src/test/TestProjectKey.java
r5024 r5368 46 46 47 47 // Extra test: create project for the key 48 int projectId = TestProject.test_create( true);48 int projectId = TestProject.test_create("Test project", true); 49 49 50 50 // Standard tests: create, load … … 158 158 numDeleted + "; expected " + expected); 159 159 } 160 write("--Delete unused project keys OK (" + expected + ")");160 write("--Delete unused project keys OK (" + numDeleted + ")"); 161 161 } 162 162 catch (Throwable ex) -
trunk/src/test/TestUser.java
r5340 r5368 76 76 77 77 // Extra tests: add, list and remove projects 78 int projectId = TestProject.test_create( true);78 int projectId = TestProject.test_create("User project", true); 79 79 test_listprojects(id, 0); 80 80 TestProject.test_adduser(projectId, id, EnumSet.of(Permission.WRITE)); -
trunk/src/test/TestWebservices.java
r5233 r5368 94 94 95 95 //Create items to use in the tests 96 int projectId = TestProject.test_create( true);96 int projectId = TestProject.test_create("Web service project", true); 97 97 98 98 int reporterListId1 = TestReporterList.test_create("net.sf.basedb.clients.test.reporterlist1", true);
Note: See TracChangeset
for help on using the changeset viewer.