From: Aidan Cornelius-Bell Date: Wed, 9 Oct 2024 22:34:17 +0000 (+1030) Subject: Added user management features X-Git-Url: https://gitweb.mndrdr.org/?a=commitdiff_plain;h=1f33b1d5d60ee29d63fe2af15098f6a7a93e2fb0;p=arelpe.git Added user management features --- diff --git a/app/controllers/user_manager_controller.rb b/app/controllers/user_manager_controller.rb new file mode 100644 index 0000000..db8d6e6 --- /dev/null +++ b/app/controllers/user_manager_controller.rb @@ -0,0 +1,30 @@ +class UserManagerController < ApplicationController + include AdminAuthenticatable + + def index + @users = User.all.order(created_at: :desc) + end + + def show + @user = User.find(params[:id]) + end + + def edit + @user = User.find(params[:id]) + end + + def update + @user = User.find(params[:id]) + if @user.update(user_params) + redirect_to user_manager_path(@user), notice: 'User was successfully updated.' + else + render :edit + end + end + + private + + def user_params + params.require(:user).permit(:email, :first_name, :last_name, :admin, :subscription_status, :buttondown_status, :support_type) + end +end diff --git a/app/helpers/user_manager_helper.rb b/app/helpers/user_manager_helper.rb new file mode 100644 index 0000000..4c21f5c --- /dev/null +++ b/app/helpers/user_manager_helper.rb @@ -0,0 +1,2 @@ +module UserManagerHelper +end diff --git a/app/views/layouts/_navigation_buttons.html.erb b/app/views/layouts/_navigation_buttons.html.erb index f4d1725..2d97d25 100644 --- a/app/views/layouts/_navigation_buttons.html.erb +++ b/app/views/layouts/_navigation_buttons.html.erb @@ -7,13 +7,16 @@ <% if !current_user %> <%= link_to "Join mind reader", join_path, class: "button" %> <% else %> - <%= link_to "Manage membership", subscriptions_path, class: "button #{controller_name == 'subscriptions' ? 'active' : ''}" %> - <%= link_to "Manage emails", mailing_lists_path, class: "button #{controller_name == 'mailing_lists' ? 'active' : ''}" %> + <%= link_to "My membership", subscriptions_path, class: "button #{controller_name == 'subscriptions' ? 'active' : ''}" %> + <%= link_to "My emails", mailing_lists_path, class: "button #{controller_name == 'mailing_lists' ? 'active' : ''}" %> + <%= link_to "My profile", edit_user_registration_path, class: "button #{controller_name == 'registrations' ? 'active' : ''}" %> <% end %> <% if current_user&.admin? %> - <%= link_to "Manage Posts", posts_path, class: "button" %> - <%= link_to "Manage Pages", pages_path, class: "button" %> - <%= link_to "Manage API Keys", api_keys_path, class: "button" %> +
+ <%= link_to "Manage posts", posts_path, class: "button" %> + <%= link_to "Manage pages", pages_path, class: "button" %> + <%= link_to "Manage API keys", api_keys_path, class: "button" %> + <%= link_to "Manage users", user_manager_index_path, class: "button" %> <% end %> \ No newline at end of file diff --git a/app/views/user_manager/edit.html.erb b/app/views/user_manager/edit.html.erb new file mode 100644 index 0000000..e204348 --- /dev/null +++ b/app/views/user_manager/edit.html.erb @@ -0,0 +1,66 @@ +
+ <% content_for :title, "User editor for #{@user.full_name}" %> +

Editing user: <%= @user.full_name %>

+ <%= link_to "Home", root_path, class: "button" %> + <%= link_to 'Show User', user_manager_path(@user), class: "button" %> + <%= link_to 'Back to Users', user_manager_index_path, class: "button" %> +
+ +
+
+ <%= form_with(model: @user, url: user_manager_path(@user), method: :patch, local: true) do |form| %> + <% if @user.errors.any? %> +
+

<%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:

+
    + <% @user.errors.full_messages.each do |message| %> +
  • <%= message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :email %> + <%= form.email_field :email %> +
