Add contact network links
This commit is contained in:
parent
781677887f
commit
decd0da0f3
|
@ -31,6 +31,14 @@ class Contact < ApplicationRecord
|
||||||
validates :send_security_notifications,
|
validates :send_security_notifications,
|
||||||
inclusion: { in: [false], unless: :contact_network_communicable? }
|
inclusion: { in: [false], unless: :contact_network_communicable? }
|
||||||
|
|
||||||
|
###########
|
||||||
|
# Methods #
|
||||||
|
###########
|
||||||
|
|
||||||
|
def link
|
||||||
|
contact_network&.link&.sub('$$', value).freeze
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def turn_blanks_into_nils
|
def turn_blanks_into_nils
|
||||||
|
|
|
@ -15,6 +15,12 @@ class ContactNetwork < ApplicationRecord
|
||||||
|
|
||||||
validates :name, good_small_text: true, uniqueness: true
|
validates :name, good_small_text: true, uniqueness: true
|
||||||
|
|
||||||
|
validates :link,
|
||||||
|
allow_nil: true,
|
||||||
|
allow_blank: false,
|
||||||
|
presence: true,
|
||||||
|
format: { with: /\A[^\s]+\z/ }
|
||||||
|
|
||||||
###########
|
###########
|
||||||
# Methods #
|
# Methods #
|
||||||
###########
|
###########
|
||||||
|
|
|
@ -18,7 +18,14 @@
|
||||||
<% contacts.each do |contact| %>
|
<% contacts.each do |contact| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= contact.contact_network.name %></td>
|
<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>
|
<td>
|
||||||
<% if policy([
|
<% if policy([
|
||||||
:settings,
|
:settings,
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
<%= ContactNetwork.human_attribute_name :name %>
|
<%= ContactNetwork.human_attribute_name :name %>
|
||||||
</th>
|
</th>
|
||||||
|
<th scope="col">
|
||||||
|
<%= ContactNetwork.human_attribute_name :link %>
|
||||||
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
<%= ContactNetwork.human_attribute_name :contacts %>
|
<%= ContactNetwork.human_attribute_name :contacts %>
|
||||||
</th>
|
</th>
|
||||||
|
@ -19,6 +22,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td scope="row"><%= contact_network.codename %></td>
|
<td scope="row"><%= contact_network.codename %></td>
|
||||||
<td><%= contact_network.name %></td>
|
<td><%= contact_network.name %></td>
|
||||||
|
<td><%= contact_network.link %></td>
|
||||||
<td><%= contact_network.contacts.count %></td>
|
<td><%= contact_network.contacts.count %></td>
|
||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -77,11 +77,13 @@ en:
|
||||||
contact_network: Contact network
|
contact_network: Contact network
|
||||||
value: Value
|
value: Value
|
||||||
send_security_notifications: Security notifications
|
send_security_notifications: Security notifications
|
||||||
|
link: Link
|
||||||
contact_network:
|
contact_network:
|
||||||
id: ID
|
id: ID
|
||||||
codename: Codename
|
codename: Codename
|
||||||
contacts: Contacts
|
contacts: Contacts
|
||||||
name: Name
|
name: Name
|
||||||
|
link: Link
|
||||||
federal_subject:
|
federal_subject:
|
||||||
id: ID
|
id: ID
|
||||||
english_name: Name
|
english_name: Name
|
||||||
|
|
|
@ -64,11 +64,13 @@ ru:
|
||||||
contact_network: Сеть контактов
|
contact_network: Сеть контактов
|
||||||
value: Значение
|
value: Значение
|
||||||
send_security_notifications: Уведомления безопасности
|
send_security_notifications: Уведомления безопасности
|
||||||
|
link: Ссылка
|
||||||
contact_network:
|
contact_network:
|
||||||
id: ID
|
id: ID
|
||||||
codename: Кодовое имя
|
codename: Кодовое имя
|
||||||
contacts: Контакты
|
contacts: Контакты
|
||||||
name: Название
|
name: Название
|
||||||
|
link: Ссылка
|
||||||
federal_subject:
|
federal_subject:
|
||||||
id: ID
|
id: ID
|
||||||
english_name: Название
|
english_name: Название
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
1 | phone | Phone
|
1 | phone | Phone | |
|
||||||
2 | email | Email
|
2 | email | Email | mailto:$$ |
|
||||||
3 | telegram_phone | Telegram (phone)
|
3 | telegram_phone | Telegram (phone) | |
|
||||||
4 | telegram_username | Telegram (username)
|
4 | telegram_username | Telegram (username) | https://t.me/$$ |
|
||||||
5 | telegram_id | Telegram (id)
|
5 | telegram_id | Telegram (id) | |
|
||||||
6 | twitter | Twitter
|
6 | twitter | Twitter | https://twitter.com/$$ |
|
||||||
7 | facebook | Facebook
|
7 | facebook | Facebook | https://fb.com/$$ |
|
||||||
8 | vkontakte | VK
|
8 | vkontakte | VK | https://vk.com/$$ |
|
||||||
9 | skype | Skype
|
9 | skype | Skype | |
|
||||||
10 | xmpp | XMPP
|
10 | xmpp | XMPP | |
|
||||||
11 | pgp | PGP
|
11 | pgp | PGP | |
|
||||||
12 | google_plus | Google+
|
12 | google_plus | Google+ | |
|
||||||
13 | www | www
|
13 | www | www | $$ |
|
||||||
14 | odnoklassniki | Odnoklassniki
|
14 | odnoklassniki | Odnoklassniki | |
|
||||||
15 | ostatus | OStatus
|
15 | ostatus | OStatus | |
|
||||||
16 | livejournal | LiveJournal
|
16 | livejournal | LiveJournal | |
|
||||||
41 | trello_id | Trello (id)
|
41 | trello_id | Trello (id) | |
|
||||||
61 | trello_username | Trello (username)
|
61 | trello_username | Trello (username) | https://trello.com/$$ |
|
||||||
|
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddLinkToContactNetworks < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
add_column :contact_networks, :link, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -29,14 +29,16 @@ do |(id, english_name, native_name, number, timezone, centre)|
|
||||||
end
|
end
|
||||||
|
|
||||||
csv_foreach :contact_networks \
|
csv_foreach :contact_networks \
|
||||||
do |(id, codename, name)|
|
do |(id, codename, name, link)|
|
||||||
id = Integer(id.strip)
|
id = Integer(id.strip)
|
||||||
codename.strip!
|
codename.strip!
|
||||||
name.strip!
|
name.strip!
|
||||||
|
link = link.strip.presence
|
||||||
|
|
||||||
ContactNetwork.where(id: id).first_or_create! do |new_contact_network|
|
ContactNetwork.where(id: id).first_or_create! do |new_contact_network|
|
||||||
new_contact_network.codename = codename
|
new_contact_network.codename = codename
|
||||||
new_contact_network.name = name
|
new_contact_network.name = name
|
||||||
|
new_contact_network.link = link
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -645,6 +645,7 @@ CREATE TABLE public.contact_networks (
|
||||||
updated_at timestamp(6) without time zone NOT NULL,
|
updated_at timestamp(6) without time zone NOT NULL,
|
||||||
codename character varying NOT NULL,
|
codename character varying NOT NULL,
|
||||||
name character varying NOT NULL,
|
name character varying NOT NULL,
|
||||||
|
link character varying,
|
||||||
CONSTRAINT codename CHECK (public.is_codename((codename)::text)),
|
CONSTRAINT codename CHECK (public.is_codename((codename)::text)),
|
||||||
CONSTRAINT name CHECK (public.is_good_small_text((name)::text))
|
CONSTRAINT name CHECK (public.is_good_small_text((name)::text))
|
||||||
);
|
);
|
||||||
|
@ -1989,6 +1990,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20191002170727'),
|
('20191002170727'),
|
||||||
('20191021060000'),
|
('20191021060000'),
|
||||||
('20191021061920'),
|
('20191021061920'),
|
||||||
('20200408085219');
|
('20200408085219'),
|
||||||
|
('20200410021628');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ FactoryBot.define do
|
||||||
factory :contact_network do
|
factory :contact_network do
|
||||||
codename { Faker::Internet.unique.username 3..36, %w[_] }
|
codename { Faker::Internet.unique.username 3..36, %w[_] }
|
||||||
name { Faker::Company.unique.name }
|
name { Faker::Company.unique.name }
|
||||||
|
link { nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :email_contact_network, class: ContactNetwork do
|
factory :email_contact_network, class: ContactNetwork do
|
||||||
|
@ -13,6 +14,7 @@ FactoryBot.define do
|
||||||
|
|
||||||
codename { 'email' }
|
codename { 'email' }
|
||||||
name { 'Email' }
|
name { 'Email' }
|
||||||
|
link { 'mailto:$$' }
|
||||||
end
|
end
|
||||||
|
|
||||||
factory :phone_contact_network, class: ContactNetwork do
|
factory :phone_contact_network, class: ContactNetwork do
|
||||||
|
@ -22,5 +24,6 @@ FactoryBot.define do
|
||||||
|
|
||||||
codename { 'phone' }
|
codename { 'phone' }
|
||||||
name { 'Phone' }
|
name { 'Phone' }
|
||||||
|
link { nil }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,6 +77,23 @@ RSpec.describe ContactNetwork do
|
||||||
it { is_expected.not_to allow_value "Foo\n" }
|
it { is_expected.not_to allow_value "Foo\n" }
|
||||||
end
|
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
|
describe '#communicable?' do
|
||||||
specify do
|
specify do
|
||||||
expect(subject.communicable?).to equal false
|
expect(subject.communicable?).to equal false
|
||||||
|
|
|
@ -114,4 +114,30 @@ RSpec.describe Contact do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
Reference in New Issue