diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb new file mode 100644 index 0000000..51c9f01 --- /dev/null +++ b/app/controllers/admin/accounts_controller.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Admin + class AccountsController < ApplicationController + prepend_before_action :authenticate_account! + before_action :require_admin! + + def search + @query = params[:q] + @account = Account.find_by(email: @query) if @query.present? + end + + private + + def require_admin! + return if current_account&.admin? + + redirect_to root_path, alert: 'Access denied.' + end + end +end diff --git a/app/views/admin/accounts/search.html.erb b/app/views/admin/accounts/search.html.erb new file mode 100644 index 0000000..60ca7e8 --- /dev/null +++ b/app/views/admin/accounts/search.html.erb @@ -0,0 +1,96 @@ +
+
+
+

Account Search

+

Search for an account by email address

+
+ + <%= form_with url: admin_accounts_search_path, method: :get, class: "space-y-4" do |f| %> +
+ +
+ +
+
+ + + <% end %> + + <% if @query.present? %> +
+ <% if @account.present? %> +
+
+ <% if @account.photo.attached? %> + <%= image_tag cdn_proxy_url(@account.photo.variant(:thumb)), class: "h-16 w-16 rounded-full object-cover" %> + <% else %> +
+ <%= @account.name&.first&.upcase %> +
+ <% end %> +
+

<%= @account.name %>

+

<%= @account.email %>

+

@<%= @account.slug %>

+
+
+ +
+ <%= link_to "View Dashboard", page_path(@account), class: "flex-1 text-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700" %> + <%= link_to "View Public Page", @account.url, target: "_blank", class: "flex-1 text-center py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50" %> +
+ +
+
+
+
Created
+
<%= @account.created_at.strftime("%b %d, %Y") %>
+
+
+
Posts
+
<%= @account.posts.count %>
+
+
+
Subscribers
+
<%= @account.subscriptions.count %>
+
+
+
Subscription
+
<%= @account.active_subscription? ? "Active" : "None" %>
+
+
+
+
+ <% else %> +
+
+
+ + + +
+
+

+ No account found for <%= @query %> +

+
+
+
+ <% end %> +
+ <% end %> +
+
diff --git a/app/views/layouts/dashboard.html.erb b/app/views/layouts/dashboard.html.erb index bebd91f..461321e 100644 --- a/app/views/layouts/dashboard.html.erb +++ b/app/views/layouts/dashboard.html.erb @@ -50,6 +50,12 @@ secondaryMenuItems = [ to: page_billing_path(@account), show: @account&.active_subscription? && Rails.configuration.multiuser_mode }, + { + name: "Account Search", + newTab: false, + to: admin_accounts_search_path, + show: @account&.admin? && Rails.configuration.multiuser_mode + }, { name: "Queue", newTab: true, diff --git a/config/routes.rb b/config/routes.rb index 6c1067b..54860b6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,6 +27,10 @@ mount PgHero::Engine, at: 'db', :constraints => { :host => Rails.configuration.base_host } end + namespace :admin, :constraints => { :host => Rails.configuration.base_host } do + get 'accounts/search', to: 'accounts#search', as: :accounts_search + end + if Rails.env.development? mount LetterOpenerWeb::Engine, at: '/letter_opener', :constraints => { :host => Rails.configuration.base_host } end