+ +
+ <%= form.label :first_name %> + <%= form.text_field :first_name %> +
+ +
+ <%= form.label :last_name %> + <%= form.text_field :last_name %> +
+ +
+ <%= form.label :admin %> + <%= form.check_box :admin %> +
+ +
+ <%= form.label :subscription_status %> + <%= form.select :subscription_status, ['active', 'inactive', 'one_time'], include_blank: true %> +
+ +
+ <%= form.label :buttondown_status %> + <%= form.select :buttondown_status, ['unactivated', 'regular', 'premium', 'gifted', 'trialed'], include_blank: true %> +
+ +
+ <%= form.label :support_type %> + <%= form.select :support_type, ['one_time', 'ongoing', 'non_financial'], include_blank: true %> +
+ +
+ <%= form.submit 'Update User' %> +
+ <% end %> + + <%= link_to 'Show User', user_manager_path(@user) %> | + <%= link_to 'Back to Users', user_manager_path %> +
+
\ No newline at end of file diff --git a/app/views/user_manager/index.html.erb b/app/views/user_manager/index.html.erb new file mode 100644 index 0000000..6965bcc --- /dev/null +++ b/app/views/user_manager/index.html.erb @@ -0,0 +1,39 @@ +
+ <% content_for :title, "User management" %> +

User management

+ <%= link_to "Home", root_path, class: "button" %> +
+ +
+
+ + + + + + + + + + + + + + <% @users.each do |user| %> + + + + + + + + + + <% end %> + +
EmailNameAdmin2FA EnabledSubscription StatusMailing List StatusActions
<%= user.email %><%= user.full_name %><%= user.admin? ? 'Yes' : 'No' %><%= user.otp_required_for_login? ? 'Yes' : 'No' %><%= user.subscription_status %><%= user.buttondown_status %> + <%= link_to 'View', user_manager_path(user) %> + <%= link_to 'Edit', edit_user_manager_path(user) %> +
+
+
\ No newline at end of file diff --git a/app/views/user_manager/show.html.erb b/app/views/user_manager/show.html.erb new file mode 100644 index 0000000..507185c --- /dev/null +++ b/app/views/user_manager/show.html.erb @@ -0,0 +1,40 @@ +
+ <% content_for :title, "User management for #{@user.full_name}" %> +

User: <%= @user.full_name %>

+ <%= link_to "Home", root_path, class: "button" %> + <%= link_to 'Edit User', edit_user_manager_path(@user), class: "button" %> + <%= link_to 'Back to Users', user_manager_index_path, class: "button" %> +
+ +
+
+
+
Email:
+
<%= @user.email %>
+ +
Name:
+
<%= @user.full_name %>
+ +
Admin:
+
<%= @user.admin? ? 'Yes' : 'No' %>
+ +
2FA Enabled:
+
<%= @user.otp_required_for_login? ? 'Yes' : 'No' %>
+ +
Subscription Status:
+
<%= @user.subscription_status %>
+ +
Mailing List Status:
+
<%= @user.buttondown_status %>
+ +
Support Type:
+
<%= @user.support_type %>
+ +
Last Payment Date:
+
<%= @user.last_payment_at&.to_s || 'N/A' %>
+ +
Last Payment Amount:
+
<%= number_to_currency(@user.payment_amount) if @user.payment_amount.present? %>
+
+
+
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9678326..e126c35 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -38,7 +38,7 @@ Rails.application.routes.draw do get '/feed', to: 'pubview#rss', as: 'rss', defaults: { format: 'rss' } get '/feed/dispatches', to: 'pubview#dispatches_rss', as: 'dispatches_rss', defaults: { format: 'rss' } get '/join', to: "pubview#join" - + resources :user_manager get '/:slug', to: 'pubview#show_public', as: 'public_page' get '/:year/:slug', to: 'pubview#post', as: 'public_post' # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. diff --git a/test/models/page_test.rb b/test/controllers/user_manager_controller_test.rb similarity index 53% copy from test/models/page_test.rb copy to test/controllers/user_manager_controller_test.rb index fa25544..c20e553 100644 --- a/test/models/page_test.rb +++ b/test/controllers/user_manager_controller_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class PageTest < ActiveSupport::TestCase +class UserManagerControllerTest < ActionDispatch::IntegrationTest # test "the truth" do # assert true # end