Add attribute Contact#show_in_public
This commit is contained in:
parent
273ce969f9
commit
20b0f74862
11 changed files with 84 additions and 1 deletions
|
@ -0,0 +1,21 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Settings::Contacts::PublicSwitchesController < ApplicationController
|
||||||
|
before_action :set_contact
|
||||||
|
|
||||||
|
# POST /settings/contacts/:contact_id/public_switch
|
||||||
|
def create
|
||||||
|
authorize [:settings, ContactPublicSwitch.new(@contact)]
|
||||||
|
|
||||||
|
@contact.show_in_public = !@contact.show_in_public
|
||||||
|
@contact.save!
|
||||||
|
|
||||||
|
redirect_to settings_contacts_url
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_contact
|
||||||
|
@contact = current_account&.contact_list&.contacts&.find params[:contact_id]
|
||||||
|
end
|
||||||
|
end
|
8
app/policies/settings/contact_public_switch_policy.rb
Normal file
8
app/policies/settings/contact_public_switch_policy.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Settings::ContactPublicSwitchPolicy < ApplicationPolicy
|
||||||
|
def create?
|
||||||
|
account &&
|
||||||
|
record.contact.contact_list.account == account
|
||||||
|
end
|
||||||
|
end
|
9
app/primitives/contact_public_switch.rb
Normal file
9
app/primitives/contact_public_switch.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ContactPublicSwitch
|
||||||
|
attr_reader :contact
|
||||||
|
|
||||||
|
def initialize(contact)
|
||||||
|
@contact = contact or raise
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,6 +10,9 @@
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
<%= Contact.human_attribute_name :send_security_notifications %>
|
<%= Contact.human_attribute_name :send_security_notifications %>
|
||||||
</th>
|
</th>
|
||||||
|
<th scope="col">
|
||||||
|
<%= Contact.human_attribute_name :show_in_public %>
|
||||||
|
</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -39,6 +42,19 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<% if policy([
|
||||||
|
:settings,
|
||||||
|
ContactPublicSwitch.new(contact),
|
||||||
|
]).create? %>
|
||||||
|
<%= link_to(
|
||||||
|
settings_contact_public_switch_path(contact),
|
||||||
|
method: :post,
|
||||||
|
) do %>
|
||||||
|
<%= bool_badge contact.show_in_public %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% if policy([:settings, contact]).destroy? %>
|
<% if policy([:settings, contact]).destroy? %>
|
||||||
<%= link_to(
|
<%= link_to(
|
||||||
|
|
|
@ -77,6 +77,7 @@ en:
|
||||||
contact_network: Contact network
|
contact_network: Contact network
|
||||||
value: Value
|
value: Value
|
||||||
send_security_notifications: Security notifications
|
send_security_notifications: Security notifications
|
||||||
|
show_in_public: Public
|
||||||
link: Link
|
link: Link
|
||||||
contact_network:
|
contact_network:
|
||||||
id: ID
|
id: ID
|
||||||
|
|
|
@ -64,6 +64,7 @@ ru:
|
||||||
contact_network: Сеть контактов
|
contact_network: Сеть контактов
|
||||||
value: Значение
|
value: Значение
|
||||||
send_security_notifications: Уведомления безопасности
|
send_security_notifications: Уведомления безопасности
|
||||||
|
show_in_public: Публичный
|
||||||
link: Ссылка
|
link: Ссылка
|
||||||
contact_network:
|
contact_network:
|
||||||
id: ID
|
id: ID
|
||||||
|
|
|
@ -40,6 +40,10 @@ Rails.application.routes.draw do
|
||||||
resource :security_notification_switch,
|
resource :security_notification_switch,
|
||||||
controller: 'contacts/security_notification_switches',
|
controller: 'contacts/security_notification_switches',
|
||||||
only: :create
|
only: :create
|
||||||
|
|
||||||
|
resource :public_switch,
|
||||||
|
controller: 'contacts/public_switches',
|
||||||
|
only: :create
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddShowInPublicToContacts < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
add_column :contacts, :show_in_public, :boolean, null: false, default: false
|
||||||
|
end
|
||||||
|
end
|
|
@ -682,6 +682,7 @@ CREATE TABLE public.contacts (
|
||||||
contact_network_id bigint NOT NULL,
|
contact_network_id bigint NOT NULL,
|
||||||
value character varying NOT NULL,
|
value character varying NOT NULL,
|
||||||
send_security_notifications boolean DEFAULT false NOT NULL,
|
send_security_notifications boolean DEFAULT false NOT NULL,
|
||||||
|
show_in_public boolean DEFAULT false NOT NULL,
|
||||||
CONSTRAINT value CHECK (public.is_good_small_text((value)::text))
|
CONSTRAINT value CHECK (public.is_good_small_text((value)::text))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1991,6 +1992,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20191021060000'),
|
('20191021060000'),
|
||||||
('20191021061920'),
|
('20191021061920'),
|
||||||
('20200408085219'),
|
('20200408085219'),
|
||||||
('20200410021628');
|
('20200410021628'),
|
||||||
|
('20200410043002');
|
||||||
|
|
||||||
|
|
||||||
|
|
7
spec/primitives/contact_public_switch_spec.rb
Normal file
7
spec/primitives/contact_public_switch_spec.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe ContactPublicSwitch, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe 'POST /settings/contacts/:contact_id/public_switch' do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Reference in a new issue