Example #1
0
def update_auth_list():
    '''添加多个权限(到某个权限组)'''
    validator = AuthsValidator().validate_for_api()
    auth_list = [get_ep_name(id) for id in validator.auth_ids.data]
    group_id = validator.group_id.data

    for auth in auth_list:
        one = AuthModel.get(group_id=group_id, auth=auth)
        if not one:
            meta = find_auth_module(auth)
            AuthModel.create(group_id=group_id,
                             auth=meta.auth,
                             module=meta.module)
    return Success(error_code=1)
Example #2
0
def create_group():
    '''新建权限组'''
    validator = BaseValidator.get_json()
    name = validator['name']  # 权限组名
    auth_ids = validator['auth_ids']  # 权限IDs
    auth_list = [get_ep_name(auth_id) for auth_id in auth_ids]  # 权限名列表
    info = validator['info']  # 权限组名描述

    group = GroupModel.create(name=name, info=info)
    for auth in auth_list:
        meta = find_auth_module(auth)
        if meta:
            AuthModel.create(auth=meta.auth,
                             module=meta.module,
                             group_id=group.id)
    return Success(error_code=1)
Example #3
0
 def append_auth_list(group_id, auth_ids=[]):
     '''
     :param group_id: 权限组id
     :param auth_ids: 权限id数组
     :return:
     '''
     auth_name_list = [get_ep_name(id) for id in auth_ids]
     with db.auto_commit():
         for name in auth_name_list:
             one = Auth.get(group_id=group_id, name=name)
             if not one:
                 meta = find_auth_module(name)
                 Auth.create(group_id=group_id,
                             name=meta.name,
                             module=meta.module,
                             commit=False)
Example #4
0
 def create_group(name, auth_ids, info):
     '''
     :param name: 权限组名
     :param auth_ids: 权限ids
     :param info: 权限组名描述
     :return:
     '''
     auth_list = [get_ep_name(auth_id) for auth_id in auth_ids]  # 权限名列表
     with db.auto_commit():
         group = Group.create(name=name, info=info, commit=False)
         db.session.flush()
         for auth in auth_list:
             meta = find_auth_module(auth)
             if meta:
                 Auth.create(auth=meta.name,
                             module=meta.module,
                             group_id=group.id,
                             commit=False)
Example #5
0
 def setUp(self):
     # self.db, application.config['DATABASE'] = tempfile.mkstemp()
     application.config.from_pyfile('config/test.cfg')
     application.config['TESTING'] = True
     self.client = application.test_client()
     self.db = db
     self.db.create_all()
     self.auth = Auth.create(
         email="*****@*****.**",
         password='******',
         token='SUmnfqii5wcuJz8WZrWJw66AsE9',
     )
Example #6
0
    def post(self):
        args = self.reqparse.parse_args()
        auth = Auth.query.filter_by(email=args.get('email')).first()
        if auth:
            return 'the %s already exists' % auth.email, 404
        data = self.api_gateway.post(f'/consumers',
                                     data={
                                         'username': args.get('email'),
                                     })
        auth = Auth.create(id=data.get('id'),
                           email=args.get('email'),
                           password=args.get('password'))

        response = self.account_api.post(f'/account-service/users',
                                         data=dict(args,
                                                   **{'auth_id': auth.id}))
        return {
            "id": data.get('id'),
            "email": args.get('email'),
            "token": args.get('token'),
            "first_name": args.get('first_name'),
            "last_name": args.get('last_name'),
            "role": args.get('role')
        }
Example #7
0
 def test_create_auth(self):
     self.assertEqual(Auth.query.count(), 1)
     self.auth = Auth.create(password='******', email='*****@*****.**')
     self.assertEqual(Auth.query.count(), 2)