Changeset 7212


Ignore:
Timestamp:
Oct 19, 2016, 2:16:14 PM (6 years ago)
Author:
Nicklas Nordborg
Message:

References #2034: New permission for annotating items

The "Share" dialog has been updated with "Annotate" permission. The option is only displayed if sharing items that are annotatable.

We need to modify the Item definitions for all annotatable item types so that the "Permissions" property on the "Properties" tab include the "Annotate" permission. This information is generated by the PermissionUtil class.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/PermissionUtil.java

    r7052 r7212  
    7979      if (item.hasPermission(Permission.READ) && itemPermissions.contains(Permission.READ)) sb.append("Read");   
    8080      if (item.hasPermission(Permission.USE) && itemPermissions.contains(Permission.USE)) sb.append(sb.length()==0 ? "Use" : ", Use");
     81      if (item.hasPermission(Permission.RESTRICTED_WRITE) && itemPermissions.contains(Permission.RESTRICTED_WRITE)) sb.append(sb.length()==0 ? "Annotate" : ", Annotate");
    8182      if (item.hasPermission(Permission.WRITE) && itemPermissions.contains(Permission.WRITE)) sb.append(sb.length()==0 ? "Write" : ", Write");
    8283      if (item.hasPermission(Permission.DELETE) && itemPermissions.contains(Permission.DELETE)) sb.append(sb.length()==0 ? "Delete" : ", Delete");
     
    8889      if(item.hasPermission(Permission.READ)) sb.append("Read");
    8990      if (item.hasPermission(Permission.USE)) sb.append(sb.length()==0 ? "Use" : ", Use");
     91      if (item.hasPermission(Permission.RESTRICTED_WRITE)) sb.append(sb.length()==0 ? "Annotate" : ", Annotate");
    9092      if (item.hasPermission(Permission.WRITE)) sb.append(sb.length()==0 ? "Write" : ", Write");
    9193      if (item.hasPermission(Permission.DELETE)) sb.append(sb.length()==0 ? "Delete" : ", Delete");
     
    225227  }
    226228 
    227   public static String translatePermissionsToString(Set<Permission> permissions)
     229  public static String translatePermissionsToString(Set<Permission> permissions, String restrictedWrite)
    228230  {
    229231    StringBuilder permissionString = new StringBuilder();
    230232    permissionString.append(permissions.contains(Permission.READ) ? "R" : "-");
    231233    permissionString.append(permissions.contains(Permission.USE) ? "U" : "-");
     234    if (restrictedWrite != null)
     235    {
     236      permissionString.append(permissions.contains(Permission.RESTRICTED_WRITE) ? restrictedWrite : "-");
     237    }
    232238    permissionString.append(permissions.contains(Permission.WRITE) ? "W" : "-");
    233239    permissionString.append(permissions.contains(Permission.DELETE) ? "D" : "-");
  • trunk/src/core/net/sf/basedb/core/Item.java

    r6990 r7212  
    182182    The item is a {@link Protocol}.
    183183  */
    184   PROTOCOL(101, "Protocol", "prl", Protocol.class, ProtocolData.class, DefinedPermissions.shareable,
     184  PROTOCOL(101, "Protocol", "prl", Protocol.class, ProtocolData.class, DefinedPermissions.shareable_annotatable,
    185185    740),
    186186  /*
     
    194194    The item is a {@link Hardware}.
    195195  */
    196   HARDWARE(121, "Hardware", "hw", Hardware.class, HardwareData.class, DefinedPermissions.shareable,
     196  HARDWARE(121, "Hardware", "hw", Hardware.class, HardwareData.class, DefinedPermissions.shareable_annotatable,
    197197    700),
    198198  /**
    199199    The item is a {@link Software}.
    200200  */
    201   SOFTWARE(123, "Software", "sw", Software.class, SoftwareData.class, DefinedPermissions.shareable,
     201  SOFTWARE(123, "Software", "sw", Software.class, SoftwareData.class, DefinedPermissions.shareable_annotatable,
    202202    720),
    203203
     
    206206    @since 3.7
    207207  */
    208   KIT(125, "Kit", "kt", Kit.class, KitData.class, DefinedPermissions.shareable,
     208  KIT(125, "Kit", "kt", Kit.class, KitData.class, DefinedPermissions.shareable_annotatable,
    209209    730),
    210210
     
    231231    The item is an {@link ItemList}
    232232  */
    233   ITEMLIST(209, "Item list", "ils", ItemList.class, ItemListData.class, DefinedPermissions.shareable,
     233  ITEMLIST(209, "Item list", "ils", ItemList.class, ItemListData.class, DefinedPermissions.shareable_annotatable,
    234234      11),
    235235  /**
     
    330330    The item is a {@link BioSource}.
    331331  */
    332   BIOSOURCE(201, "Biosource", "bs", BioSource.class, BioSourceData.class, DefinedPermissions.shareable,
     332  BIOSOURCE(201, "Biosource", "bs", BioSource.class, BioSourceData.class, DefinedPermissions.shareable_annotatable,
    333333    430),
    334334  /**
    335335    The item is a {@link Sample}.
    336336  */
    337   SAMPLE(202, "Sample", "smp", Sample.class, SampleData.class, DefinedPermissions.shareable,
     337  SAMPLE(202, "Sample", "smp", Sample.class, SampleData.class, DefinedPermissions.shareable_annotatable,
    338338    420),
    339339  /**
    340340    The item is an {@link Extract}.
    341341  */
    342   EXTRACT(203, "Extract", "xtr", Extract.class, ExtractData.class, DefinedPermissions.shareable,
     342  EXTRACT(203, "Extract", "xtr", Extract.class, ExtractData.class, DefinedPermissions.shareable_annotatable,
    343343    410),
    344344
     
    355355    The item is a {@link Tag}.
    356356  */
    357   TAG(206, "Tag", "tag", Tag.class, TagData.class, DefinedPermissions.shareable,
     357  TAG(206, "Tag", "tag", Tag.class, TagData.class, DefinedPermissions.shareable_annotatable,
    358358    440),
    359359
     
    361361    The item is a {@link BioPlate}
    362362   */
    363   BIOPLATE(207, "Bioplate", "bpl", BioPlate.class, BioPlateData.class, DefinedPermissions.shareable,
     363  BIOPLATE(207, "Bioplate", "bpl", BioPlate.class, BioPlateData.class, DefinedPermissions.shareable_annotatable,
    364364      460),
    365365
     
    407407    The item is a {@link Plate}.
    408408  */
    409   PLATE(222, "Plate", "pla", Plate.class, PlateData.class, DefinedPermissions.shareable,
     409  PLATE(222, "Plate", "pla", Plate.class, PlateData.class, DefinedPermissions.shareable_annotatable,
    410410    600),
    411411  /**
     
    439439    The item is an {@link ArrayDesign}.
    440440  */
    441   ARRAYDESIGN(241, "Array design", "ard", ArrayDesign.class, ArrayDesignData.class, DefinedPermissions.shareable,
     441  ARRAYDESIGN(241, "Array design", "ard", ArrayDesign.class, ArrayDesignData.class, DefinedPermissions.shareable_annotatable,
    442442    520),
    443443  /**
    444444    The item is an {@link ArrayBatch}.
    445445  */
    446   ARRAYBATCH(242, "Array batch", "arb", ArrayBatch.class, ArrayBatchData.class, DefinedPermissions.shareable,
     446  ARRAYBATCH(242, "Array batch", "arb", ArrayBatch.class, ArrayBatchData.class, DefinedPermissions.shareable_annotatable,
    447447    510),
    448448  /**
    449449    The item is an {@link ArraySlide}.
    450450  */
    451   ARRAYSLIDE(243, "Array slide", "ars", ArraySlide.class, ArraySlideData.class, DefinedPermissions.shareable,
     451  ARRAYSLIDE(243, "Array slide", "ars", ArraySlide.class, ArraySlideData.class, DefinedPermissions.shareable_annotatable,
    452452    500),
    453453  /**
     
    476476    The item is a {@link PhysicalBioAssay}.
    477477  */
    478   PHYSICALBIOASSAY(267, "Physical bioassay", "pba", PhysicalBioAssay.class, PhysicalBioAssayData.class, DefinedPermissions.shareable,
     478  PHYSICALBIOASSAY(267, "Physical bioassay", "pba", PhysicalBioAssay.class, PhysicalBioAssayData.class, DefinedPermissions.shareable_annotatable,
    479479    350),
    480480
     
    482482    The item is a {@link DerivedBioAssay}.
    483483  */
    484   DERIVEDBIOASSAY(268, "Derived bioassay", "dba", DerivedBioAssay.class, DerivedBioAssayData.class, DefinedPermissions.shareable,
     484  DERIVEDBIOASSAY(268, "Derived bioassay", "dba", DerivedBioAssay.class, DerivedBioAssayData.class, DefinedPermissions.shareable_annotatable,
    485485    330),
    486486   
     
    488488    The item is a {@link RawBioAssay}.
    489489  */
    490   RAWBIOASSAY(264, "Raw bioassay", "rba", RawBioAssay.class, RawBioAssayData.class, DefinedPermissions.shareable,
     490  RAWBIOASSAY(264, "Raw bioassay", "rba", RawBioAssay.class, RawBioAssayData.class, DefinedPermissions.shareable_annotatable,
    491491    300),
    492492   
     
    517517    The item is a {@link PluginDefinition}
    518518  */
    519   PLUGINDEFINITION(282, "Plugin definition", "pld", PluginDefinition.class, PluginDefinitionData.class, DefinedPermissions.shareable,
     519  PLUGINDEFINITION(282, "Plugin definition", "pld", PluginDefinition.class, PluginDefinitionData.class, DefinedPermissions.shareable_annotatable,
    520520    1050),
    521521  /**
    522522    The item is a {@link PluginConfiguration}
    523523  */
    524   PLUGINCONFIGURATION(283, "Plugin configuration", "plc", PluginConfiguration.class, PluginConfigurationData.class, DefinedPermissions.shareable,
     524  PLUGINCONFIGURATION(283, "Plugin configuration", "plc", PluginConfiguration.class, PluginConfigurationData.class, DefinedPermissions.shareable_annotatable,
    525525    1040),
    526526  /**
     
    10251025    private static final Set<Permission> ownable = Collections.unmodifiableSet(EnumSet.of(Permission.CREATE, Permission.READ, Permission.USE, Permission.WRITE, Permission.DELETE, Permission.SET_OWNER));
    10261026    private static final Set<Permission> shareable = Collections.unmodifiableSet(EnumSet.of(Permission.CREATE, Permission.READ, Permission.USE, Permission.WRITE, Permission.DELETE, Permission.SET_OWNER, Permission.SET_PERMISSION));
     1027    private static final Set<Permission> shareable_annotatable = Collections.unmodifiableSet(EnumSet.of(Permission.CREATE, Permission.READ, Permission.USE, Permission.RESTRICTED_WRITE, Permission.WRITE, Permission.DELETE, Permission.SET_OWNER, Permission.SET_PERMISSION));
    10271028  }
    10281029
  • trunk/src/core/net/sf/basedb/core/MultiPermissions.java

    r7189 r7212  
    9696  private final Map<ItemKey, GroupPermissions> groupPermissions;
    9797  private final Map<ProjectKey, ProjectPermissions> projectPermissions;
     98  private final boolean hasAnnotatableItem;
    9899
    99100  /**
     
    112113    this.groupPermissions = new HashMap<ItemKey, GroupPermissions>();
    113114    this.projectPermissions = new HashMap<ProjectKey, ProjectPermissions>();
     115    boolean foundAnAnnotatableItem = false;
    114116    for (SharedItem item : itemsToShare)
    115117    {
     118      if (item instanceof Annotatable) foundAnAnnotatableItem = true;
    116119      if (items.add(item))
    117120      {
     
    129132      }
    130133    }
    131   }
    132 
     134    this.hasAnnotatableItem = foundAnAnnotatableItem;
     135  }
     136
     137  /**
     138    Is any of the items to share an annotatable item?
     139    @since 3.10
     140  */
     141  public boolean hasAnnotatableItem()
     142  {
     143    return hasAnnotatableItem;
     144  }
     145 
    133146  /**
    134147    Grant permissions to a user. Use an empty <code>Set</code> or null
  • trunk/www/common/share/list_share.jsp

    r5946 r7212  
    3131  import="net.sf.basedb.core.Permission"
    3232  import="net.sf.basedb.core.SharedItem"
     33  import="net.sf.basedb.core.Annotatable"
    3334  import="net.sf.basedb.core.User"
    3435  import="net.sf.basedb.core.Group"
     
    5758{
    5859  SharedItem item = (SharedItem)itemType.getById(dc, itemId);
     60  String useRestrictedWrite = item instanceof Annotatable ? "A" : null;
    5961  MultiPermissions mp = new MultiPermissions(Collections.singleton(item));
    6062  List<User> users = mp.getUsers().list(dc);
     
    119121                  /><%=Base.getLinkedName(ID, project, false, true)%></tbl:cell>
    120122                  <tbl:cell column="permissions">
    121                     <%=PermissionUtil.translatePermissionsToString(permissions)%>
     123                    <%=PermissionUtil.translatePermissionsToString(permissions, useRestrictedWrite)%>
    122124                  </tbl:cell>
    123125                </tbl:row>
     
    136138                  /><%=Base.getLinkedName(ID, group, false, true)%></tbl:cell>
    137139                  <tbl:cell column="permissions">
    138                     <%=PermissionUtil.translatePermissionsToString(permissions)%>
     140                    <%=PermissionUtil.translatePermissionsToString(permissions, useRestrictedWrite)%>
    139141                  </tbl:cell>
    140142                </tbl:row>
     
    153155                  /><%=Base.getLinkedName(ID, user, false, true)%></tbl:cell>
    154156                  <tbl:cell column="permissions">
    155                     <%=PermissionUtil.translatePermissionsToString(permissions)%>
     157                    <%=PermissionUtil.translatePermissionsToString(permissions, useRestrictedWrite)%>
    156158                  </tbl:cell>
    157159                </tbl:row>
  • trunk/www/common/share/share.js

    r7030 r7212  
    2727  var EVERYONE_ID;
    2828  var SHARE_TO_EVERYONE;
     29  var USE_RESTRICTED_WRITE;
    2930  var Permission = {};
    3031 
     
    3536    Permission.READ = Data.int('page-data', 'read');
    3637    Permission.USE = Data.int('page-data', 'use');
     38    Permission.RESTRICTED_WRITE = Data.int('page-data', 'restricted-write');
    3739    Permission.WRITE = Data.int('page-data', 'write');
    3840    Permission.DELETE = Data.int('page-data', 'delete');
     
    5759    Events.addEventHandler('read', 'click', share.permissionsOnClick);
    5860    Events.addEventHandler('use', 'click', share.permissionsOnClick);
     61    Events.addEventHandler('restricted_write', 'click', share.permissionsOnClick);
    5962    Events.addEventHandler('write', 'click', share.permissionsOnClick);
    6063    Events.addEventHandler('delete', 'click', share.permissionsOnClick);
     
    6568    EVERYONE_ID = Data.int('page-data', 'everyone-id');
    6669    SHARE_TO_EVERYONE = Data.int('page-data', 'share-to-everyone');
     70    USE_RESTRICTED_WRITE = Data.int('page-data', 'use-restricted-write');
    6771  }
    6872
     
    256260      s += permissionCode & Permission.READ ? "R" : "-";
    257261      s += permissionCode & Permission.USE ? "U" : "-";
     262      if (USE_RESTRICTED_WRITE)
     263      {
     264        s += permissionCode & Permission.RESTRICTED_WRITE ? "A" : "-";
     265      }
    258266      s += permissionCode & Permission.WRITE ? "W" : "-";
    259267      s += permissionCode & Permission.DELETE ? "D" : "-";
     
    277285    if (frm['read'].checked) c += Permission.READ;
    278286    if (frm['use'].checked) c += Permission.USE;
     287    if (frm['restricted_write'].checked) c += Permission.RESTRICTED_WRITE;
    279288    if (frm['write'].checked) c += Permission.WRITE;
    280289    if (frm['delete'].checked) c += Permission.DELETE;
     
    294303    {
    295304      frm['write'].checked = frm['write'].checked || frm['delete'].checked || frm['set_owner'].checked || frm['set_permission'].checked;
     305      frm['restricted_write'].checked = frm['restricted_write'].checked || frm['write'].checked;
    296306      frm['use'].checked = frm['use'].checked || frm['write'].checked;
    297       frm['read'].checked = frm['read'].checked || frm['use'].checked;
     307      frm['read'].checked = frm['read'].checked || frm['use'].checked || frm['restricted_write'].checked;
    298308    }
    299309    else
    300310    {
    301311      frm['use'].checked = frm['use'].checked && frm['read'].checked;
    302       frm['write'].checked = frm['write'].checked && frm['use'].checked;
     312      frm['restricted_write'].checked = frm['restricted_write'].checked && frm['read'].checked;
     313      frm['write'].checked = frm['write'].checked && frm['use'].checked && frm['restricted_write'].checked;
    303314      frm['delete'].checked = frm['delete'].checked && frm['write'].checked;
    304315      frm['set_owner'].checked = frm['set_owner'].checked && frm['write'].checked;
     
    317328    frm['read'].checked = permissionCode & Permission.READ;
    318329    frm['use'].checked = permissionCode & Permission.USE;
     330    frm['restricted_write'].checked = permissionCode & Permission.RESTRICTED_WRITE;
    319331    frm['write'].checked = permissionCode & Permission.WRITE;
    320332    frm['delete'].checked = permissionCode & Permission.DELETE;
     
    325337    frm['read'].disabled = disabled;
    326338    frm['use'].disabled = disabled;
     339    frm['restricted_write'].disabled = disabled || !USE_RESTRICTED_WRITE;
    327340    frm['write'].disabled = disabled;
    328341    frm['delete'].disabled = disabled;
  • trunk/www/common/share/share.jsp

    r6608 r7212  
    6868private static final int READ_CODE = PermissionUtil.getPermissionCode(EnumSet.of(Permission.READ));
    6969private static final int USE_CODE = PermissionUtil.getPermissionCode(EnumSet.of(Permission.USE));
     70private static final int RESTRICTED_WRITE_CODE = PermissionUtil.getPermissionCode(EnumSet.of(Permission.RESTRICTED_WRITE));
    7071private static final int WRITE_CODE = PermissionUtil.getPermissionCode(EnumSet.of(Permission.WRITE));
    7172private static final int DELETE_CODE = PermissionUtil.getPermissionCode(EnumSet.of(Permission.DELETE));
     
    9192  }
    9293
     94  final boolean hasAnnotatableItem = mp.hasAnnotatableItem();
    9395  JSONArray jsonShare = new JSONArray();
    9496
     
    113115          Set<Permission> first = p.values().iterator().next();
    114116          permissionCode = PermissionUtil.getPermissionCode(first);
    115           permissionString = PermissionUtil.translatePermissionsToString(first);
     117          permissionString = PermissionUtil.translatePermissionsToString(first, hasAnnotatableItem ? "A" : null);
    116118        }
    117119        json.put("name", user.getName() + " [" + permissionString + "]");
     
    142144          Set<Permission> first = p.values().iterator().next();
    143145          permissionCode = PermissionUtil.getPermissionCode(first);
    144           permissionString = PermissionUtil.translatePermissionsToString(first);
     146          permissionString = PermissionUtil.translatePermissionsToString(first, hasAnnotatableItem ? "A" : null);
    145147        }
    146148        json.put("name", group.getName() + " [" + permissionString + "]");
     
    170172          Set<Permission> first = p.values().iterator().next();
    171173          permissionCode = PermissionUtil.getPermissionCode(first);
    172           permissionString = PermissionUtil.translatePermissionsToString(first);
     174          permissionString = PermissionUtil.translatePermissionsToString(first, hasAnnotatableItem ? "A" : null);
    173175        }
    174176        json.put("name", project.getName() + " [" + permissionString + "]");
     
    218220      data-read="<%=READ_CODE%>"
    219221      data-use="<%=USE_CODE%>"
     222      data-restricted-write="<%=RESTRICTED_WRITE_CODE%>"
    220223      data-write="<%=WRITE_CODE%>"
    221224      data-delete="<%=DELETE_CODE%>"
     
    224227      data-everyone-id="<%=SystemItems.getId(Group.EVERYONE)%>"
    225228      data-share-to-everyone="<%=sc.hasSystemPermission(Permission.SHARE_TO_EVERYONE) ? 1 : 0%>"
     229      data-use-restricted-write="<%=hasAnnotatableItem ? 1 : 0 %>"
    226230      ></div>
    227231   
     
    252256        <input type="checkbox" id="read" checked name="read"><label for="read">Read</label><br>
    253257        <input type="checkbox" id="use" checked name="use"><label for="use">Use</label><br>
     258        <span style="<%=hasAnnotatableItem ? "" : "display: none;"%>">
     259        <input type="checkbox" id="restricted_write" name="restricted_write"><label for="restricted_write">Annotate</label><br>
     260        </span>
    254261        <input type="checkbox" id="write" name="write"><label for="write">Write</label><br>
    255262        <input type="checkbox" id="delete" name="delete"><label for="delete">Delete</label><br>
Note: See TracChangeset for help on using the changeset viewer.