diff --git a/app/controllers/telegram_chats_controller.rb b/app/controllers/telegram_chats_controller.rb new file mode 100644 index 0000000..8c30ee8 --- /dev/null +++ b/app/controllers/telegram_chats_controller.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +class TelegramChatsController < ApplicationController + before_action :set_telegram_chat, except: :index + + # GET /telegram_chats + def index + authorize :telegram_chat + @telegram_chats = policy_scope(TelegramChat) + end + + # GET /telegram_chats/:id + def show + authorize @telegram_chat + end + +private + + def set_telegram_chat + @telegram_chat = TelegramChat.find params[:id] + end +end diff --git a/app/policies/telegram_chat_policy.rb b/app/policies/telegram_chat_policy.rb new file mode 100644 index 0000000..4d541c0 --- /dev/null +++ b/app/policies/telegram_chat_policy.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class TelegramChatPolicy < ApplicationPolicy + def index? + context.account&.is_superuser? + end + + def show? + context.account&.is_superuser? + end + + class Scope < Scope + def resolve + return scope.all if context.account&.is_superuser? + + scope.none + end + end +end diff --git a/app/views/telegram_chats/index.html.erb b/app/views/telegram_chats/index.html.erb new file mode 100644 index 0000000..d326a5f --- /dev/null +++ b/app/views/telegram_chats/index.html.erb @@ -0,0 +1,52 @@ +
+ <%= TelegramChat.human_attribute_name :id %> + | ++ <%= TelegramChat.human_attribute_name :remote_id %> + | ++ <%= TelegramChat.human_attribute_name :chat_type %> + | ++ <%= TelegramChat.human_attribute_name :title %> + | ++ <%= TelegramChat.human_attribute_name :username %> + | ++ <%= TelegramChat.human_attribute_name :first_name %> + | ++ <%= TelegramChat.human_attribute_name :last_name %> + | ++ |
---|---|---|---|---|---|---|---|
<%= telegram_chat.id %> | +<%= telegram_chat.remote_id %> | +<%= telegram_chat.chat_type %> | +<%= truncate telegram_chat.title, length: 20 %> | +<%= truncate telegram_chat.username, length: 20 %> | +<%= truncate telegram_chat.first_name, length: 20 %> | +<%= truncate telegram_chat.last_name, length: 20 %> | ++ <% if policy(telegram_chat).show? %> + <%= link_to telegram_chat_path(telegram_chat), + role: :button, class: 'btn btn-light btn-sm' do %> + + <% end %> + <% end %> + | +