Docs and st uff

master
E. Almqvist 3 years ago
parent 3f7109e195
commit d445daaf59
  1. 1
      src/TODO.md
  2. 55
      src/routes/admin.rb
  3. 0
      src/routes/main.rb

@ -1,5 +1,4 @@
# TODO # TODO
- Yardoc 50%
- Film - Film
## Refactor ## Refactor

@ -1,6 +1,8 @@
############### ###############
# Admin panel # # Admin panel #
############### ###############
# Admin panel
get "/admin" do get "/admin" do
flags = get_current_user.flags flags = get_current_user.flags
@ -17,7 +19,9 @@ get "/admin" do
serve :"admin/index", {flags: flags, data: data} serve :"admin/index", {flags: flags, data: data}
end end
# ADMIN USER MANAGEMENT # Ban user
# @param [Integer] id
# @see User#banned=
get "/admin/users/:id/ban" do get "/admin/users/:id/ban" do
auth_denied unless get_current_user.admin? auth_denied unless get_current_user.admin?
id = params[:id].to_i id = params[:id].to_i
@ -30,6 +34,9 @@ get "/admin/users/:id/ban" do
redirect back redirect back
end end
# Unban user
# @param [Integer] id
# @see User#banned=
get "/admin/users/:id/unban" do get "/admin/users/:id/unban" do
auth_denied unless get_current_user.admin? auth_denied unless get_current_user.admin?
id = params[:id].to_i id = params[:id].to_i
@ -42,6 +49,8 @@ get "/admin/users/:id/unban" do
redirect back redirect back
end end
# Edit user credentials
# @param [Integer] id
get "/admin/users/:id/edit" do get "/admin/users/:id/edit" do
auth_denied unless get_current_user.admin? auth_denied unless get_current_user.admin?
id = params[:id].to_i id = params[:id].to_i
@ -50,6 +59,9 @@ get "/admin/users/:id/edit" do
serve :"admin/users/edit", {user: user} serve :"admin/users/edit", {user: user}
end end
# Give role to user
# @param [Integer] user_id User id
# @param [Integer] role_id Role id
post "/admin/users/rolegive" do post "/admin/users/rolegive" do
user = get_current_user user = get_current_user
auth_denied unless user.permitted?(:roleman) auth_denied unless user.permitted?(:roleman)
@ -69,6 +81,9 @@ post "/admin/users/rolegive" do
end end
end end
# Revoke role from user
# @param [Integer] user_id User id
# @param [Integer] role_id Role id
post "/admin/users/rolerevoke" do post "/admin/users/rolerevoke" do
user = get_current_user user = get_current_user
auth_denied unless user.permitted?(:roleman) auth_denied unless user.permitted?(:roleman)
@ -86,7 +101,10 @@ post "/admin/users/rolerevoke" do
end end
end end
# Set users money
# @param [Integer] id
# @param [Float] money
# @see User#balance=
post "/admin/users/setmoney" do post "/admin/users/setmoney" do
user = get_current_user user = get_current_user
auth_denied unless user.permitted? :moneyman auth_denied unless user.permitted? :moneyman
@ -102,6 +120,9 @@ post "/admin/users/setmoney" do
redirect back redirect back
end end
# Set users reputation score
# @param [Integer] id
# @param [Float] reputation
post "/admin/users/setreputation" do post "/admin/users/setreputation" do
user = get_current_user user = get_current_user
auth_denied unless user.admin? auth_denied unless user.admin?
@ -118,19 +139,23 @@ post "/admin/users/setreputation" do
end end
# ADMIN ROLE MANAGEMENT # ADMIN ROLE MANAGEMENT
# Role check for id
def role_check(id) def role_check(id)
no_go_away if ROLE_IDS.include? id no_go_away if ROLE_IDS.include? id
auth_denied unless get_current_user.permitted? :roleman auth_denied unless get_current_user.permitted? :roleman
end end
# Create role
# @param [String] name
# @param [String] color Hex color
# @param [Integer Bitmap] flags
post "/admin/roles" do post "/admin/roles" do
user = get_current_user user = get_current_user
auth_denied unless user.permitted? :roleman auth_denied unless user.permitted? :roleman
name = params[:name] name = params[:name]
color = params[:color] color = params[:color]
flags = params[:flags]
flags = params[:flags].to_i flags = params[:flags].to_i
flags = verify_flags(flags, user.flags) flags = verify_flags(flags, user.flags)
@ -143,6 +168,8 @@ post "/admin/roles" do
redirect back redirect back
end end
# Delete role
# @param [Integer] id
get "/admin/roles/:id/delete" do get "/admin/roles/:id/delete" do
id = params[:id].to_i id = params[:id].to_i
role_check id role_check id
@ -153,6 +180,8 @@ get "/admin/roles/:id/delete" do
redirect back redirect back
end end
# Edit role form
# @param [Integer] id
get "/admin/roles/:id/edit" do get "/admin/roles/:id/edit" do
id = params[:id].to_i id = params[:id].to_i
role_check id role_check id
@ -165,6 +194,7 @@ get "/admin/roles/:id/edit" do
end end
end end
# Very user flags for operation
def verify_flags(flags, userflags) def verify_flags(flags, userflags)
# TODO: check if this actually works # TODO: check if this actually works
# should work in practise but who knows # should work in practise but who knows
@ -173,6 +203,11 @@ def verify_flags(flags, userflags)
return newflags return newflags
end end
# Update role
# @param [Integer] id
# @param [String] name New name
# @param [String] color New hex color
# @param [Integer Bitmap] flags
post "/admin/roles/:id/update" do post "/admin/roles/:id/update" do
id = params[:id].to_i id = params[:id].to_i
user = get_current_user user = get_current_user
@ -194,6 +229,10 @@ end
# ADMIN CATEGORY MANAGEMENT # ADMIN CATEGORY MANAGEMENT
# Create category
# @param [String] name
# @param [String] color Hex color string
post "/admin/categories" do post "/admin/categories" do
user = get_current_user user = get_current_user
auth_denied unless user.permitted? :cateman auth_denied unless user.permitted? :cateman
@ -210,6 +249,8 @@ post "/admin/categories" do
redirect back redirect back
end end
# Delete a category
# @param [Integer] id
get "/admin/categories/:id/delete" do get "/admin/categories/:id/delete" do
id = params[:id].to_i id = params[:id].to_i
user = get_current_user user = get_current_user
@ -221,6 +262,8 @@ get "/admin/categories/:id/delete" do
redirect back redirect back
end end
# Edit category form
# @param [Integer] id
get "/admin/categories/:id/edit" do get "/admin/categories/:id/edit" do
id = params[:id].to_i id = params[:id].to_i
user = get_current_user user = get_current_user
@ -234,6 +277,10 @@ get "/admin/categories/:id/edit" do
end end
end end
# Update category
# @param [Integer] id
# @param [String] name New name
# @param [String] color New hex color
post "/admin/categories/:id/update" do post "/admin/categories/:id/update" do
id = params[:id].to_i id = params[:id].to_i
user = get_current_user user = get_current_user

Loading…
Cancel
Save