Add action Settings::Contacts::SecurityNotificationSwitches#create
This commit is contained in:
parent
ac78717d6b
commit
5c9a5f319c
7 changed files with 75 additions and 2 deletions
|
@ -0,0 +1,22 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Settings::Contacts::SecurityNotificationSwitchesController \
|
||||||
|
< ApplicationController
|
||||||
|
before_action :set_contact
|
||||||
|
|
||||||
|
# POST /settings/contacts/:contact_id/security_notification_switch
|
||||||
|
def create
|
||||||
|
authorize [:settings, ContactSecurityNotificationSwitch.new(@contact)]
|
||||||
|
|
||||||
|
@contact.send_security_notifications = !@contact.send_security_notifications
|
||||||
|
@contact.save!
|
||||||
|
|
||||||
|
redirect_to settings_contacts_url
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def set_contact
|
||||||
|
@contact = current_account&.contact_list&.contacts&.find params[:contact_id]
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class Settings::ContactSecurityNotificationSwitchPolicy < ApplicationPolicy
|
||||||
|
def create?
|
||||||
|
account &&
|
||||||
|
record.contact.contact_list.account == account &&
|
||||||
|
record.contact.contact_network_communicable?
|
||||||
|
end
|
||||||
|
end
|
9
app/primitives/contact_security_notification_switch.rb
Normal file
9
app/primitives/contact_security_notification_switch.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class ContactSecurityNotificationSwitch
|
||||||
|
attr_reader :contact
|
||||||
|
|
||||||
|
def initialize(contact)
|
||||||
|
@contact = contact or raise
|
||||||
|
end
|
||||||
|
end
|
|
@ -19,7 +19,19 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= contact.contact_network.name %></td>
|
<td><%= contact.contact_network.name %></td>
|
||||||
<td><%= truncate contact.value %></td>
|
<td><%= truncate contact.value %></td>
|
||||||
<td><%= bool_badge contact.send_security_notifications %></td>
|
<td>
|
||||||
|
<% if policy([
|
||||||
|
:settings,
|
||||||
|
ContactSecurityNotificationSwitch.new(contact),
|
||||||
|
]).create? %>
|
||||||
|
<%= link_to(
|
||||||
|
settings_contact_security_notification_switch_path(contact),
|
||||||
|
method: :post,
|
||||||
|
) do %>
|
||||||
|
<%= bool_badge contact.send_security_notifications %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% if policy([:settings, contact]).destroy? %>
|
<% if policy([:settings, contact]).destroy? %>
|
||||||
<%= link_to(
|
<%= link_to(
|
||||||
|
|
|
@ -34,8 +34,13 @@ Rails.application.routes.draw do
|
||||||
resource :profile, only: %i[edit update]
|
resource :profile, only: %i[edit update]
|
||||||
resource :appearance, only: %i[edit update]
|
resource :appearance, only: %i[edit update]
|
||||||
resource :person, only: %i[show new]
|
resource :person, only: %i[show new]
|
||||||
resources :contacts, only: %i[index create destroy]
|
|
||||||
resources :sessions, only: :index
|
resources :sessions, only: :index
|
||||||
|
|
||||||
|
resources :contacts, only: %i[index create destroy] do
|
||||||
|
resource :security_notification_switch,
|
||||||
|
controller: 'contacts/security_notification_switches',
|
||||||
|
only: :create
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Settings::ContactSecurityNotificationSwitchPolicy do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe(
|
||||||
|
'POST /settings/contacts/:contact_id/security_notification_switch',
|
||||||
|
) do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Reference in a new issue