Opened 8 years ago

Closed 8 years ago

#2025 closed defect (fixed)

It is not always possible to set permissions on newly created items

Reported by: Nicklas Nordborg Owned by: everyone
Priority: major Milestone: BASE 3.9.1
Component: core Version:
Keywords: Cc:

Description

The scenario is a code snippet in a plug-in or extensions that want to create a new item and set access permissions in the same transaction. Depending on the order of calling the methods this may result in a PermissionDeniedException. We use a file as an example:

File f = File.getFile(dc, dir, filename, true); // Creates a new file
dc.saveItem(f);
f.setProjectKey(null); // Do not share to the current project
dc.commit();

In the example above the third line results in a PermissionDeniedException. Switching the order of line 2 and 3 gets rid of the exception in this case. It is however not always possible to re-arrange the code in the working order. If we create a directory instead of a file:

Directory dir = Directory.getNew(dc, path);
dir.setProjectKey(null);

This also results in a PermissionDeniedException. The Directory.getNew() method has an implicit call to DbControl.saveItem (since it may need to create multiple directories for the path).

In any case, since the current user is the owner of the items, it should be possible to set/save items in any order.

Change History (1)

comment:1 by Nicklas Nordborg, 8 years ago

Resolution: fixed
Status: newclosed

(In [7184]) Fixes #2025: It is not always possible to set permissions on newly created items

Note: See TracTickets for help on using tickets.