move everything to backend folder for migration to dashboard repository
This commit is contained in:
parent
af6b006409
commit
92ec7c653d
89 changed files with 0 additions and 0 deletions
2
backend/areas/roles/__init__.py
Normal file
2
backend/areas/roles/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
from .roles import *
|
||||
from .models import *
|
||||
12
backend/areas/roles/models.py
Normal file
12
backend/areas/roles/models.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from sqlalchemy import Integer, String
|
||||
from database import db
|
||||
|
||||
|
||||
class Role(db.Model):
|
||||
NO_ACCESS_ROLE_ID = 3
|
||||
|
||||
id = db.Column(Integer, primary_key=True)
|
||||
name = db.Column(String(length=64))
|
||||
|
||||
def __repr__(self):
|
||||
return f"Role {self.name}"
|
||||
18
backend/areas/roles/role_service.py
Normal file
18
backend/areas/roles/role_service.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from areas.apps.models import AppRole
|
||||
from .models import Role
|
||||
|
||||
|
||||
class RoleService:
|
||||
@staticmethod
|
||||
def get_roles():
|
||||
roles = Role.query.all()
|
||||
return [{"id": r.id, "name": r.name} for r in roles]
|
||||
|
||||
@staticmethod
|
||||
def get_role_by_id(role_id):
|
||||
return Role.query.filter_by(id=role_id).first()
|
||||
|
||||
@staticmethod
|
||||
def is_user_admin(userId):
|
||||
dashboard_role_id = AppRole.query.filter_by(user_id=userId, app_id=1).first().role_id
|
||||
return dashboard_role_id == 1
|
||||
15
backend/areas/roles/roles.py
Normal file
15
backend/areas/roles/roles.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
from flask import jsonify, request
|
||||
from flask_jwt_extended import jwt_required
|
||||
from flask_cors import cross_origin
|
||||
|
||||
from areas import api_v1
|
||||
|
||||
from .role_service import RoleService
|
||||
|
||||
|
||||
@api_v1.route("/roles", methods=["GET"])
|
||||
@jwt_required()
|
||||
@cross_origin()
|
||||
def get_roles():
|
||||
roles = RoleService.get_roles()
|
||||
return jsonify(roles)
|
||||
Reference in a new issue