User banning/unbanning

master
E. Almqvist 3 years ago
parent 3a558f9d31
commit 8599895cb2
  1. 16
      src/app.rb
  2. 6
      src/db_models.rb
  3. 4
      src/lib/database.rb

@ -240,7 +240,23 @@ end
get "/admin/users/:id/ban" do
auth_denied unless get_current_user.admin?
id = params[:id].to_i
user = User.find_by_id id
user.banned = true
flash[:error] = "Banned user '#{user.name}'"
redirect "/admin"
end
get "/admin/users/:id/unban" do
auth_denied unless get_current_user.admin?
id = params[:id].to_i
user = User.find_by_id id
user.banned = false
flash[:success] = "Unbanned user '#{user.name}'"
redirect "/admin"
end
# ADMIN ROLE MANAGEMENT

@ -174,9 +174,11 @@ class User < EntityModel
def banned=(b)
if b then
resp = User_Role_relation.give_role(@id, ROLE_IDS[:banned])
# Add the "banned" role
resp = User_Role_relation.give_role(@id, ROLES[:banned][:id])
else
# Remove the "banned" role
resp = User_Role_relation.revoke_role(@id, ROLES[:banned][:id])
end
end
end

@ -87,7 +87,9 @@ class EntityModel
end
def self.delete(filter="", *args)
self.query "DELETE FROM #{self.name} #{self.apply_filter(filter)}", *args
q = "DELETE FROM #{self.name}"
q = self.apply_filter(q, filter)
self.query q, *args
end
def self.set(attr, data, filter="") # slower but more lazy

Loading…
Cancel
Save