def delete(self, member_id): try: map = self.get_map(member_id) account = self.get_account(map.account_id) except peewee.DoesNotExist: abort(404, message="groupmember does not exist") # make sure logged in user has perms if self.auth.account.account_type != 'senior_admin': # check they are a member and is_admin is 1 try: mymap = ModelMap.get( ModelMap.group_id == map.group_id, ModelMap.account_id == self.auth.account.account_id) if mymap.is_admin != 1: abort(403) except peewee.DoesNotExist: abort(403) try: # FIXME need to delete domain maps when in place map.delete_instance() # Log change group = ModelGroup.get(ModelGroup.group_id == map.group_id) self.dns_log(0, ("Removed " + account.first_name + " " + account.last_name + " from group " + group.name)) except: abort(400, message="unable to delete groupmember") return {'status': 'ok'}
def get_group(self, group_id): if self.auth.account.account_type != 'senior_admin': # DoesNotExist will be raised if map doesn't exist group_map = ModelMap.get( ModelMap.account_id == self.auth.account.account_id, ModelMap.group_id == group_id) return ModelGroup.get(ModelGroup.group_id == group_id)
def post(self): group_id = request.form.get('group_id') account_id = request.form.get('account_id') is_admin = request.form.get('is_admin', 0) # Handle params if group_id is None: abort(400, message="'group_id' parameter is required") if account_id is None: abort(400, message="'account_id' parameter is required") if str(is_admin) != "1" and str(is_admin) != "0": abort(400, message="'is_admin' must be 1 or 0") is_admin = int(is_admin) # Verify user try: account = self.get_account(account_id) except peewee.DoesNotExist: abort(400, message="Account does not exist") if account.status != "active": abort(400, message="Account is not active") # Make sure map doesn't exist try: map = self.get_map(account_id, group_id) abort(400, message="Account is already a group member") except peewee.DoesNotExist: pass # make sure logged in user has perms if self.auth.account.account_type != 'senior_admin': # check they are a member and is_admin is 1 try: mymap = self.get_map( self.auth.account.account_id, group_id ) if mymap.is_admin != 1: abort(403) except peewee.DoesNotExist: abort(403) # Add map newmap = self.create_map(account_id, group_id, is_admin) formatted = newmap.format_member(newmap, account) # Log change group = ModelGroup.get(ModelGroup.group_id == group_id) self.dns_log( 0, ( "Added " + account.first_name + " " + account.last_name + " to group " + group.name ) ) return {'status': 'ok', 'groupmember': formatted}, 201
def get_group(self, group_id): if self.auth.account.account_type != 'senior_admin': # DoesNotExist will be raised if map doesn't exist group_map = ModelMap.get( ModelMap.account_id == self.auth.account.account_id, ModelMap.group_id == group_id ) return ModelGroup.get(ModelGroup.group_id == group_id)
def get_group(self, group_id): return ModelGroup.get( ModelGroup.group_id == group_id )
def get_group(self, group_id): return ModelGroup.get(ModelGroup.group_id == group_id)