fix: SuperAdmin Improvements (#3733)

- Fix broken access tokens pages
- Fix broken avatar images in the super admin users tab
- Fix broken pagination links in super admin
- Add agent bot tabs

Fixes: #2021
This commit is contained in:
Sojan Jose 2022-01-12 08:30:00 +05:30 committed by GitHub
parent bec1266242
commit f44be0b1e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 18 additions and 77 deletions

View file

@ -12,6 +12,7 @@ class AgentBotDashboard < Administrate::BaseDashboard
avatar_url: AvatarField,
id: Field::Number,
name: Field::String,
account: Field::BelongsTo.with_options(searchable: true, searchable_field: 'name', order: 'id DESC'),
description: Field::String,
outgoing_url: Field::String,
created_at: Field::DateTime,
@ -26,6 +27,7 @@ class AgentBotDashboard < Administrate::BaseDashboard
COLLECTION_ATTRIBUTES = %i[
id
avatar_url
account
name
outgoing_url
].freeze
@ -34,7 +36,7 @@ class AgentBotDashboard < Administrate::BaseDashboard
# an array of attributes that will be displayed on the model's show page.
SHOW_PAGE_ATTRIBUTES = %i[
id
avatar_url
account
name
description
outgoing_url
@ -45,6 +47,7 @@ class AgentBotDashboard < Administrate::BaseDashboard
# on the model's form (`new` and `edit`) pages.
FORM_ATTRIBUTES = %i[
name
account
description
outgoing_url
].freeze

View file

@ -2,6 +2,6 @@ require 'administrate/field/base'
class AvatarField < Administrate::Field::Base
def avatar_url
data.presence || '/admin/avatar.png'
data.presence&.gsub('?d=404', '?d=mp')
end
end

View file

@ -16,11 +16,9 @@
# unique_permissibles_index (platform_app_id,permissible_id,permissible_type) UNIQUE
#
class PlatformAppPermissible < ApplicationRecord
include AccessTokenable
validates :platform_app, presence: true
validates :platform_app_id, uniqueness: { scope: [:permissible_id, :permissible_type] }
belongs_to :platform_app
belongs_to :permissible, polymorphic: true, dependent: :destroy_async
belongs_to :permissible, polymorphic: true
end

View file

@ -1 +1 @@
<%= image_tag field.avatar_url %>
<%= image_tag field.avatar_url if field.avatar_url.present? %>

View file

@ -1 +1 @@
<%= image_tag field.avatar_url %>
<%= image_tag field.avatar_url if field.avatar_url.present? %>

View file

@ -17,7 +17,8 @@ as defined by the routes in the `admin/` namespace
super_admins: 'ion ion-unlocked',
access_tokens: 'ion-key',
platform_apps: 'ion ion-social-buffer',
installation_configs: 'ion ion-settings'
installation_configs: 'ion ion-settings',
agent_bots: 'ion ion-social-android',
}
%>
@ -39,7 +40,7 @@ as defined by the routes in the `admin/` namespace
</li>
<% Administrate::Namespace.new(namespace).resources.each do |resource| %>
<% next if ["account_users", "agent_bots", "dashboard", "devise/sessions", "app_configs" ].include? resource.resource %>
<% next if ["account_users", "dashboard", "devise/sessions", "app_configs" ].include? resource.resource %>
<li class="navigation__link navigation__link--<%= nav_link_state(resource) %>">
<i class="<%= sidebar_icons[resource.resource.to_sym] %>"></i>
<%= link_to(

View file

@ -62,5 +62,5 @@ It renders the `_table` partial to display details about the resources.
table_title: "page-title"
) %>
<%= paginate resources %>
<%= paginate resources, param_name: '_page'%>
</section>

View file

@ -1,66 +0,0 @@
<%#
# Index
This view is the template for the index page.
It is responsible for rendering the search bar, header and pagination.
It renders the `_table` partial to display details about the resources.
## Local variables:
- `page`:
An instance of [Administrate::Page::Collection][1].
Contains helper methods to help display a table,
and knows which attributes should be displayed in the resource's table.
- `resources`:
An instance of `ActiveRecord::Relation` containing the resources
that match the user's search criteria.
By default, these resources are passed to the table partial to be displayed.
- `search_term`:
A string containing the term the user has searched for, if any.
- `show_search_bar`:
A boolean that determines if the search bar should be shown.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
%>
<% content_for(:title) do %>
<%= display_resource_name(page.resource_name) %>
<% end %>
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title" id="page-title">
<%= content_for(:title) %>
</h1>
<% if show_search_bar %>
<%= render(
"search",
search_term: search_term,
resource_name: display_resource_name(page.resource_name)
) %>
<% end %>
<div>
<%= link_to(
t(
"administrate.actions.new_resource",
name: page.resource_name.titleize.downcase
),
[:new, namespace, page.resource_path.to_sym],
class: "button",
) if valid_action?(:new) && show_action?(:new, new_resource) %>
</div>
</header>
<section class="main-content__body main-content__body--flush">
<%= render(
"collection",
collection_presenter: page,
collection_field_name: resource_name,
page: page,
resources: resources,
table_title: "page-title"
) %>
<%= paginate resources %>
</section>

View file

@ -0,0 +1,5 @@
class RemovePlatformAppPermissibleAccessTokens < ActiveRecord::Migration[6.1]
def change
AccessToken.where(owner_type: 'PlatformAppPermissible').destroy_all
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_01_11_200105) do
ActiveRecord::Schema.define(version: 2022_01_11_223630) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB