Changeset 2916


Ignore:
Timestamp:
Nov 15, 2006, 11:07:43 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

References #348: Take ownership of items

Framework is done. Used Biosources as test case. Now it just have to be implemented on all
list and view pages.

Location:
trunk
Files:
3 added
12 edited

Legend:

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

    r2664 r2916  
    8282      if (item.hasPermission(Permission.WRITE) && itemPermissions.contains(Permission.WRITE)) sb.append(sb.length()==0 ? "Write" : ", Write");
    8383      if (item.hasPermission(Permission.DELETE) && itemPermissions.contains(Permission.DELETE)) sb.append(sb.length()==0 ? "Delete" : ", Delete");
    84       if (item.hasPermission(Permission.SET_OWNER) && itemPermissions.contains(Permission.SET_OWNER)) sb.append(sb.length()==0 ? "Change owner" : ", Change owner");
     84      if (item.hasPermission(Permission.SET_OWNER) && itemPermissions.contains(Permission.SET_OWNER)) sb.append(sb.length()==0 ? "Take ownership" : ", Take ownership");
    8585      if (item.hasPermission(Permission.SET_PERMISSION) && itemPermissions.contains(Permission.SET_PERMISSION)) sb.append(sb.length()==0 ? "Change permisson" : ", Change permission");
    8686    }
  • trunk/src/core/net/sf/basedb/core/Ownable.java

    r2304 r2916  
    7070      have permission to change the owner on the item
    7171    @throws InvalidDataException If the owner is null
     72    @see #takeOwnership()
    7273  */
    7374  public void setOwner(User owner)
    7475    throws PermissionDeniedException, InvalidDataException;
    7576
     77  /**
     78    Take ownership of the item.
     79    @throws PermissionDeniedException If the logged in user doesn't have
     80      permission to take ownership
     81    @since 2.2
     82  */
     83  public void takeOwnership()
     84    throws PermissionDeniedException;
     85 
     86  /**
     87    Check if the logged in user is the owner of this item or not.
     88    @return TRUE if the logged in user is the owner, FALSE otherwise
     89    @since 2.2
     90  */
     91  public boolean isOwner();
     92 
    7693}
  • trunk/src/core/net/sf/basedb/core/OwnedItem.java

    r2304 r2916  
    6363    OwnableUtil.setOwner(getData(), owner);
    6464  }
     65  public void takeOwnership()
     66    throws PermissionDeniedException
     67  {
     68    checkPermission(Permission.SET_OWNER);
     69    DbControl dc = getDbControl();
     70    getData().setOwner(HibernateUtil.loadData(
     71      dc.getHibernateSession(), UserData.class, dc.getSessionControl().getLoggedInUserId()));
     72  }
     73  public boolean isOwner()
     74  {
     75    return getData().getOwner().getId() == getSessionControl().getLoggedInUserId();
     76  }
    6577  // -------------------------------------------
    6678
  • trunk/www/admin/plugindefinitions/edit_plugin.jsp

    r2854 r2916  
    817817        <input type="checkbox" name="grant_write" onClick="permissionOnClick(this)">Write<br>
    818818        <input type="checkbox" name="grant_delete" onClick="permissionOnClick(this)">Delete<br>
    819         <input type="checkbox" name="grant_set_owner" onClick="permissionOnClick(this)">Set owner<br>
     819        <input type="checkbox" name="grant_set_owner" onClick="permissionOnClick(this)">Take ownership<br>
    820820        <input type="checkbox" name="grant_set_permission" onClick="permissionOnClick(this)">Set permission
    821821      </td>
     
    827827        <input type="checkbox" name="deny_write" onClick="permissionOnClick(this)">Write<br>
    828828        <input type="checkbox" name="deny_delete" onClick="permissionOnClick(this)">Delete<br>
    829         <input type="checkbox" name="deny_set_owner" onClick="permissionOnClick(this)">Set owner<br>
     829        <input type="checkbox" name="deny_set_owner" onClick="permissionOnClick(this)">Take ownership<br>
    830830        <input type="checkbox" name="deny_set_permission" onClick="permissionOnClick(this)">Set permission
    831831      </td>
  • trunk/www/admin/plugindefinitions/view_plugin.jsp

    r2854 r2916  
    561561        has that permission<br>
    562562        <b>C/c</b> = Create, <b>R/r</b> = Read, <b>U/u</b> = Use,
    563         <b>W/w</b> = Write, <b>D/d</b> = Delete, <b>O/o</b> = Change owner,
     563        <b>W/w</b> = Write, <b>D/d</b> = Delete, <b>O/o</b> = Take ownership,
    564564        <b>P/p</b> = Change permissions
    565565        </td>
  • trunk/www/admin/roles/edit_role.jsp

    r2753 r2916  
    409409      <input type="checkbox" name="write" onClick="setPermissions(this.checked)">Write<br>
    410410      <input type="checkbox" name="delete" onClick="setPermissions(this.checked)">Delete<br>
    411       <input type="checkbox" name="set_owner" onClick="setPermissions(this.checked)">Set owner<br>
     411      <input type="checkbox" name="set_owner" onClick="setPermissions(this.checked)">Take ownership<br>
    412412      <input type="checkbox" name="set_permission" onClick="setPermissions(this.checked)">Set permission<br>
    413413      </td>
  • trunk/www/admin/roles/view_role.jsp

    r2753 r2916  
    288288        <td colspan="99" class="panel">
    289289        <b>C</b> = Create, <b>R</b> = Read, <b>U</b> = Use,
    290         <b>W</b> = Write, <b>D</b> = Delete, <b>O</b> = Change owner, <b>P</b> = Change permissions
     290        <b>W</b> = Write, <b>D</b> = Delete, <b>O</b> = Take ownership, <b>P</b> = Change permissions
    291291       
    292292        </td>
  • trunk/www/biomaterials/biosources/index.jsp

    r2811 r2916  
    4040  import="net.sf.basedb.util.RemovableUtil"
    4141  import="net.sf.basedb.util.ShareableUtil"
     42  import="net.sf.basedb.util.OwnableUtil"
    4243  import="net.sf.basedb.clients.web.Base"
    4344  import="net.sf.basedb.clients.web.WebException"
     
    213214    redirect = "../../common/share/share.jsp?ID="+ID+"&item_type="+itemType.name();
    214215  }
     216  else if ("TakeOwnershipOfItem".equals(cmd))
     217  {
     218    // Take ownership a single item and then return to the view page
     219    dc = sc.newDbControl();
     220    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     221    OwnableUtil.setOwner(dc, itemType, Collections.singleton(cc.getId()), null);
     222    dc.commit();
     223    redirect = viewPage;
     224  }
     225  else if ("TakeOwnershipOfItems".equals(cmd))
     226  {
     227    // Take ownership all selected items on the list page
     228    dc = sc.newDbControl();
     229    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     230    int numTotal = cc.getSelected().size();
     231    int numOwned = OwnableUtil.setOwner(dc, itemType, cc.getSelected(), null);
     232    dc.commit();
     233    if (numTotal != numOwned)
     234    {
     235      message = (numOwned == 0 ? "No" : "Only "+numOwned+" of "+numTotal) + " items could be taken, because you have no SET_OWNER permission";
     236    }
     237    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
     238  }
    215239  else if ("ExportItems".equals(cmd))
    216240  {
  • trunk/www/biomaterials/biosources/list_biosources.jsp

    r2893 r2916  
    141141      frm.submit();
    142142    }
     143    function takeOwnership()
     144    {
     145      var frm = document.forms[formId];
     146      if (Forms.numChecked(frm) == 0)
     147      {
     148        alert('Please select at least one item in the list');
     149        return;
     150      }
     151      if (confirm('Are you sure that you want to take ownership of the selected items? It can\'t be undone.'))
     152      {
     153        frm.action = submitPage;
     154        frm.cmd.value = 'TakeOwnershipOfItems';
     155        frm.submit();
     156      }
     157    }
    143158    function shareItem(itemId)
    144159    {
     
    304319          title="Share&hellip;"
    305320          tooltip="Share the selected items"
     321        />
     322        <tbl:button
     323          image="take_ownership.png"
     324          onclick="takeOwnership()"
     325          title="Take ownership&hellip;"
     326          tooltip="Take ownership of the selected items"
    306327        />
    307328        <tbl:button
  • trunk/www/biomaterials/biosources/view_biosource.jsp

    r2753 r2916  
    8080  final boolean deletePermission = bioSource.hasPermission(Permission.DELETE);
    8181  final boolean sharePermission = bioSource.hasPermission(Permission.SET_PERMISSION);
     82  final boolean setOwnerPermission = bioSource.hasPermission(Permission.SET_OWNER);
     83  final boolean isOwner = bioSource.isOwner();
    8284  %>
    8385
     
    100102    {
    101103      location.replace('index.jsp?ID=<%=ID%>&cmd=RestoreItem&item_id=<%=itemId%>');
     104    }
     105    function takeOwnership()
     106    {
     107      if (confirm('Are you sure that you want to take ownership of this item? It can\'t be undone.'))
     108      {
     109        location.replace('index.jsp?ID=<%=ID%>&cmd=TakeOwnershipOfItem&item_id=<%=itemId%>');
     110      }
    102111    }
    103112    function runPlugin(cmd)
     
    152161        title="Share&hellip;"
    153162        tooltip="<%=sharePermission ? "Share this biosource to other user, groups and projects" : "You do not have permission to share this biosource"%>"
     163      />
     164      <tbl:button
     165        disabled="<%=setOwnerPermission ? false : true%>"
     166        image="<%=setOwnerPermission ? "take_ownership.png" : "take_ownership_disabled.png"%>"
     167        onclick="takeOwnership()"
     168        title="Take ownership&hellip;"
     169        visible="<%=!isOwner%>"
     170        tooltip="<%=setOwnerPermission ? "Take ownership of this item" : "You do not have permission to take ownership of this item"%>"
    154171      />
    155172      <tbl:button
  • trunk/www/common/share/share.jsp

    r2776 r2916  
    381381        <input type="checkbox" name="write" onClick="permissionsOnClick('write')">Write<br>
    382382        <input type="checkbox" name="delete" onClick="permissionsOnClick('delete')">Delete<br>
    383         <input type="checkbox" name="set_owner" onClick="permissionsOnClick('set_owner')">Set owner<br>
     383        <input type="checkbox" name="set_owner" onClick="permissionsOnClick('set_owner')">Take ownership<br>
    384384        <input type="checkbox" name="set_permission" onClick="permissionsOnClick('set_permission')">Set permission<br>
    385385      </td>
  • trunk/www/my_base/projects/edit_project.jsp

    r2776 r2916  
    374374      <input type="checkbox" name="write" onClick="permissionsOnClick('write')">Write<br>
    375375      <input type="checkbox" name="delete" onClick="permissionsOnClick('delete')">Delete<br>
    376       <input type="checkbox" name="set_owner" onClick="permissionsOnClick('set_owner')">Set owner<br>
     376      <input type="checkbox" name="set_owner" onClick="permissionsOnClick('set_owner')">Take ownership<br>
    377377      <input type="checkbox" name="set_permission" onClick="permissionsOnClick('set_permission')">Set permission<br>
    378378    </td>
Note: See TracChangeset for help on using the changeset viewer.