Add action TelegramBot#show
This commit is contained in:
parent
9fa103ab75
commit
8b365a955d
|
@ -1,9 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TelegramBotsController < ApplicationController
|
||||
before_action :set_telegram_bot, except: :index
|
||||
|
||||
# GET /telegram_bots
|
||||
def index
|
||||
authorize :telegram_bot
|
||||
@telegram_bots = policy_scope(TelegramBot)
|
||||
end
|
||||
|
||||
# GET /telegram_bots/:id
|
||||
def show
|
||||
authorize @telegram_bot
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_telegram_bot
|
||||
@telegram_bot = TelegramBot.find params[:id]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,10 @@ class TelegramBotPolicy < ApplicationPolicy
|
|||
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?
|
||||
|
|
|
@ -25,7 +25,14 @@
|
|||
<td><%= telegram_bot.secret %></td>
|
||||
<td><%= telegram_bot.api_token %></td>
|
||||
<td><%= truncate telegram_bot.username, length: 20 %></td>
|
||||
<td></td>
|
||||
<td>
|
||||
<% if policy(telegram_bot).show? %>
|
||||
<%= link_to telegram_bot_path(telegram_bot),
|
||||
role: :button, class: 'btn btn-light btn-sm' do %>
|
||||
<i class="far fa-eye"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<div class="container">
|
||||
<dl>
|
||||
<dt><%= TelegramBot.human_attribute_name :secret %></dt>
|
||||
<dd><%= @telegram_bot.secret %></dd>
|
||||
|
||||
<dt><%= TelegramBot.human_attribute_name :api_token %></dt>
|
||||
<dd><%= @telegram_bot.api_token %></dd>
|
||||
|
||||
<dt><%= TelegramBot.human_attribute_name :username %></dt>
|
||||
<dd><%= truncate @telegram_bot.username %></dd>
|
||||
</dl>
|
||||
</div>
|
|
@ -20,7 +20,7 @@ Rails.application.routes.draw do
|
|||
only: %i[index create]
|
||||
end
|
||||
|
||||
resources :telegram_bots, only: :index
|
||||
resources :telegram_bots, only: %i[index show]
|
||||
|
||||
resources :telegram_bot_updates, only: :create
|
||||
end
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /telegram_bots/:id' do
|
||||
let!(:telegram_bot) { create :telegram_bot }
|
||||
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
get "/telegram_bots/#{telegram_bot.id}"
|
||||
end
|
||||
|
||||
context 'when no account is authenticated' do
|
||||
let(:current_account) { nil }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
context 'when guest account is authenticated' do
|
||||
let(:current_account) { create :guest_account }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
context 'when usual account is authenticated' do
|
||||
let(:current_account) { create :account_with_user }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
context 'when superuser account is authenticated' do
|
||||
let(:current_account) { create :superuser_account }
|
||||
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue