1
0
Fork 0

Add action Settings::ContactsController#index

This commit is contained in:
Alex Kotov 2019-09-03 00:30:18 +05:00
parent 9bfe23d9be
commit 1a1724cda0
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
11 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,19 @@
# frozen_string_literal: true
class Settings::ContactsController < ApplicationController
before_action :skip_policy_scope, only: :index
before_action :set_account
# GET /settings/contacts
def index
authorize %i[settings contact]
@contacts = @account.contact_list.contacts
end
private
def set_account
@account = current_account.clone&.reload
end
end

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class Settings::ContactPolicy < ApplicationPolicy
def index?
!!account
end
end

View File

@ -13,4 +13,8 @@
policy(%i[settings person]).show?,
settings_person_path,
],
contacts: [
policy(%i[settings contact]).index?,
settings_contacts_path,
],
) %>

View File

@ -0,0 +1,31 @@
<div class="container">
<div class="row">
<div class="col-md-3 mb-4">
<%= render partial: 'settings/nav_sidebar', locals: { tab: :contacts } %>
</div>
<div class="col-md-9">
<table class="table">
<thead>
<tr>
<th scope="col">
<%= Contact.human_attribute_name :contact_network %>
</th>
<th scope="col">
<%= Contact.human_attribute_name :value %>
</th>
</tr>
</thead>
<tbody>
<% @contacts.each do |contact| %>
<tr>
<td><%= contact.contact_network.name %></td>
<td><%= truncate contact.value %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>

View File

@ -4,6 +4,9 @@ en:
account:
one: Account
many: Accounts
contact:
one: Contact
many: Contacts
contact_network:
one: Contact network
many: Contact networks
@ -36,6 +39,10 @@ en:
biography: Bio
avatar: Avatar
person: Person
contact:
id: ID
contact_network: Contact network
value: Value
contact_network:
id: ID
codename: Codename

View File

@ -4,6 +4,9 @@ ru:
account:
one: Аккаунт
many: Аккаунты
contact:
one: Контакт
many: Контакты
contact_network:
one: Сеть контактов
many: Сети контактов
@ -36,6 +39,10 @@ ru:
biography: Биография
avatar: Аватар
person: Человек
contact:
id: ID
contact_network: Сеть контактов
value: Значение
contact_network:
id: ID
codename: Кодовое имя

View File

@ -9,3 +9,4 @@ en:
credentials: Credentials
profile: Public profile
person: Person
contacts: Contacts

View File

@ -9,3 +9,4 @@ ru:
credentials: Данные для входа
profile: Публичный профиль
person: Личность
contacts: Контакты

View File

@ -33,6 +33,7 @@ Rails.application.routes.draw do
namespace :settings do
resource :profile, only: %i[edit update]
resource :person, only: %i[show new]
resources :contacts, only: :index
end
#########################

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Settings::ContactPolicy do
pending "add some examples to (or delete) #{__FILE__}"
end

View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe 'GET /settings/contacts' do
before do
sign_in current_account.user if current_account&.user
get '/settings/contacts'
end
for_account_types nil do
specify do
expect(response).to have_http_status :forbidden
end
end
for_account_types :usual, :personal, :superuser do
specify do
expect(response).to have_http_status :ok
end
end
end