def to_dict(self): dic = { c.key: getattr(self, c.key) for c in inspect(self).mapper.column_attrs if c.key not in ('user_id', 'app_id') } user = User.get_by_id(self.user_id) dic['username'] = user.nickname dic['action'] = self.action.name return dic
def _(*args, **kwargs): if current_app.config['DEBUG']: g.user = User(FAKE_USER) else: g.user = get_current_user(require_token, scopes_required) if not g.user: # TODO: change the message abort(403, "please provide valid token or user/password") return func(*args, **kwargs)
def _(*args, **kwargs): if current_app.config['DEBUG']: g.user = User(**FAKE_USER) else: g.user = get_current_user() if not g.user: # TODO: change the message abort(403, '{}?next={}'.format(url_for('user.login'), request.url)) elif privileged and g.user.privileged != 1: abort(403, 'dude you are not administrator') return func(*args, **kwargs)
def subscriber_list(self): if not self.subscribers: return [] try: username_list = json.loads(self.subscribers) except json.JSONDecodeError as e: logger.exception(f"subscribers of app {self.name} is invalid({self.subscribers})") return [] from console.models.user import User users = [] for username in username_list: user = User.get_by_username(username) if user is not None: users.append(user) return users
def list_users(): """ List all users --- responses: 200: description: user list schema: type: array items: $ref: '#/definitions/User' examples: application/json: [ { "username": "******", "nickname": "dude", "email": "*****@*****.**", "avatar": "xxx.png", "privileged": True, "data": "ggg" } ] """ return jsonify([u.to_dict() for u in User.get_all()])
def validate_user_id(id_): from console.models.user import User if not bool(User.get(id_)): raise ValidationError( 'User {} not found, needs to login first'.format(id_))