Skip to content
Snippets Groups Projects
Commit 013a7438 authored by Mart van Santen's avatar Mart van Santen
Browse files

Cleanup code

parent b20067fd
No related branches found
No related tags found
1 merge request!71Resolve "Admin logins should gain admin privileges"
Pipeline #10670 failed with stages
in 1 minute and 28 seconds
......@@ -165,26 +165,30 @@ app.cli.add_command(app_cli)
@click.argument('app_slug')
@click.argument('role')
def setrole(email, app_slug, role):
app.logger.info(f"Assiging role {role} to {email} for app {app_slug}");
"""Set role for a sure
:param email: Email address of user to assign role
:param app_slug: Slug name of the app, for example 'nextcloud'
:param role: Role to assign. currently only 'admin', 'user'
"""
app.logger.info(f"Assiging role {role} to {email} for app {app_slug}")
# Find user
user = KratosUser.find_by_email(KRATOS_ADMIN, email)
if role != 'admin' and role != 'user':
print("At this point only the roles 'admin' and 'user' are accepted");
exit(1)
print("At this point only the roles 'admin' and 'user' are accepted")
sys.exit(1)
if not user:
print("User not found. Abort");
exit(1)
print("User not found. Abort")
sys.exit(1)
app_obj = db.session.query(App).filter(App.slug==app_slug).first()
if not app_obj:
print("App not found. Abort.");
exit(1)
print("App not found. Abort.")
sys.exit(1)
role_obj = db.session.query(AppRole).\
filter(AppRole.app_id==app_obj.id).\
......@@ -199,7 +203,6 @@ def setrole(email, app_slug, role):
obj.app_id = app_obj.id
obj.role = role
db.session.add(obj)
db.session.commit()
......@@ -549,6 +552,7 @@ def consent():
filter(AppRole.user_id==user.uuid).first()
if role_obj:
role = role_obj.role
app.logger.info(f"Using {role} when applying consent for {kratos_id}")
# Get claims for this user, provided the current app
claims = user.get_claims(app_name, role)
......
......@@ -359,6 +359,7 @@ class KratosUser():
"preferred_username": username,
"email": self.email,
"stackspin_roles": role,
"openappstack_roles": role,
}
......
......@@ -36,13 +36,14 @@ class AppRole(db.Model):
The AppRole object, stores the roles Users have on Apps
"""
# pylint: disable=no-member
user_id = db.Column(String, primary_key=True)
# pylint: disable=no-member
app_id = db.Column(Integer, ForeignKey('app.id'),
primary_key=True)
# pylint: disable=no-member
role = db.Column(String)
def __repr__(self):
return f"{self.role} for {self.user_id} on {self.app_id}"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment