-
-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to create and update placement types
- Loading branch information
Showing
14 changed files
with
199 additions
and
1 deletion.
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,46 @@ | ||
class PlacementTypesController < ApplicationController | ||
before_action :set_placement_type, only: %i[edit update] | ||
|
||
def new | ||
authorize PlacementType | ||
@placement_type = PlacementType.new | ||
end | ||
|
||
def edit | ||
authorize @placement_type | ||
end | ||
|
||
def create | ||
authorize PlacementType | ||
@placement_type = PlacementType.new(placement_type_params) | ||
@placement_type.casa_org = current_organization | ||
respond_to do |format| | ||
if @placement_type.save | ||
format.html { redirect_to edit_casa_org_path(current_organization.id), notice: "Placement Type was successfully created." } | ||
else | ||
format.html { render :new, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
authorize @placement_type | ||
respond_to do |format| | ||
if @placement_type.update(placement_type_params) | ||
format.html { redirect_to edit_casa_org_path(current_organization.id), notice: "Placement Type was successfully updated." } | ||
else | ||
format.html { render :edit, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_placement_type | ||
@placement_type = PlacementType.find(params[:id]) | ||
end | ||
|
||
def placement_type_params | ||
params.require(:placement_type).permit(:name) | ||
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,6 @@ | ||
class PlacementTypePolicy < ApplicationPolicy | ||
alias_method :create?, :is_admin_same_org? | ||
alias_method :edit?, :is_admin_same_org? | ||
alias_method :new?, :is_admin_same_org? | ||
alias_method :update?, :is_admin_same_org? | ||
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,50 @@ | ||
<div class="row"> | ||
<div class="col-lg-12"> | ||
<div class="card-style mb-30"> | ||
<div class="row align-items-center"> | ||
<div class="col-md-6"> | ||
<h3>Placement Types</h3> | ||
</div> | ||
<div class="col-md-6"> | ||
<div class="breadcrumb-wrapper"> | ||
<span class="ml-5"> | ||
<%= link_to new_placement_type_path, class: "btn-sm main-btn primary-btn btn-hover" do %> | ||
<i class="lni lni-plus mr-10"></i> | ||
New Placement Type | ||
<% end %> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="table-wrapper table-responsive"> | ||
<table class="table striped-table"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @placement_types.each do |placement_type| %> | ||
<tr id="placement_types-<%= placement_type.id %>"> | ||
<td scope="row" class="min-width"> | ||
<%= placement_type.name %> | ||
</td> | ||
|
||
<td> | ||
<%= link_to edit_placement_type_path(placement_type) do %> | ||
<div class="action"> | ||
<button class="text-danger"> | ||
<i class="lni lni-pencil-alt"></i> Edit | ||
</button> | ||
</div> | ||
<% end %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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,30 @@ | ||
<div class="title-wrapper pt-30"> | ||
<div class="row align-items-center"> | ||
<div class="col-md-6"> | ||
<div class="title mb-30"> | ||
<h1> | ||
<%= title %> | ||
</h1> | ||
</div> | ||
</div> | ||
</div> | ||
</div><!-- ==== end title ==== --> | ||
|
||
<div class="card-style mb-30"> | ||
<%= form_with(model: placement_type, local: true) do |form| %> | ||
<div class="alert-box danger-alert"> | ||
<%= render "/shared/error_messages", resource: placement_type %> | ||
</div> | ||
|
||
<div class="input-style-1"> | ||
<%= form.label :name, "Name" %> | ||
<%= form.text_field :name, class: "form-control", required: true %> | ||
</div> | ||
|
||
<div class="actions mb-10"> | ||
<%= button_tag(type: "submit", class: "btn-sm main-btn primary-btn btn-hover") do %> | ||
<i class="lni lni-checkmark-circle mr-5"></i> Submit | ||
<% end %> | ||
</div> | ||
<% end %> | ||
</div> |
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 @@ | ||
<%= render partial: "form", locals: { title: "Edit Placement Type", placement_type: @placement_type } %> |
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 @@ | ||
<%= render partial: "form", locals: { title: "New Placement Type", placement_type: @placement_type } %> |
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,29 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe PlacementTypePolicy, type: :policy do | ||
subject { described_class } | ||
let(:placement_type) { build(:placement_type, casa_org: organization) } | ||
|
||
let(:organization) { build(:casa_org) } | ||
let(:casa_admin) { create(:casa_admin, casa_org: organization) } | ||
let(:other_org_admin) { create(:casa_admin) } | ||
let(:volunteer) { build(:volunteer, casa_org: organization) } | ||
let(:supervisor) { build(:supervisor, casa_org: organization) } | ||
|
||
permissions :create?, :edit?, :new?, :update? do | ||
it "allows same org casa_admins" do | ||
is_expected.to permit(casa_admin, placement_type) | ||
end | ||
|
||
it "allows does not allow different org casa_admins" do | ||
is_expected.to_not permit(other_org_admin, placement_type) | ||
end | ||
it "does not permit supervisor" do | ||
is_expected.to_not permit(supervisor, placement_type) | ||
end | ||
|
||
it "does not permit volunteer" do | ||
is_expected.to_not permit(volunteer, placement_type) | ||
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