diff --git a/app/controllers/admin/admin_users_controller.rb b/app/controllers/admin/admin_users_controller.rb new file mode 100644 index 0000000..82b1371 --- /dev/null +++ b/app/controllers/admin/admin_users_controller.rb @@ -0,0 +1,45 @@ +class Admin::AdminUsersController < Admin::BaseController + before_action :require_superadmin! + + def index + @superadmins = User.where(admin_level: :superadmin).order(:slack_username) + @admins = User.where(admin_level: :admin).order(:slack_username) + @viewers = User.where(admin_level: :viewer).order(:slack_username) + end + + def update + @user = User.find(params[:id]) + new_level = params[:admin_level] + + if @user == current_user + redirect_to admin_admin_users_path, alert: "you cannot change your own admin level" + return + end + + if @user.set_admin_level(new_level) + redirect_to admin_admin_users_path, notice: "#{@user.display_name}'s admin level updated to #{new_level}." + else + redirect_to admin_admin_users_path, alert: "failed to update admin level." + end + end + + def search + query = params[:q].to_s.strip + @users = if query.present? + User.where("slack_username ILIKE :q OR username ILIKE :q OR slack_uid ILIKE :q", q: "%#{query}%") + .limit(20) + else + User.none + end + + render partial: "search_results", locals: { users: @users } + end + + private + + def require_superadmin! + unless current_user&.admin_level_superadmin? + redirect_to root_path, alert: "no perms lmaoo" + end + end +end diff --git a/app/views/admin/admin_users/_search_results.html.erb b/app/views/admin/admin_users/_search_results.html.erb new file mode 100644 index 0000000..74217e5 --- /dev/null +++ b/app/views/admin/admin_users/_search_results.html.erb @@ -0,0 +1,39 @@ +<% if users.any? %> +
+ <% users.each do |user| %> +
+
+ Avatar +
+ <%= user.display_name %> + <% if user.admin_level != "default" %> + + <%= user.admin_level %> + + <% end %> +
<%= user.slack_uid || "No Slack ID" %>
+
+
+
+ <%= button_to "→ Superadmin", admin_admin_user_path(user, admin_level: "superadmin"), + method: :patch, + class: "px-3 py-1 bg-red-600 hover:bg-red-500 text-white text-sm font-medium rounded transition-colors cursor-pointer" %> + <%= button_to "→ Admin", admin_admin_user_path(user, admin_level: "admin"), + method: :patch, + class: "px-3 py-1 bg-yellow-600 hover:bg-yellow-500 text-white text-sm font-medium rounded transition-colors cursor-pointer" %> + <%= button_to "→ Viewer", admin_admin_user_path(user, admin_level: "viewer"), + method: :patch, + class: "px-3 py-1 bg-blue-600 hover:bg-blue-500 text-white text-sm font-medium rounded transition-colors cursor-pointer" %> +
+
+ <% end %> +
+<% else %> +

nuthin found

+<% end %> diff --git a/app/views/admin/admin_users/index.html.erb b/app/views/admin/admin_users/index.html.erb new file mode 100644 index 0000000..d12afa2 --- /dev/null +++ b/app/views/admin/admin_users/index.html.erb @@ -0,0 +1,200 @@ +
+
+

Admin Management

+

Who can access the admin panel?

+
+ +
+

Promote

+
+ +
+
+
+ +
+

Superadmins (<%= @superadmins.count %>)

+ <% if @superadmins.any? %> +
+ + + + + + + + + + <% @superadmins.each do |user| %> + + + + + + <% end %> + +
UserSlack IDActions
+
+ Avatar + <%= user.display_name %> + <% if user == current_user %> + (you) + <% end %> +
+
<%= user.slack_uid || "N/A" %> + <% if user != current_user %> +
+ <%= button_to "→ Admin", admin_admin_user_path(user, admin_level: "admin"), + method: :patch, + class: "px-3 py-1 bg-yellow-600 hover:bg-yellow-500 text-white text-sm font-medium rounded transition-colors cursor-pointer", + data: { confirm: "Demote #{user.display_name} to Admin?" } %> + <%= button_to "→ Viewer", admin_admin_user_path(user, admin_level: "viewer"), + method: :patch, + class: "px-3 py-1 bg-blue-600 hover:bg-blue-500 text-white text-sm font-medium rounded transition-colors cursor-pointer", + data: { confirm: "Demote #{user.display_name} to Viewer?" } %> + <%= button_to "→ Default", admin_admin_user_path(user, admin_level: "default"), + method: :patch, + class: "px-3 py-1 bg-gray-600 hover:bg-gray-500 text-white text-sm font-medium rounded transition-colors cursor-pointer", + data: { confirm: "Remove #{user.display_name}'s admin privileges?" } %> +
+ <% else %> + Cannot modify yourself + <% end %> +
+
+ <% else %> +

