-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add admin & API support for Organization Contacts.
- Loading branch information
Showing
23 changed files
with
267 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class Admin | ||
class OrganizationContactsController < ApplicationController | ||
before_action :authenticate_admin! | ||
layout 'admin' | ||
|
||
def edit | ||
@organization = Organization.find(params[:organization_id]) | ||
@contact = Contact.find(params[:id]) | ||
@admin_decorator = AdminDecorator.new(current_admin) | ||
|
||
unless @admin_decorator.allowed_to_access_organization?(@organization) | ||
redirect_to admin_dashboard_path, | ||
alert: "Sorry, you don't have access to that page." | ||
end | ||
end | ||
|
||
def update | ||
@contact = Contact.find(params[:id]) | ||
@organization = Organization.find(params[:organization_id]) | ||
|
||
if @contact.update(params[:contact]) | ||
flash[:notice] = 'Contact was successfully updated.' | ||
redirect_to [:admin, @organization, @contact] | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def new | ||
@admin_decorator = AdminDecorator.new(current_admin) | ||
@organization = Organization.find(params[:organization_id]) | ||
|
||
unless @admin_decorator.allowed_to_access_organization?(@organization) | ||
redirect_to admin_dashboard_path, | ||
alert: "Sorry, you don't have access to that page." | ||
end | ||
|
||
@contact = Contact.new | ||
end | ||
|
||
def create | ||
@organization = Organization.find(params[:organization_id]) | ||
@contact = @organization.contacts.new(params[:contact]) | ||
|
||
if @contact.save | ||
flash[:notice] = "Contact '#{@contact.name}' was successfully created." | ||
redirect_to admin_organization_path(@organization) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def destroy | ||
contact = Contact.find(params[:id]) | ||
contact.destroy | ||
redirect_to admin_organization_path(contact.organization), | ||
notice: "Contact '#{contact.name}' was successfully deleted." | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class LocationsOrganizationSerializer < ActiveModel::Serializer | ||
attributes :id, :accreditations, :alternate_name, :date_incorporated, | ||
:description, :email, :funding_sources, :licenses, :name, :slug, | ||
:website, :url, :locations_url | ||
|
||
def url | ||
api_organization_url(object) | ||
end | ||
|
||
def locations_url | ||
api_org_locations_url(object) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class SummarizedOrganizationSerializer < ActiveModel::Serializer | ||
attributes :id, :alternate_name, :name, :slug, :url | ||
|
||
def url | ||
api_organization_url(object) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
= render 'admin/contacts/forms/fields', f: f | ||
|
||
.save-box.navbar-default | ||
%p | ||
= 'Creating contact for' | ||
%strong | ||
= "#{@organization.name}" | ||
= f.submit 'Create contact', class: 'btn btn-success', data: { disable_with: 'Please wait...' } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.content-box | ||
%h2= "#{@contact.try(:name)} / #{@organization.name}" | ||
= form_for [:admin, @organization, @contact], html: { class: 'edit_entry' } do |f| | ||
= render 'admin/contacts/form', f: f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.content-box | ||
%h1 Create a new contact | ||
|
||
= form_for [:admin, @organization, @contact], html: { method: :post, class: 'edit_entry' } do |f| | ||
= render 'admin/contacts/forms/new_org_contact', f: f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require 'rails_helper' | ||
|
||
feature 'Delete contact' do | ||
background do | ||
@location = create(:location) | ||
@location.contacts.create!(attributes_for(:contact)) | ||
login_super_admin | ||
visit '/admin/locations/vrs-services' | ||
click_link 'Moncef Belyamani' | ||
end | ||
|
||
scenario 'when deleting contact' do | ||
find_link('Permanently delete this contact').click | ||
using_wait_time 1 do | ||
expect(current_path).to eq admin_location_path(@location) | ||
expect(page).not_to have_link 'Moncef Belyamani' | ||
end | ||
end | ||
end |
Oops, something went wrong.