Changeset 1310


Ignore:
Timestamp:
Mar 4, 2011, 3:45:04 PM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #292: Check/create annotation types, etc. required by reggie

Smarter check for required permissions when a project is active. Only some of the annotation types (with personal information) need to be shared to the 'PatientCurator?' group. The other annotation types can be shared to the active project.

Important note! This code is affected by http://base.thep.lu.se/ticket/1583 if an item is already shared to a different project or group than the active project or 'PatientCurator?' group. This will result in a (almost) blank page that can't be used for validation or create missing items.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/README

    r1301 r1310  
    2020    installation. Otherwise, just wait a bit and the automatic installation will
    2121    find and install the new extension.
    22  5. Log in as a user with Administrator priviliges. Go to the Extensions->Reggie
    23     menu. Select the 'Verify/install required annotation types and other items'
    24     wizard and create the required items. If the 'Reggie' menu is not visible
    25     try BASE->Reload permissions menu.
    26  6. Done.
     22 5. Log in as a user with Administrator priviliges.
     23 6. Create a project and set it as the active project. This step is
     24    optional but is recommended. Running Reggie without an active project
     25    will generate warning messages later on.
     26 7. Go to the Extensions->Reggie menu. Select the 'Verify/install required
     27    annotation types and other items' wizard. If the 'Reggie' menu is not
     28    visible try BASE->Reload permissions menu.
     29 8. It should display a list with several error message about missing items.
     30    Click on the "Create missing items" button to create them. If no project
     31    was created in step 6, all annotatation types will be shared with the
     32    'PatientCurator' group, otherwise only some will be shared to the
     33    group and some will be shared to the active project.
     34 9. Done.
    2735
    2836 
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/InstallServlet.java

    r1309 r1310  
    2525import net.sf.basedb.core.Permission;
    2626import net.sf.basedb.core.Project;
     27import net.sf.basedb.core.ProjectKey;
    2728import net.sf.basedb.core.SessionControl;
    2829import net.sf.basedb.core.SharedItem;
     
    8384        }
    8485       
    85         // Annotation type checks
     86        PermissionOptions sharedToActiveProject = null;
     87        int projectId = dc.getSessionControl().getActiveProjectId();
     88        if (projectId != 0)
     89        {
     90          sharedToActiveProject = new PermissionOptions();
     91          sharedToActiveProject.set(Project.getById(dc, projectId), Permission.USE);
     92        }
     93       
     94        // Annotation type checks
     95        // -- the first batch need to be shared to the PatientCurator group
    8696        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_PERSONAL_NUMBER, Item.BIOSOURCE, Type.STRING, 1,
    8797            null, sharedToPatientCurator, createIfMissing));
     
    90100        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_ALL_FIRST_NAMES, Item.BIOSOURCE, Type.STRING, 1,
    91101            null, sharedToPatientCurator, createIfMissing));
     102       
     103        // -- the second batch need only be shared to the active project or to the PatientCurator group
     104        PermissionOptions effectiveOptions = sharedToActiveProject == null ?
     105            sharedToPatientCurator : sharedToActiveProject;
     106
    92107        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_DATE_OF_BIRTH, Item.BIOSOURCE, Type.DATE, 1,
    93             null, sharedToPatientCurator, createIfMissing));
     108            null, effectiveOptions, createIfMissing));
    94109        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_GENDER, Item.BIOSOURCE, Type.STRING, 1,
    95             new EnumerationOptions("F", "M"), sharedToPatientCurator, createIfMissing));
     110            new EnumerationOptions("F", "M"), effectiveOptions, createIfMissing));
    96111        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_LATERALITY, Item.SAMPLE, Type.STRING, 1,
    97             new EnumerationOptions("LEFT", "RIGHT"), sharedToPatientCurator, createIfMissing));
     112            new EnumerationOptions("LEFT", "RIGHT"), effectiveOptions, createIfMissing));
    98113        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_REASON_IF_NO_SPECIMEN, Item.SAMPLE, Type.STRING, 0,
    99             null, sharedToPatientCurator, createIfMissing));
     114            null, effectiveOptions, createIfMissing));
    100115        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_PAD, Item.SAMPLE, Type.STRING, 1,
    101             null, sharedToPatientCurator, createIfMissing));
     116            null, effectiveOptions, createIfMissing));
    102117        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_PAD_CASE, Item.SAMPLE, Type.STRING, 0,
    103             null, sharedToPatientCurator, createIfMissing));
     118            null, effectiveOptions, createIfMissing));
    104119       
    105120        json.put("checks", jsonChecks);
     
    381396  {
    382397    private Map<Group, Permission> groupPermissions;
     398    private Map<Project, Permission> projectPermissions;
    383399    private String message;
    384400   
     
    386402    {
    387403      groupPermissions = new HashMap<Group, Permission>();
     404      projectPermissions = new HashMap<Project, Permission>();
    388405    }
    389406
     
    394411    {
    395412      groupPermissions.put(g, p);
     413    }
     414
     415    /**
     416      Set a permission for the given project.
     417    */
     418    void set(Project pr, Permission p)
     419    {
     420      projectPermissions.put(pr, p);
    396421    }
    397422
     
    403428    boolean checkPermissions(SharedItem item)
    404429    {
     430      ProjectKey pKey = item.getProjectKey();
     431      for (Map.Entry<Project, Permission> entry : projectPermissions.entrySet())
     432      {
     433        Project pr = entry.getKey();
     434        Permission p = entry.getValue();
     435        if (pKey == null || !pKey.getPermissions(pr).contains(p))
     436        {
     437          message = "Not shared to project: " + pr.getName() + " (" + p + ")";
     438          return false;
     439        }
     440      }
    405441      ItemKey key = item.getItemKey();
    406442      for (Map.Entry<Group, Permission> entry : groupPermissions.entrySet())
     
    414450          return false;
    415451        }
    416        
    417452      }
    418453      return true;
     
    439474        mp.addPermissions(g, Collections.singleton(p));
    440475      }
     476      for (Map.Entry<Project, Permission> entry : projectPermissions.entrySet())
     477      {
     478        Project pr = entry.getKey();
     479        Permission p = entry.getValue();
     480        mp.addPermissions(pr, Collections.singleton(p));
     481      }
    441482      mp.updateKeys(item.getDbControl());
    442483    }
Note: See TracChangeset for help on using the changeset viewer.