No superadmins found!

+ <% end %> +
+ +
+

Admins (<%= @admins.count %>)

+ <% if @admins.any? %> +
+ + + + + + + + + + <% @admins.each do |user| %> + + + + + + <% end %> + +
UserSlack IDActions
+
+ Avatar + <%= user.display_name %> +
+
<%= user.slack_uid || "N/A" %> +
+ <%= button_to "→ Superadmin", admin_admin_user_path(user, admin_level: "superadmin"), + method: :patch, + class: "px-3 py-1 bg-red-600 hover:bg-red-500 text-white text-sm font-medium rounded transition-colors cursor-pointer", + data: { confirm: "Promote #{user.display_name} to Superadmin?" } %> + <%= button_to "→ Viewer", admin_admin_user_path(user, admin_level: "viewer"), + method: :patch, + class: "px-3 py-1 bg-blue-600 hover:bg-blue-500 text-white text-sm font-medium rounded transition-colors cursor-pointer", + data: { confirm: "Demote #{user.display_name} to Viewer?" } %> + <%= button_to "→ Default", admin_admin_user_path(user, admin_level: "default"), + method: :patch, + class: "px-3 py-1 bg-gray-600 hover:bg-gray-500 text-white text-sm font-medium rounded transition-colors cursor-pointer", + data: { confirm: "Remove #{user.display_name}'s admin privileges?" } %> +
+
+
+ <% else %> +

No admins found

+ <% end %> +
+ +
+

Viewers (<%= @viewers.count %>)

+ <% if @viewers.any? %> +
+ + + + + + + + + + <% @viewers.each do |user| %> + + + + + + <% end %> + +
UserSlack IDActions
+
+ Avatar + <%= user.display_name %> +
+
<%= user.slack_uid || "N/A" %> +
+ <%= button_to "→ Superadmin", admin_admin_user_path(user, admin_level: "superadmin"), + method: :patch, + class: "px-3 py-1 bg-red-600 hover:bg-red-500 text-white text-sm font-medium rounded transition-colors cursor-pointer", + data: { confirm: "Promote #{user.display_name} to Superadmin?" } %> + <%= button_to "→ Admin", admin_admin_user_path(user, admin_level: "admin"), + method: :patch, + class: "px-3 py-1 bg-yellow-600 hover:bg-yellow-500 text-white text-sm font-medium rounded transition-colors cursor-pointer", + data: { confirm: "Promote #{user.display_name} to Admin?" } %> + <%= button_to "→ Default", admin_admin_user_path(user, admin_level: "default"), + method: :patch, + class: "px-3 py-1 bg-gray-600 hover:bg-gray-500 text-white text-sm font-medium rounded transition-colors cursor-pointer", + data: { confirm: "Remove #{user.display_name}'s viewer privileges?" } %> +
+
+
+ <% else %> +

No viewers found

+ <% end %> +
+
+ + diff --git a/app/views/shared/_nav.html.erb b/app/views/shared/_nav.html.erb index bb9e17e..c6f9eac 100644 --- a/app/views/shared/_nav.html.erb +++ b/app/views/shared/_nav.html.erb @@ -142,6 +142,11 @@ <% end %> <% end %> <% end %> + <% superadmin_tool(nil, "div") do %> + <%= link_to admin_admin_users_path, class: "block px-2 py-1 rounded-lg transition #{current_page?(admin_admin_users_path) ? 'bg-primary/50 text-primary' : 'hover:bg-[#23272a]'}", data: { action: "click->nav#clickLink" } do %> + Admin Management + <% end %> + <% end %> <% superadmin_tool(nil, "div") do %> <%= link_to admin_deletion_requests_path, class: "block px-2 py-1 rounded-lg transition #{current_page?(admin_deletion_requests_path) ? 'bg-primary/50 text-primary' : 'hover:bg-[#23272a]'}", data: { action: "click->nav#clickLink" } do %> Account Deletions diff --git a/config/routes.rb b/config/routes.rb index d7a0157..f1e26a6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,14 @@ Rails.application.routes.draw do mount AhoyCaptain::Engine => "/ahoy_captain" mount Flipper::UI.app(Flipper) => "flipper", as: :flipper + namespace :admin do + resources :admin_users, only: [ :index, :update ] do + collection do + get :search + end + end + end + # get "/my/mailing_address", to: "my/mailing_address#show", as: :my_mailing_address end