def _addMember(request, group, user): """Add a new member to the group. Add user to group followers, create a group-join activity item and push item to group, group-followers feed. Update user groups with new group. Keyword params: @group: entity object of the group @user: entity object of the user @request: """ deferreds = [] itemType = "activity" relation = Relation(user.id, []) if not getattr(user, 'basic', []): yield user.fetchData(['basic']) responseType = "I" acl = {"accept": {"groups": [group.id]}} _acl = pickle.dumps(acl) itemId = utils.getUniqueKey() colname = _entityGroupMapColName(group) yield db.insert(user.id, "entityGroupsMap", "", colname) yield db.insert(group.id, "groupMembers", itemId, user.id) item = yield utils.createNewItem(request, "activity", user, acl, "groupJoin") item["meta"]["target"] = group.id d1 = db.insert(group.id, "followers", "", user.id) d2 = db.batch_insert(itemId, 'items', item) d3 = feed.pushToFeed(group.id, item["meta"]["uuid"], itemId, itemId, responseType, itemType, user.id) d4 = feed.pushToOthersFeed(user.id, user.basic['org'], item["meta"]["uuid"], itemId, itemId, _acl, responseType, itemType, user.id, promoteActor=False) d5 = utils.updateDisplayNameIndex(user.id, [group.id], user.basic['name'], None) deferreds = [d1, d2, d3, d4, d5] yield defer.DeferredList(deferreds)
def makeAdmin(request, group, user, me): """make user admin of the group. Only an group-administrator can make an group-member and administrator. Keyword params: @request: @me: @user: user object @group: group object """ if me.id not in group.admins: raise errors.PermissionDenied(_('You are not an administrator of the group')) cols = yield db.get_slice(group.id, "groupMembers", [user.id]) if not cols: raise errors.InvalidRequest(_('Only group member can become administrator')) if user.id in group.admins: defer.returnValue(None) yield db.insert(group.id, "entities", '', user.id, 'admins') yield db.insert(user.id, "entities", group.basic['name'], group.id, "adminOfGroups") itemType = "activity" responseType = "I" acl = {"accept": {"groups": [group.id]}} _acl = pickle.dumps(acl) itemId = utils.getUniqueKey() item = yield utils.createNewItem(request, "activity", user, acl, "groupAdmin") item["meta"]["target"] = group.id d1 = db.batch_insert(itemId, 'items', item) d2 = feed.pushToFeed(group.id, item["meta"]["uuid"], itemId, itemId, responseType, itemType, user.id) d3 = feed.pushToOthersFeed(user.id, user.basic['org'], item["meta"]["uuid"], itemId, itemId, _acl, responseType, itemType, user.id, promoteActor=False) yield defer.DeferredList([d1, d2, d3])