Beispiel #1
0
def delete_role(data):
    try:
        Role.objects(publicId=data['publicId']).delete()
        response_object = {
            'status': Const.SUCCESS,
            'message': Const.ROLE_DELETE_SUCCESS
        }
        return response_object, Const.SUCCESS_CODE
    except Exception as e:
        response_object = {
            'status': Const.FAIL,
            'message': e
        }
        return response_object, Const.FAILURE_CODE
Beispiel #2
0
def save_new_role(data):
    new_role = Role()
    try:
        new_role.entiry_id = data['entiry_id'],
    except KeyError:
        pass
    try:
        new_role.name = data['name'],
    except KeyError:
        pass
    try:
        new_role.sn_name = data['sn_name'],
    except KeyError:
        pass
    try:
        new_role.tm_name = data['tm_name'],
    except KeyError:
        pass

    save_changes(new_role)
    response_object = {
        'status': 'success',
        'message': 'Successfully created role.',
    }
    return response_object, 201
Beispiel #3
0
def update_role(data):
    try:
        if data['publicId']:
            Role.objects(publicId=data['publicId']).update(**data)
            response_object = {
                'status': Const.SUCCESS,
                'message': Const.ROLE_UPDATE_SUCCESS
            }
            return response_object, Const.SUCCESS_CODE
        else:
            response_object = {
                'status': Const.FAIL,
                'message': "publicId is required"
            }
            return response_object, Const.FAILURE_CODE

    except Exception as e:
        response_object = {
            'status': Const.FAIL,
            'message': e
        }
        return response_object, Const.FAILURE_CODE
 def gen_role():
     logging.info("Generating Role ...")
     os.chdir(os.path.dirname(__file__))
     path = os.getcwd()
     with open(os.path.join(path, 'sample/role.json')) as json_file:
         data = json.load(json_file)
         for p in data:
             role = Role(name=p['name'], description=p['description'])
             db.session.add(role)
         try:
             db.session.commit()
             logging.info("Generate Role Completed !")
         except Exception as e:
             db.session.rollback()
             logging.error("Generate Role Failure !")
             logging.error(str(e))
Beispiel #5
0
def initiate_dbs():
    from app.main.model.store import Store
    from app.main.model.user import User
    from app.main.model.role import Role, RoleType
    from app.main import db

    store = Store(name="ABC Retail 1", email="*****@*****.**")
    db.session.add(store)
    db.session.commit()

    role = Role(name=RoleType.ADMIN, store_id=store.id)
    db.session.add(role)
    db.session.commit()

    user = User(email="*****@*****.**", password="******")
    user.roles.append(role)
    db.session.add(user)
    db.session.commit()
Beispiel #6
0
def save_new_role(data):
    role = Role.query.filter_by(rolename=data['rolename']).first()
    if not role:
        new_role = Role(
            rolename=data['rolename'],
            description=data['description'],
            created_on=datetime.datetime.utcnow()
        )
        save_changes(new_role)
        response_object = {
            'status': 'success',
            'message': 'Successfully created role.',
            'id': str(new_role.id)
        }
        return response_object, 201
    else:
        response_object = {
            'status': 'fail',
            'message': 'Role already exists. Not created.',
        }
        return response_object, 409
def create_role(data):
    public_id = get_jwt_identity()
    name = data['name'].strip()
    des = data['description'].strip()
    check_role = Role.query.filter_by(name=name).first()
    if not check_role:
        user = User.query.filter_by(public_id=public_id).first()
        role = Role(name=name, description=des, created_by=user.username)
        save_changes(role)
        res_obj = {
            'status': 'success',
            'message': 'Role is created',
            'name': name,
            'description': des
        }
        return res_obj, 201
    else:
        res_obj = {
            'status': 'fail',
            'message': 'Role {} already exists.'.format(name),
        }
        return res_obj, 409
Beispiel #8
0
def insert_role(data):
    try:
        if not data['role']:
            response_object = {
                'status': Const.FAIL,
                'message': 'Role field Required.'
            }
            return response_object, Const.FAILURE_CODE
        data['publicId'] = uuid.uuid4()
        data['createdOn'] = datetime.now()
        # print(data)
        Role(**data).save()
        response_object = {
            'status': Const.SUCCESS,
            'message': Const.ROLE_INSERT_SUCCESS
        }
        return response_object, Const.SUCCESS_CODE

    except Exception as e:
        response_object = {
            'status': Const.FAIL,
            'message': e
        }
        return response_object, Const.FAILURE_CODE
from app.main.model.store import Store
from app.main.model.user import User
from app.main.model.role import Role, RoleType
from app.main import db

store = Store(name="ABC Retail 1", email="*****@*****.**")
db.session.add(store)
db.session.commit()

role = Role(name=RoleType.ADMIN, store_id=store.id)
role_work = Role(name=RoleType.WORKER, store_id=store.id)
db.session.add(role)
db.session.add(role_work)
db.session.commit()

user = User(email="*****@*****.**", password="******")
user1 = User(email="*****@*****.**", password="******")
user.roles.append(role)
user1.roles.append(role_work)
db.session.add(user)
db.session.add(user1)
db.session.commit()