1
0
Fork 0

Add action TelegramBotsController#index

This commit is contained in:
Alex Kotov 2018-12-07 05:14:34 +05:00
parent 0600d9b3ec
commit 84f15fa270
No known key found for this signature in database
GPG key ID: 4E831250F47DE154
8 changed files with 150 additions and 12 deletions

View file

@ -0,0 +1,9 @@
# frozen_string_literal: true
class TelegramBotsController < ApplicationController
# GET /telegram_bots
def index
authorize :telegram_bot
@telegram_bots = policy_scope(TelegramBot)
end
end

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class TelegramBotPolicy < ApplicationPolicy
def index?
context.account&.is_superuser?
end
class Scope < Scope
def resolve
return scope.all if context.account&.is_superuser?
scope.none
end
end
end

View file

@ -0,0 +1,28 @@
<div class="container">
<table class="table">
<thead>
<tr>
<th scope="col">
<%= TelegramBot.human_attribute_name :id %>
</th>
<th scope="col">
<%= TelegramBot.human_attribute_name :secret %>
</th>
<th scope="col">
<%= TelegramBot.human_attribute_name :api_token %>
</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<% @telegram_bots.each do |telegram_bot| %>
<tr>
<td scope="row"><%= telegram_bot.id %></td>
<td><%= telegram_bot.secret %></td>
<td><%= telegram_bot.api_token %></td>
</tr>
<% end %>
</tbody>
</table>
</div>

View file

@ -1,6 +1,9 @@
en: en:
activerecord: activerecord:
models: models:
country_state:
one: State
other: States
membership_app: membership_app:
one: Membership application one: Membership application
other: Membership applications other: Membership applications
@ -13,13 +16,17 @@ en:
passport_map: passport_map:
one: Passport mapping one: Passport mapping
other: Passport mappings other: Passport mappings
country_state: telegram_bot:
one: State one: Telegram bot
other: States other: Telegram bots
user: user:
one: User one: User
other: Users other: Users
attributes: attributes:
country_state:
id: ID
membership_apps: Membership applications
name: Name
membership_app: membership_app:
id: ID id: ID
country_state: State country_state: State
@ -61,10 +68,10 @@ en:
passport_map/sex: passport_map/sex:
male: Male male: Male
female: Female female: Female
country_state: telegram_bot:
id: ID id: ID
membership_apps: Membership applications secret: Secret
name: Name api_token: API token
user: user:
id: ID id: ID
confirmation_sent_at: Confirmation sent at confirmation_sent_at: Confirmation sent at

View file

@ -1,6 +1,9 @@
ru: ru:
activerecord: activerecord:
models: models:
country_state:
one: Регион
other: Регионы
membership_app: membership_app:
one: Заявление на вступление one: Заявление на вступление
other: Заявления на вступление other: Заявления на вступление
@ -13,13 +16,17 @@ ru:
passport_map: passport_map:
one: Отображение паспорта one: Отображение паспорта
other: Отображения паспортов other: Отображения паспортов
country_state: telegram_bot:
one: Регион one: Telegram-бот
other: Регионы other: Telegram-боты
user: user:
one: Пользователь one: Пользователь
other: Пользователи other: Пользователи
attributes: attributes:
country_state:
id: ID
membership_apps: Заявления на вступление
name: Название
membership_app: membership_app:
id: ID id: ID
country_state: Регион country_state: Регион
@ -61,10 +68,10 @@ ru:
passport_map/sex: passport_map/sex:
male: Мужской male: Мужской
female: Женский female: Женский
country_state: telegram_bot:
id: ID id: ID
membership_apps: Заявления на вступление secret: Секрет
name: Название api_token: Токен API
user: user:
id: ID id: ID
confirmation_sent_at: Дата отправки подтверждения confirmation_sent_at: Дата отправки подтверждения

View file

@ -20,5 +20,7 @@ Rails.application.routes.draw do
only: %i[index create] only: %i[index create]
end end
resources :telegram_bots, only: :index
resources :telegram_bot_updates, only: :create resources :telegram_bot_updates, only: :create
end end

View file

@ -0,0 +1,25 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe TelegramBotPolicy do
permissions '.scope' do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
end
end

View file

@ -0,0 +1,45 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'GET /telegram_bots' do
before do
sign_in current_account.user if current_account&.user
create_list :telegram_bot, 5
get '/telegram_bots'
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