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