diff --git a/src/app.rb b/src/app.rb index 35ad6db..2e44fcc 100755 --- a/src/app.rb +++ b/src/app.rb @@ -294,16 +294,16 @@ post "/admin/roles/give" do user = get_current_user auth_denied if user.permitted? :roleman - user_id = params[:user_id] - role_id = params[:role_id] + user_id = params[:user_id].to_i + role_id = params[:role_id].to_i - if user.role_ids.include? role_id or user.admin? then - User_Role_relation.give_role(user_id, role_id) + if user.role_ids.include?(role_id) or user.admin? then + resp = User_Role_relation.give_role(user_id, role_id) newrole = Role.find_by_id role_id promoted_user = User.find_by_id user_id - flash[:success] = "Gave role '#{newrole.name}' to #{promoted_user.name}!" + flash[:success] = "Gave role '#{newrole.name}' to #{promoted_user.name}!" if resp redirect "/admin" else auth_denied "You are not permitted to give that role!", 403, "/admin" diff --git a/src/db_init.rb b/src/db_init.rb index b5e07ef..a5c6a3c 100644 --- a/src/db_init.rb +++ b/src/db_init.rb @@ -18,6 +18,6 @@ def db_init # Create all default roles q = "INSERT OR IGNORE INTO Role (id, name, color, flags) VALUES (?, ?, ?, ?)" ROLES.each do |id, role| - db.query(q, role[:id], role[:name], role[:color], role[:flags]) + Role.query(q, role[:id], role[:name], role[:color], role[:flags]) end end diff --git a/src/db_models.rb b/src/db_models.rb index 1a25442..d7ab2bc 100644 --- a/src/db_models.rb +++ b/src/db_models.rb @@ -229,8 +229,7 @@ class User_Role_relation < EntityModel def self.give_role(user_id, role_id) user = User.find_by_id user_id - # TODO prevent duplicate roles - if not user.role_ids.include? role_id then + if not user.role_ids.include?(role_id) then data = { role_id: role_id, user_id: user_id diff --git a/src/views/stylesheets/style.sass b/src/views/stylesheets/style.sass index cf608d7..f7f216d 100644 --- a/src/views/stylesheets/style.sass +++ b/src/views/stylesheets/style.sass @@ -315,6 +315,7 @@ ul.list-container .card background-color: $bg_clr border-radius: $border_radius + width: inherit h2 text-align: left padding: 0 .8rem @@ -336,7 +337,11 @@ ul.list-container margin: 0 auto aside + display: flex + flex-direction: column + align-items: center margin-right: 2rem + width: 300px #userinfo margin-bottom: 1.75rem text-align: center