]> gitweb.mndrdr.org Git - arelpe.git/commitdiff
Added user management features
authorAidan Cornelius-Bell <[email protected]>
Wed, 9 Oct 2024 22:34:17 +0000 (09:04 +1030)
committerAidan Cornelius-Bell <[email protected]>
Wed, 9 Oct 2024 22:34:17 +0000 (09:04 +1030)
app/controllers/user_manager_controller.rb [new file with mode: 0644]
app/helpers/user_manager_helper.rb [new file with mode: 0644]
app/views/layouts/_navigation_buttons.html.erb
app/views/user_manager/edit.html.erb [new file with mode: 0644]
app/views/user_manager/index.html.erb [new file with mode: 0644]
app/views/user_manager/show.html.erb [new file with mode: 0644]
config/routes.rb
test/controllers/user_manager_controller_test.rb [copied from test/models/page_test.rb with 53% similarity]

diff --git a/app/controllers/user_manager_controller.rb b/app/controllers/user_manager_controller.rb
new file mode 100644 (file)
index 0000000..db8d6e6
--- /dev/null
@@ -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 (file)
index 0000000..4c21f5c
--- /dev/null
@@ -0,0 +1,2 @@
+module UserManagerHelper
+end
index f4d1725930202d7b5136e50514eb859fc408bec2..2d97d25aa7307e6d4d67efda4bacd9c421c5d6a3 100644 (file)
@@ -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" %>
+  <br>
+  <%= 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 %>
 </div>
\ 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 (file)
index 0000000..e204348
--- /dev/null
@@ -0,0 +1,66 @@
+<div class="container">
+  <% content_for :title, "User editor for #{@user.full_name}" %>
+  <h1>Editing user: <%= @user.full_name %></h1>
+  <%= 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" %>
+</div>
+
+<div class="post">
+       <div class="container">
+               <%= form_with(model: @user, url: user_manager_path(@user), method: :patch, local: true) do |form| %>
+               <% if @user.errors.any? %>
+                       <div id="error_explanation">
+                       <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
+                       <ul>
+                               <% @user.errors.full_messages.each do |message| %>
+                               <li><%= message %></li>
+                               <% end %>
+                       </ul>
+                       </div>
+               <% end %>
+               
+               <div>
+                       <%= form.label :email %>
+                       <%= form.email_field :email %>
+               </div>
+               
+               <div>
+                       <%= form.label :first_name %>
+                       <%= form.text_field :first_name %>
+               </div>
+               
+               <div>
+                       <%= form.label :last_name %>
+                       <%= form.text_field :last_name %>
+               </div>
+               
+               <div>
+                       <%= form.label :admin %>
+                       <%= form.check_box :admin %>
+               </div>
+               
+               <div>
+                       <%= form.label :subscription_status %>
+                       <%= form.select :subscription_status, ['active', 'inactive', 'one_time'], include_blank: true %>
+               </div>
+               
+               <div>
+                       <%= form.label :buttondown_status %>
+                       <%= form.select :buttondown_status, ['unactivated', 'regular', 'premium', 'gifted', 'trialed'], include_blank: true %>
+               </div>
+               
+               <div>
+                       <%= form.label :support_type %>
+                       <%= form.select :support_type, ['one_time', 'ongoing', 'non_financial'], include_blank: true %>
+               </div>
+               
+               <div>
+                       <%= form.submit 'Update User' %>
+               </div>
+               <% end %>
+               
+               <%= link_to 'Show User', user_manager_path(@user) %> |
+               <%= link_to 'Back to Users', user_manager_path %>
+       </div>
+</div>
\ 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 (file)
index 0000000..6965bcc
--- /dev/null
@@ -0,0 +1,39 @@
+<div class="container">
+  <% content_for :title, "User management" %>
+  <h1>User management</h1>
+  <%= link_to "Home", root_path, class: "button" %>
+</div>
+
+<div class="post">
+  <div class="container">
+       <table>
+       <thead>
+               <tr>
+               <th>Email</th>
+               <th>Name</th>
+               <th>Admin</th>
+               <th>2FA Enabled</th>
+               <th>Subscription Status</th>
+               <th>Mailing List Status</th>
+               <th>Actions</th>
+               </tr>
+       </thead>
+       <tbody>
+               <% @users.each do |user| %>
+               <tr>
+                       <td><%= user.email %></td>
+                       <td><%= user.full_name %></td>
+                       <td><%= user.admin? ? 'Yes' : 'No' %></td>
+                       <td><%= user.otp_required_for_login? ? 'Yes' : 'No' %></td>
+                       <td><%= user.subscription_status %></td>
+                       <td><%= user.buttondown_status %></td>
+                       <td>
+                       <%= link_to 'View', user_manager_path(user) %>
+                       <%= link_to 'Edit', edit_user_manager_path(user) %>
+                       </td>
+               </tr>
+               <% end %>
+       </tbody>
+       </table>
+  </div>
+</div>
\ 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 (file)
index 0000000..507185c
--- /dev/null
@@ -0,0 +1,40 @@
+<div class="container">
+  <% content_for :title, "User management for #{@user.full_name}" %>
+  <h1>User: <%= @user.full_name %></h1>
+  <%= 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" %>
+</div>
+
+<div class="post">
+       <div class="container">
+               <dl>
+               <dt>Email:</dt>
+               <dd><%= @user.email %></dd>
+               
+               <dt>Name:</dt>
+               <dd><%= @user.full_name %></dd>
+               
+               <dt>Admin:</dt>
+               <dd><%= @user.admin? ? 'Yes' : 'No' %></dd>
+               
+               <dt>2FA Enabled:</dt>
+               <dd><%= @user.otp_required_for_login? ? 'Yes' : 'No' %></dd>
+               
+               <dt>Subscription Status:</dt>
+               <dd><%= @user.subscription_status %></dd>
+               
+               <dt>Mailing List Status:</dt>
+               <dd><%= @user.buttondown_status %></dd>
+               
+               <dt>Support Type:</dt>
+               <dd><%= @user.support_type %></dd>
+               
+               <dt>Last Payment Date:</dt>
+               <dd><%= @user.last_payment_at&.to_s || 'N/A' %></dd>
+               
+               <dt>Last Payment Amount:</dt>
+               <dd><%= number_to_currency(@user.payment_amount) if @user.payment_amount.present? %></dd>
+               </dl>
+       </div>
+</div>
\ No newline at end of file
index 9678326904631997867415fedcb6896c8ced8ef9..e126c357f49d9a8947b2065e90e04e63fdf15849 100644 (file)
@@ -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.
similarity index 53%
copy from test/models/page_test.rb
copy to test/controllers/user_manager_controller_test.rb
index fa2554411c801b91035a0ca77dc3dff0fc1e6c3b..c20e55398121277aacd76569addc4bc4f89d9834 100644 (file)
@@ -1,6 +1,6 @@
 require "test_helper"
 
-class PageTest < ActiveSupport::TestCase
+class UserManagerControllerTest < ActionDispatch::IntegrationTest
   # test "the truth" do
   #   assert true
   # end