1
0
Fork 0

Add contact network links

This commit is contained in:
Alex Kotov 2020-04-10 07:15:48 +05:00
parent 781677887f
commit decd0da0f3
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
13 changed files with 107 additions and 21 deletions

View File

@ -31,6 +31,14 @@ class Contact < ApplicationRecord
validates :send_security_notifications,
inclusion: { in: [false], unless: :contact_network_communicable? }
###########
# Methods #
###########
def link
contact_network&.link&.sub('$$', value).freeze
end
private
def turn_blanks_into_nils

View File

@ -15,6 +15,12 @@ class ContactNetwork < ApplicationRecord
validates :name, good_small_text: true, uniqueness: true
validates :link,
allow_nil: true,
allow_blank: false,
presence: true,
format: { with: /\A[^\s]+\z/ }
###########
# Methods #
###########

View File

@ -18,7 +18,14 @@
<% contacts.each do |contact| %>
<tr>
<td><%= contact.contact_network.name %></td>
<td><%= truncate contact.value %></td>
<td>
<% if contact.link.nil? %>
<%= truncate contact.value %>
<% else %>
<%= link_to truncate(contact.value), contact.link, target: :_blank %>
<i class="fas fa-external-link-alt fa-xs text-muted"></i>
<% end %>
</td>
<td>
<% if policy([
:settings,

View File

@ -7,6 +7,9 @@
<th scope="col">
<%= ContactNetwork.human_attribute_name :name %>
</th>
<th scope="col">
<%= ContactNetwork.human_attribute_name :link %>
</th>
<th scope="col">
<%= ContactNetwork.human_attribute_name :contacts %>
</th>
@ -19,6 +22,7 @@
<tr>
<td scope="row"><%= contact_network.codename %></td>
<td><%= contact_network.name %></td>
<td><%= contact_network.link %></td>
<td><%= contact_network.contacts.count %></td>
<td></td>
</tr>

View File

@ -77,11 +77,13 @@ en:
contact_network: Contact network
value: Value
send_security_notifications: Security notifications
link: Link
contact_network:
id: ID
codename: Codename
contacts: Contacts
name: Name
link: Link
federal_subject:
id: ID
english_name: Name

View File

@ -64,11 +64,13 @@ ru:
contact_network: Сеть контактов
value: Значение
send_security_notifications: Уведомления безопасности
link: Ссылка
contact_network:
id: ID
codename: Кодовое имя
contacts: Контакты
name: Название
link: Ссылка
federal_subject:
id: ID
english_name: Название

View File

@ -1,18 +1,18 @@
1 | phone | Phone
2 | email | Email
3 | telegram_phone | Telegram (phone)
4 | telegram_username | Telegram (username)
5 | telegram_id | Telegram (id)
6 | twitter | Twitter
7 | facebook | Facebook
8 | vkontakte | VK
9 | skype | Skype
10 | xmpp | XMPP
11 | pgp | PGP
12 | google_plus | Google+
13 | www | www
14 | odnoklassniki | Odnoklassniki
15 | ostatus | OStatus
16 | livejournal | LiveJournal
41 | trello_id | Trello (id)
61 | trello_username | Trello (username)
1 | phone | Phone | |
2 | email | Email | mailto:$$ |
3 | telegram_phone | Telegram (phone) | |
4 | telegram_username | Telegram (username) | https://t.me/$$ |
5 | telegram_id | Telegram (id) | |
6 | twitter | Twitter | https://twitter.com/$$ |
7 | facebook | Facebook | https://fb.com/$$ |
8 | vkontakte | VK | https://vk.com/$$ |
9 | skype | Skype | |
10 | xmpp | XMPP | |
11 | pgp | PGP | |
12 | google_plus | Google+ | |
13 | www | www | $$ |
14 | odnoklassniki | Odnoklassniki | |
15 | ostatus | OStatus | |
16 | livejournal | LiveJournal | |
41 | trello_id | Trello (id) | |
61 | trello_username | Trello (username) | https://trello.com/$$ |

1 1 phone Phone Phone
2 2 email Email Email mailto:$$
3 3 telegram_phone Telegram (phone) Telegram (phone)
4 4 telegram_username Telegram (username) Telegram (username) https://t.me/$$
5 5 telegram_id Telegram (id) Telegram (id)
6 6 twitter Twitter Twitter https://twitter.com/$$
7 7 facebook Facebook Facebook https://fb.com/$$
8 8 vkontakte VK VK https://vk.com/$$
9 9 skype Skype Skype
10 10 xmpp XMPP XMPP
11 11 pgp PGP PGP
12 12 google_plus Google+ Google+
13 13 www www www $$
14 14 odnoklassniki Odnoklassniki Odnoklassniki
15 15 ostatus OStatus OStatus
16 16 livejournal LiveJournal LiveJournal
17 41 trello_id Trello (id) Trello (id)
18 61 trello_username Trello (username) Trello (username) https://trello.com/$$

View File

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddLinkToContactNetworks < ActiveRecord::Migration[6.0]
def change
add_column :contact_networks, :link, :string
end
end

View File

@ -29,14 +29,16 @@ do |(id, english_name, native_name, number, timezone, centre)|
end
csv_foreach :contact_networks \
do |(id, codename, name)|
do |(id, codename, name, link)|
id = Integer(id.strip)
codename.strip!
name.strip!
link = link.strip.presence
ContactNetwork.where(id: id).first_or_create! do |new_contact_network|
new_contact_network.codename = codename
new_contact_network.name = name
new_contact_network.link = link
end
end

View File

@ -645,6 +645,7 @@ CREATE TABLE public.contact_networks (
updated_at timestamp(6) without time zone NOT NULL,
codename character varying NOT NULL,
name character varying NOT NULL,
link character varying,
CONSTRAINT codename CHECK (public.is_codename((codename)::text)),
CONSTRAINT name CHECK (public.is_good_small_text((name)::text))
);
@ -1989,6 +1990,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20191002170727'),
('20191021060000'),
('20191021061920'),
('20200408085219');
('20200408085219'),
('20200410021628');

View File

@ -4,6 +4,7 @@ FactoryBot.define do
factory :contact_network do
codename { Faker::Internet.unique.username 3..36, %w[_] }
name { Faker::Company.unique.name }
link { nil }
end
factory :email_contact_network, class: ContactNetwork do
@ -13,6 +14,7 @@ FactoryBot.define do
codename { 'email' }
name { 'Email' }
link { 'mailto:$$' }
end
factory :phone_contact_network, class: ContactNetwork do
@ -22,5 +24,6 @@ FactoryBot.define do
codename { 'phone' }
name { 'Phone' }
link { nil }
end
end

View File

@ -77,6 +77,23 @@ RSpec.describe ContactNetwork do
it { is_expected.not_to allow_value "Foo\n" }
end
describe '#link' do
def allow_value(*)
super.for :link
end
it { is_expected.to allow_value nil }
it { is_expected.not_to allow_value '' }
it { is_expected.not_to allow_value ' ' }
it { is_expected.to allow_value 'mailto:$$' }
it { is_expected.to allow_value 'https://t.me/$$' }
it { is_expected.not_to allow_value ' mailto:$$' }
it { is_expected.not_to allow_value 'mailto:$$ ' }
it { is_expected.not_to allow_value ' mailto:$$ ' }
end
describe '#communicable?' do
specify do
expect(subject.communicable?).to equal false

View File

@ -114,4 +114,30 @@ RSpec.describe Contact do
end
end
end
describe '#link' do
context 'for email' do
subject { create :email_contact }
specify do
expect(subject.link).to be_instance_of String
end
specify do
expect(subject.link).to be_frozen
end
specify do
expect(subject.link).to eq "mailto:#{subject.value}"
end
end
context 'for phone' do
subject { create :phone_contact }
specify do
expect(subject.link).to equal nil
end
end
end
end