Example #1
0
def create_perm():

    if request.json and 'scopes' in request.json and 'match' in request.json:
        scopes = request.json["scopes"]
        match = request.json["match"]

        for s in scopes:
            if not is_in_scope(s):
                return jsonify(
                    status="error",
                    message="Requested scope %s is beyond existing scopes: %s."
                    % (s, ','.join(g.scopes))), 403

        try:
            perm = db.create_perm(scopes, match)
        except Exception as e:
            return jsonify(status="error", message=str(e)), 500
    else:
        return jsonify(
            status="error",
            message="Must supply user 'scope' and 'match' as parameters"), 400

    if perm:
        return jsonify(status="ok", id=perm['id'], permission=perm), 201, {
            'Location': absolute_url('/scope/' + perm['id'])
        }
    else:
        return jsonify(
            status="error",
            message="Permissions lookup for this match already exists"), 409
Example #2
0
 def create(self):
     return Permission.from_db(db.create_perm(self))
Example #3
0
 def create(self) -> 'Permission':
     return Permission.from_db(db.create_perm(self))