--- /dev/null
+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
--- /dev/null
+module UserManagerHelper
+end
<% 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
--- /dev/null
+<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
--- /dev/null
+<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
--- /dev/null
+<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
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.
require "test_helper"
-class PageTest < ActiveSupport::TestCase
+class UserManagerControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end