def get(self, id=None):
     queryData = request.args.to_dict()
     if id:
         user_group = UserGroupModel.find_by_id(id)
         if user_group:
             return user_group.json()
         else:
             return {'message': 'user group not found'}, 404
     user_groups = UserGroupModel.find(**queryData)
     return {'user_groups': list(map(lambda x: x.json(), user_groups))}, 200
    def delete(self, id):
        user_group = UserGroupModel.find_by_id(id)
        if user_group:
            user_group.delete_from_db()

            return {'success': 'user_group deleted'}, 202

        return {'error': 'user_group not found'}, 404
Exemple #3
0
 def json(self):
   user_group = UserGroupModel.find_by_id(self.user_group)
   return {'username': self.username, 
           'id': self.id, 
           'password': self.password,
           'email': self.email,
           'phone_number': self.phone_number,
           'user_group': user_group.json() if user_group else None,
           }
Exemple #4
0
  def get_user_permissions(self):
    user_permissions = []

    if self.user_group:
      user_group = UserGroupModel.find_by_id(self.user_group)
      if user_group:
        user_roles = user_group.roles
        for role in user_roles:
          permissions = role.permissions
          user_permissions.extend(permissions)
    return user_permissions
    def put(self, id):
        data = json.loads(request.data)

        if 'roles' not in data or data['roles'] == '':
            return {
                'error': "The user group roles is empty".format(data['name'])
            }, 400

        user_group = UserGroupModel.find_by_id(id)
        if user_group:
            user_group.update(**data)
            return user_group.json(), 201

        return {'error': 'user_group not found'}, 404
    def post(self):
        data = json.loads(request.data)

        if 'roles' not in data or len(
                data['roles']) == 0 or data['roles'] == '':
            return {
                'error': "The user group roles is empty".format(data['name'])
            }, 400

        if UserGroupModel.find_by_name(data["name"]):
            return {
                'message':
                "A user_group with name '{}' already exists.".format(
                    data["name"])
            }, 400
        user_group = UserGroupModel(**data)
        # try:
        user_group.save_to_db()
        # except:
        #   return {"message": "An error occurred creating the user_group."}, 500

        return user_group.json(), 201
Exemple #7
0
 def get_user_roles(self):
   user_group = UserGroupModel.find_by_id(self.user_group)
   return RoleModel.find_by_id(user_group.roles)
 def get(self, name):
     user_group = UserGroupModel.find_by_name(name)
     if user_group:
         return user_group.childinuser_group()
 def get(self):
     return {
         'user_groups':
         list(map(lambda x: x.json(), UserGroupModel.find_all()))
     }, 200
 def get(self, id):
     user_group = UserGroupModel.find_by_id(id)
     if user_group:
         return {'roles': list(map(lambda x: x.json(), user_group.roles))}
     return {'error': 'user_group not found'}, 404