1
0
Fork 0

Add attribute Contact#show_in_public

This commit is contained in:
Alex Kotov 2020-04-10 09:37:23 +05:00
parent 273ce969f9
commit 20b0f74862
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
11 changed files with 84 additions and 1 deletions

View File

@ -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

View File

@ -0,0 +1,8 @@
# frozen_string_literal: true
class Settings::ContactPublicSwitchPolicy < ApplicationPolicy
def create?
account &&
record.contact.contact_list.account == account
end
end

View File

@ -0,0 +1,9 @@
# frozen_string_literal: true
class ContactPublicSwitch
attr_reader :contact
def initialize(contact)
@contact = contact or raise
end
end

View File

@ -10,6 +10,9 @@
<th scope="col">
<%= Contact.human_attribute_name :send_security_notifications %>
</th>
<th scope="col">
<%= Contact.human_attribute_name :show_in_public %>
</th>
<th scope="col"></th>
</tr>
</thead>
@ -39,6 +42,19 @@
<% end %>
<% end %>
</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>
<% if policy([:settings, contact]).destroy? %>
<%= link_to(

View File

@ -77,6 +77,7 @@ en:
contact_network: Contact network
value: Value
send_security_notifications: Security notifications
show_in_public: Public
link: Link
contact_network:
id: ID

View File

@ -64,6 +64,7 @@ ru:
contact_network: Сеть контактов
value: Значение
send_security_notifications: Уведомления безопасности
show_in_public: Публичный
link: Ссылка
contact_network:
id: ID

View File

@ -40,6 +40,10 @@ Rails.application.routes.draw do
resource :security_notification_switch,
controller: 'contacts/security_notification_switches',
only: :create
resource :public_switch,
controller: 'contacts/public_switches',
only: :create
end
end

View File

@ -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

View File

@ -682,6 +682,7 @@ CREATE TABLE public.contacts (
contact_network_id bigint NOT NULL,
value character varying 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))
);
@ -1991,6 +1992,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20191021060000'),
('20191021061920'),
('20200408085219'),
('20200410021628');
('20200410021628'),
('20200410043002');

View 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

View File

@ -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