Skip to content

Commit

Permalink
Add WARNING on group-write graph operation
Browse files Browse the repository at this point in the history
When a user is in a new writeable-group (a new
feature for 5.1.2) *AND* is trying to perform
an operation on an object they don't own, then
print a "WARNING" message before acting. With
the hope that users will first issue a --dry-run,
this will hopefully suffice to prevent false
deletions, etc. The only other option would be
to require confirmation, which would be quite a
new CLI introduction at this point.
  • Loading branch information
joshmoore committed May 14, 2015
1 parent 8719dd8 commit ba35e24
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions components/tools/OmeroPy/src/omero/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1722,13 +1722,48 @@ def main_method(self, args):
if not args.ordered and len(commands) > 1:
commands = self.combine_commands(commands)

for command_check in commands:
self._check_command(command_check)

if len(commands) == 1:
cmd = args.obj[0]
else:
cmd = omero.cmd.DoAll(commands)

self._process_request(cmd, args, client)

def _check_command(self, command_check):
query = self.ctx.get_client().sf.getQueryService()
ec = self.ctx.get_event_context()
own_id = ec.userId
if not command_check or not command_check.targetObjects:
return
for k, v in command_check.targetObjects.items():
query_str = (
"select "
"x.details.owner.id, "
"x.details.group.details.permissions "
"from %s x "
"where x.id = :id") % k
if not v:
return
for w in v:
try:
uid, perms = omero.rtypes.unwrap(
query.projection(
query_str,
omero.sys.ParametersI().addId(w),
{"omero.group": "-1"})[0])
perms = perms["perm"]
perms = omero.model.PermissionsI(perms)
if perms.isGroupWrite() and uid != own_id:
self.ctx.err(
"WARNING: %s:%s belongs to user %s" % (
k, w, uid))
except:
self.ctx.dbg(traceback.format_exc())
# Doing nothing since this is a best effort

def combine_commands(self, commands):
"""
Combine several commands into as few as possible.
Expand Down

0 comments on commit ba35e24

Please sign in to comment.