def group_create(self, name, description, expire_date=None, visibility='A'): """Create a group. :type name: str :param name: The groups name. :type description: str :param description: The groups description. :type expire_date: DateTime :param expire_date: The groups expiration date. :type visibility: str :param visibility: The groups visibility. Can one of: 'A' All 'I' Internal 'N' None """ # Perform auth-check self.ba.can_create_group(self.operator_id, groupname=name) # Check if group exists if Utils.get_group(self.db, 'name', name): raise Errors.CerebrumRPCException('Group already exists.') co = Factory.get('Constants')(self.db) gr = Factory.get('Group')(self.db) # Test if visibility is sane vis = co.GroupVisibility(visibility) try: int(vis) except (Errors.NotFoundError, TypeError): raise Errors.CerebrumRPCException('Invalid visibility.') # Create the group # TODO: Moar try/except? GroupAPI.group_create(gr, self.operator_id, vis, name, description, expire_date) # Set moderator if appropriate. # TODO: use the commented version when we pass the config as a dict. if getattr(self.config, 'GROUP_OWNER_OPSET', None): # Fetch operator. en = Utils.get_entity_by_id(self.db, self.operator_id) # Grant auth GroupAPI.grant_auth(en, gr, getattr(self.config, 'GROUP_OWNER_OPSET')) return gr.entity_id