def manage_group_owner(request, action, gid, conn=None, **kwargs): template = "webadmin/group_form_owner.html" userId = conn.getEventContext().userId group = conn.getObject("ExperimenterGroup", gid) memberIds = [m.id for m in group.getMembers()] ownerIds = [e.id for e in group.getOwners()] experimenters = list(conn.getObjects("Experimenter")) experimenterDefaultIds = list() for e in experimenters: if e != userId and e.getDefaultGroup() is not None and e.getDefaultGroup().id == group.id: experimenterDefaultIds.append(str(e.id)) msgs = [] if action == 'edit': permissions = getActualPermissions(group) form = GroupOwnerForm(initial={'permissions': permissions, 'members':memberIds, 'owners':ownerIds, 'experimenters':experimenters}) context = {'form':form, 'gid': gid, 'permissions': permissions, 'group':group, 'experimenterDefaultGroups':",".join(experimenterDefaultIds), 'ownerIds':(",".join(str(x) for x in ownerIds if x != userId)), 'userId':userId} elif action == "save": if request.method != 'POST': return HttpResponseRedirect(reverse(viewname="wamyaccount", args=["edit", group.id])) else: form = GroupOwnerForm(data=request.POST.copy(), initial={'experimenters':experimenters}) if form.is_valid(): members = form.cleaned_data['members'] owners = form.cleaned_data['owners'] permissions = form.cleaned_data['permissions'] listOfOwners = getSelectedExperimenters(conn, owners) conn.setOwnersOfGroup(group, listOfOwners) permissions = int(permissions) if getActualPermissions(group) != permissions: perm = setActualPermissions(permissions) conn.updatePermissions(group, perm) new_members = getSelectedExperimenters(conn, members) removalFails = conn.setMembersOfGroup(group, new_members) if len(removalFails) == 0: return HttpResponseRedirect(reverse("wamyaccount")) # If we've failed to remove user... # prepare error messages for e in removalFails: url = reverse("wamanageexperimenterid", args=["edit", e.id]) msgs.append("Can't remove user <a href='%s'>%s</a> from their only group" % (url, e.getFullName())) # refresh the form and add messages form = GroupOwnerForm(initial={'permissions': permissions, 'members':memberIds, 'owners':ownerIds, 'experimenters':experimenters}) context = {'form':form, 'gid': gid, 'permissions': permissions, 'group':group, 'experimenterDefaultGroups':",".join(experimenterDefaultIds), 'ownerIds':(",".join(str(x) for x in ownerIds if x != userId)), 'userId':userId} else: return HttpResponseRedirect(reverse("wamyaccount")) context['template'] = template if len(msgs) > 0: context['ome'] = {} context['ome']['message'] = "<br>".join(msgs) return context
def getEditFormContext(): group = conn.getObject("ExperimenterGroup", gid) memberIds = [m.id for m in group.getMembers()] ownerIds = [e.id for e in group.getOwners()] permissions = getActualPermissions(group) form = GroupOwnerForm( initial={ 'permissions': permissions, 'members': memberIds, 'owners': ownerIds, 'experimenters': experimenters }) context = { 'form': form, 'gid': gid, 'permissions': permissions, "group": group } experimenterDefaultIds = list() for e in experimenters: if (e != userId and e.getDefaultGroup() is not None and e.getDefaultGroup().id == group.id): experimenterDefaultIds.append(str(e.id)) context['experimenterDefaultGroups'] = ",".join(experimenterDefaultIds) context['ownerIds'] = (",".join( str(x) for x in ownerIds if x != userId)) return context
def manage_group_owner(request, action, gid, conn=None, **kwargs): template = "webadmin/group_form_owner.html" userId = conn.getEventContext().userId group = conn.getObject("ExperimenterGroup", gid) memberIds = [m.id for m in group.getMembers()] ownerIds = [e.id for e in group.getOwners()] experimenters = list(conn.getObjects("Experimenter")) experimenterDefaultIds = list() for e in experimenters: if e != userId and e.getDefaultGroup() is not None and e.getDefaultGroup().id == group.id: experimenterDefaultIds.append(str(e.id)) if action == 'edit': permissions = getActualPermissions(group) form = GroupOwnerForm(initial={'permissions': permissions, 'members':memberIds, 'owners':ownerIds, 'experimenters':experimenters}) context = {'form':form, 'gid': gid, 'permissions': permissions, 'group':group, 'experimenterDefaultGroups':",".join(experimenterDefaultIds), 'ownerIds':(",".join(str(x) for x in ownerIds if x != userId)), 'userId':userId} elif action == "save": if request.method != 'POST': return HttpResponseRedirect(reverse(viewname="wamyaccount", args=["edit", group.id])) else: form = GroupOwnerForm(data=request.POST.copy(), initial={'experimenters':experimenters}) if form.is_valid(): members = form.cleaned_data['members'] owners = form.cleaned_data['owners'] permissions = form.cleaned_data['permissions'] listOfOwners = getSelectedExperimenters(conn, owners) conn.setOwnersOfGroup(group, listOfOwners) new_members = getSelectedExperimenters(conn, members) conn.setMembersOfGroup(group, new_members) permissions = int(permissions) if getActualPermissions(group) != permissions: perm = setActualPermissions(permissions) conn.updatePermissions(group, perm) return HttpResponseRedirect(reverse("wamyaccount")) context = {'form':form, 'gid': gid, 'permissions': permissions, 'group':group, 'experimenterDefaultGroups':",".join(experimenterDefaultIds), 'ownerIds':(",".join(str(x) for x in ownerIds if x != userId)), 'userId':userId} else: return HttpResponseRedirect(reverse("wamyaccount")) context['template'] = template return context
def manage_group_owner(request, action, gid, **kwargs): myaccount = True template = "webadmin/group_form_owner.html" conn = None try: conn = kwargs["conn"] except: logger.error(traceback.format_exc()) info = {'today': _("Today is %(tday)s") % {'tday': datetime.date.today()}, 'myaccount':myaccount} eventContext = {'userName':conn.getEventContext().userName, 'isAdmin':conn.getEventContext().isAdmin, 'version': request.session.get('version')} controller = BaseGroup(conn, gid) if action == 'edit': permissions = controller.getActualPermissions() form = GroupOwnerForm(initial={'permissions': permissions, 'readonly': controller.isReadOnly()}) context = {'info':info, 'eventContext':eventContext, 'form':form, 'gid': gid, 'permissions': permissions, 'group':controller.group, 'owners':controller.getOwnersNames()} elif action == "save": if request.method != 'POST': return HttpResponseRedirect(reverse(viewname="wamyaccount", args=["edit", controller.group.id])) else: form = GroupOwnerForm(data=request.POST.copy()) if form.is_valid(): permissions = form.cleaned_data['permissions'] readonly = toBoolean(form.cleaned_data['readonly']) controller.updatePermissions(permissions, readonly) return HttpResponseRedirect(reverse("wamyaccount")) context = {'info':info, 'eventContext':eventContext, 'form':form, 'gid': gid} else: return HttpResponseRedirect(reverse("wamyaccount")) t = template_loader.get_template(template) c = Context(request, context) rsp = t.render(c) return HttpResponse(rsp)
def manage_group_owner(request, action, gid, conn=None, **kwargs): template = "webadmin/group_form_owner.html" userId = conn.getEventContext().userId group = conn.getObject("ExperimenterGroup", gid) memberIds = [m.id for m in group.getMembers()] ownerIds = [e.id for e in group.getOwners()] experimenters = list(conn.getObjects("Experimenter")) experimenterDefaultIds = list() for e in experimenters: if e != userId and e.getDefaultGroup( ) is not None and e.getDefaultGroup().id == group.id: experimenterDefaultIds.append(str(e.id)) if action == 'edit': permissions = getActualPermissions(group) form = GroupOwnerForm( initial={ 'permissions': permissions, 'members': memberIds, 'owners': ownerIds, 'experimenters': experimenters }) context = { 'form': form, 'gid': gid, 'permissions': permissions, 'group': group, 'experimenterDefaultGroups': ",".join(experimenterDefaultIds), 'ownerIds': (",".join(str(x) for x in ownerIds if x != userId)), 'userId': userId } elif action == "save": if request.method != 'POST': return HttpResponseRedirect( reverse(viewname="wamyaccount", args=["edit", group.id])) else: form = GroupOwnerForm(data=request.POST.copy(), initial={'experimenters': experimenters}) if form.is_valid(): members = form.cleaned_data['members'] owners = form.cleaned_data['owners'] permissions = form.cleaned_data['permissions'] listOfOwners = getSelectedExperimenters(conn, owners) conn.setOwnersOfGroup(group, listOfOwners) new_members = getSelectedExperimenters(conn, members) conn.setMembersOfGroup(group, new_members) permissions = int(permissions) if getActualPermissions(group) != permissions: perm = setActualPermissions(permissions) conn.updatePermissions(group, perm) return HttpResponseRedirect(reverse("wamyaccount")) context = { 'form': form, 'gid': gid, 'permissions': permissions, 'group': group, 'experimenterDefaultGroups': ",".join(experimenterDefaultIds), 'ownerIds': (",".join(str(x) for x in ownerIds if x != userId)), 'userId': userId } else: return HttpResponseRedirect(reverse("wamyaccount")) context['template'] = template return context
def manage_group_owner(request, action, gid, conn=None, **kwargs): template = "webadmin/group_form_owner.html" group = conn.getObject("ExperimenterGroup", gid) experimenters = list(conn.getObjects("Experimenter")) userId = conn.getEventContext().userId def getEditFormContext(): group = conn.getObject("ExperimenterGroup", gid) memberIds = [m.id for m in group.getMembers()] ownerIds = [e.id for e in group.getOwners()] permissions = getActualPermissions(group) form = GroupOwnerForm(initial={'permissions': permissions, 'members':memberIds, 'owners':ownerIds, 'experimenters':experimenters}) context = {'form':form, 'gid': gid, 'permissions': permissions, "group": group} experimenterDefaultIds = list() for e in experimenters: if e != userId and e.getDefaultGroup() is not None and e.getDefaultGroup().id == group.id: experimenterDefaultIds.append(str(e.id)) context['experimenterDefaultGroups'] = ",".join(experimenterDefaultIds) context['ownerIds'] = (",".join(str(x) for x in ownerIds if x != userId)) return context msgs = [] if action == 'edit': context = getEditFormContext() elif action == "save": if request.method != 'POST': return HttpResponseRedirect(reverse(viewname="wamyaccount", args=["edit", group.id])) else: form = GroupOwnerForm(data=request.POST.copy(), initial={'experimenters':experimenters}) if form.is_valid(): members = form.cleaned_data['members'] owners = form.cleaned_data['owners'] permissions = form.cleaned_data['permissions'] listOfOwners = getSelectedExperimenters(conn, owners) conn.setOwnersOfGroup(group, listOfOwners) new_members = getSelectedExperimenters(conn, members) removalFails = conn.setMembersOfGroup(group, new_members) permissions = int(permissions) permissions_error = False if getActualPermissions(group) != permissions: perm = setActualPermissions(permissions) try: conn.updatePermissions(group, perm) except omero.SecurityViolation, ex: permissions_error = True if ex.message.startswith('Cannot change permissions'): msgs.append("Downgrade to private group not currently possible") else: msgs.append(ex.message) if len(removalFails) == 0 and not permissions_error: return HttpResponseRedirect(reverse("wamyaccount")) # If we've failed to remove user... # prepare error messages for e in removalFails: url = reverse("wamanageexperimenterid", args=["edit", e.id]) msgs.append("Can't remove user <a href='%s'>%s</a> from their only group" % (url, e.getFullName())) # refresh the form and add messages context = getEditFormContext()