Skip to content

Commit

Permalink
Use try/finally to make sure we revertGroupForSession()
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed May 10, 2023
1 parent ce5aded commit 4491c05
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions omeroweb/webclient/webclient_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -1479,8 +1479,7 @@ def updateGroup(self, group, name, permissions, description=None):

temp_switch = False
if self.getEventContext().groupId == group.id:
# can't update current group
temp_switch = True
# we can't update the current group
# find a group to temp switch to...
gids = [
gid
Expand All @@ -1490,26 +1489,28 @@ def updateGroup(self, group, name, permissions, description=None):
if len(gids) == 0:
return ["You can't edit your current group!"]
self.setGroupForSession(gids[0])

up_gr = group._obj
up_gr.name = rstring(str(name))
up_gr.description = (
(description != "" and description is not None)
and rstring(str(description))
or None
)
temp_switch = True

msgs = []
admin_serv = self.getAdminService()
admin_serv.updateGroup(up_gr)
try:
up_gr = group._obj
up_gr.name = rstring(str(name))
up_gr.description = (
(description != "" and description is not None)
and rstring(str(description))
or None
)

if str(permissions) != str(up_gr.details.getPermissions()):
err = self.updatePermissions(group, permissions)
if err is not None:
msgs.append(err)
admin_serv = self.getAdminService()
admin_serv.updateGroup(up_gr)

if temp_switch:
self.revertGroupForSession()
if str(permissions) != str(up_gr.details.getPermissions()):
err = self.updatePermissions(group, permissions)
if err is not None:
msgs.append(err)
finally:
if temp_switch:
self.revertGroupForSession()
return msgs

def updateMyAccount(
Expand Down

0 comments on commit 4491c05

Please sign in to comment.