Move telegram bot routes
This commit is contained in:
parent
3850ef1b6c
commit
238d7833c6
8 changed files with 16 additions and 14 deletions
|
@ -1,17 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TelegramBotsController < ApplicationController
|
||||
class Staff::TelegramBotsController < ApplicationController
|
||||
before_action :set_telegram_bot, except: :index
|
||||
|
||||
# GET /telegram_bots
|
||||
def index
|
||||
authorize :telegram_bot
|
||||
@telegram_bots = policy_scope(TelegramBot)
|
||||
authorize %i[staff telegram_bot]
|
||||
@telegram_bots = policy_scope(
|
||||
TelegramBot,
|
||||
policy_scope_class: Staff::TelegramBotPolicy::Scope,
|
||||
)
|
||||
end
|
||||
|
||||
# GET /telegram_bots/:id
|
||||
def show
|
||||
authorize @telegram_bot
|
||||
authorize [:staff, @telegram_bot]
|
||||
end
|
||||
|
||||
private
|
|
@ -1,6 +1,6 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TelegramBotPolicy < ApplicationPolicy
|
||||
class Staff::TelegramBotPolicy < ApplicationPolicy
|
||||
def index?
|
||||
context.account&.is_superuser?
|
||||
end
|
|
@ -26,8 +26,8 @@
|
|||
<td><%= telegram_bot.api_token %></td>
|
||||
<td><%= truncate telegram_bot.username, length: 20 %></td>
|
||||
<td>
|
||||
<% if policy(telegram_bot).show? %>
|
||||
<%= link_to telegram_bot_path(telegram_bot),
|
||||
<% if policy([:staff, telegram_bot]).show? %>
|
||||
<%= link_to [:staff, telegram_bot],
|
||||
role: :button, class: 'btn btn-light btn-sm' do %>
|
||||
<i class="far fa-eye"></i>
|
||||
<% end %>
|
|
@ -34,11 +34,10 @@ Rails.application.routes.draw do
|
|||
only: %i[index create]
|
||||
end
|
||||
|
||||
resources :telegram_bots, only: %i[index show]
|
||||
resources :telegram_chats, only: %i[index show]
|
||||
end
|
||||
|
||||
resources :telegram_bots, only: %i[index show]
|
||||
|
||||
resources :telegram_bots, only: [] do
|
||||
resources :updates,
|
||||
controller: 'telegram_bots/updates',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe TelegramBotPolicy do
|
||||
RSpec.describe Staff::TelegramBotPolicy do
|
||||
permissions '.scope' do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /telegram_bots' do
|
||||
RSpec.describe 'GET /staff/telegram_bots' do
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
|
||||
create_list :telegram_bot, 5
|
||||
|
||||
get '/telegram_bots'
|
||||
get '/staff/telegram_bots'
|
||||
end
|
||||
|
||||
context 'when no account is authenticated' do
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /telegram_bots/:id' do
|
||||
RSpec.describe 'GET /staff/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}"
|
||||
get "/staff/telegram_bots/#{telegram_bot.id}"
|
||||
end
|
||||
|
||||
context 'when no account is authenticated' do
|
Reference in a new issue