Example #1
0
    def init_global_vars():
        g.page = request.args.get('page', type=int, default=0)
        g.start = request.args.get('start', type=int, default=g.page * 20)
        g.limit = request.args.get('limit', type=int, default=20)

        if request.path == '/user/login_from_openid/' or request.path.startswith('/ajax'):
            return

        if 'uid' not in session:
            abort(401)
        g.user = User.get_by_uid(session['uid'])
Example #2
0
def grant_project(uid):
    user = User.get_by_uid(uid)
    if not user:
        return {'reason': '用户不存在'}, 404

    name = request.form.get('project', '')
    p = Project.get_by_name(name)
    if not p:
        return {'reason': '项目不存在'}, 404

    user.grant_project(name)
    log = OPLog.create(g.user.id, OPLOG_ACTION.grant_project)
    log.project_name = name
    log.acceptor = user.uid
Example #3
0
def set_user():
    u = User.get_by_uid(request.form['uid'])
    if u is None:
        raise ValueError('no such user')

    group = request.form['group']
    if group:
        u.set_group(group)

    flags = request.form.getlist('privs')
    privilege = reduce(lambda x, y: x | y, [getattr(USER_ROLE, p.lower(), 0) for p in flags], 0)
    u.set_privilege(privilege)

    log = OPLog.create(g.user.id, OPLOG_ACTION.grant_privilege)
    log.privilege = privilege
    log.acceptor = u.uid
Example #4
0
def user_detail(uid):
    user = User.get_by_uid(uid)
    if not user:
        abort(404)
    return render_template('/settings/user_detail.html', user=user)