def edit(me, group, name, access, desc, displayPic): """update group meta info. Only group-admin can edit group meta info. Keyword params: @me: @group: @name: name of the group. @access: group access type (open/closed). @desc: description of the group. @displayPic: profile pic of the group. """ if me.id not in group.admins: raise errors.PermissionDenied('Only administrator can edit group meta data') if name: start = name.lower() + ':' cols = yield db.get_slice(me.basic['org'], "entityGroupsMap", start=start, count=1) for col in cols: name_, groupId_ = col.column.name.split(':') if name_ == name.lower() and groupId_ != group.id: raise errors.InvalidGroupName(name) meta = {'basic': {}} if name and name != group.basic['name']: meta['basic']['name'] = name if desc and desc != group.basic.get('desc', ''): meta['basic']['desc'] = desc if access in ['closed', 'open'] and access != group.basic['access']: meta['basic']['access'] = access if displayPic: avatar = yield saveAvatarItem(group.id, me.basic['org'], displayPic) meta['basic']['avatar'] = avatar if name and name != group.basic["name"]: members = yield db.get_slice(group.id, "groupMembers") members = utils.columnsToDict(members).keys() entities = members + [me.basic['org']] oldColName = "%s:%s" % (group.basic["name"].lower(), group.id) colname = '%s:%s' % (name.lower(), group.id) mutations = {} for entity in entities: mutations[entity] = {'entityGroupsMap': {colname: '', oldColName: None}} #XXX:notify group-members about the change in name yield db.batch_mutate(mutations) if meta['basic']: yield db.batch_insert(group.id, 'entities', meta) if not desc and group.basic.get('desc', ''): yield db.remove(group.id, "entities", 'desc', 'basic') if (not desc and group.basic.get('desc', '')) or meta['basic']: defer.returnValue(True)
def _updateOrgInfo(self, request): (appchange, script, args, myId) = yield self._getBasicArgs(request) orgId = args["orgId"] org = args['org'] name = utils.getRequestArg(request, "name") dp = utils.getRequestArg(request, "dp", sanitize=False) orgInfo, orgDetails = {}, {} if dp: avatar = yield saveAvatarItem(orgId, orgId, dp, isLogo=True) orgInfo["basic"] = {} orgInfo["basic"]["logo"] = avatar org.basic['logo'] = avatar orgDetails["logo"] = utils.companyLogo(org) if name: if "basic" not in orgInfo: orgInfo["basic"] = {} orgInfo["basic"]["name"] = name args['org'].basic['name'] = name orgDetails["name"] = name if orgInfo: yield db.batch_insert(orgId, "entities", orgInfo) response = """ <script> var data = %s; if (data.logo){ var imageUrl = data.logo; parent.$('#sitelogo-img').attr('src', imageUrl); } if (data.name){ parent.$('#sitelogo-link').attr('title', data.name); parent.$('#sitelogo-img').attr('alt', data.name); } parent.$$.alerts.info("%s"); </script> """ % (json.dumps(orgDetails), _("Company details updated")) request.write(response)
def create(request, me, name, access, description, displayPic): """create a new group. add creator to the group members. make create administrator of the group. Note: No two groups in an organization should have same name. Keyword params: @request: @me: @name: name of the group. @access: group access type (open/closed). @description: description of the group. @displayPic: profile pic of the group. """ if not name: raise errors.MissingParams([_("Group name")]) cols = yield db.get_slice(me.basic['org'], "entityGroupsMap", start=name.lower(), count=2) for col in cols: if col.column.name.split(':')[0] == name.lower(): raise errors.InvalidGroupName(name) groupId = utils.getUniqueKey() group = base.Entity(groupId) meta = {"name": name, "type": "group", "access": access, "org": me.basic['org']} admins = {me.id: ''} if description: meta["desc"] = description if displayPic: avatar = yield saveAvatarItem(group.id, me.basic['org'], displayPic) meta["avatar"] = avatar group.update({'basic': meta, 'admins': admins}) yield group.save() colname = _entityGroupMapColName(group) yield db.insert(me.id, "entities", name, group.id, 'adminOfGroups') yield db.insert(me.basic['org'], "entityGroupsMap", '', colname) yield _addMember(request, group, me)