Add action Staffs::RelationStatusesController#show
This commit is contained in:
parent
17f8215d93
commit
434ba5b74e
6 changed files with 71 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Staffs::RelationStatusesController < ApplicationController
|
||||
before_action :set_relation_status, only: :show
|
||||
|
||||
# GET /staff/relation_statuses
|
||||
def index
|
||||
authorize [:staff, RelationStatus]
|
||||
|
@ -9,4 +11,15 @@ class Staffs::RelationStatusesController < ApplicationController
|
|||
policy_scope_class: Staff::RelationStatusPolicy::Scope,
|
||||
).page(params[:page])
|
||||
end
|
||||
|
||||
# GET /staff/relation_statuses/:codename
|
||||
def show
|
||||
authorize [:staff, @relation_status]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_relation_status
|
||||
@relation_status = RelationStatus.find_by! codename: params[:codename]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,6 +7,12 @@ class Staff::RelationStatusPolicy < ApplicationPolicy
|
|||
account&.superuser?
|
||||
end
|
||||
|
||||
def show?
|
||||
return false if restricted?
|
||||
|
||||
account&.superuser?
|
||||
end
|
||||
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
return scope.none if restricted?
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<th scope="col">
|
||||
<%= RelationStatus.human_attribute_name :name %>
|
||||
</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
|
@ -15,6 +16,11 @@
|
|||
<tr>
|
||||
<td scope="row"><%= relation_status.codename %></td>
|
||||
<td><%= relation_status.name %></td>
|
||||
<td>
|
||||
<% if policy([:staff, relation_status]).show? %>
|
||||
<%= open_action [:staff, relation_status] %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
15
app/views/staffs/relation_statuses/show.html.erb
Normal file
15
app/views/staffs/relation_statuses/show.html.erb
Normal file
|
@ -0,0 +1,15 @@
|
|||
<div class="container">
|
||||
<%= nav_breadcrumb(
|
||||
[translate(:staff_services), staff_root_path],
|
||||
[RelationStatus.model_name.human(count: 0), staff_relation_statuses_path],
|
||||
RelationStatus.model_name.human(count: 1),
|
||||
) %>
|
||||
|
||||
<dl>
|
||||
<dt><%= RelationStatus.human_attribute_name :codename %></dt>
|
||||
<dd><%= @relation_status.codename %></dd>
|
||||
|
||||
<dt><%= RelationStatus.human_attribute_name :name %></dt>
|
||||
<dd><%= @relation_status.name %></dd>
|
||||
</dl>
|
||||
</div>
|
|
@ -59,7 +59,7 @@ Rails.application.routes.draw do
|
|||
|
||||
resources :contact_networks, only: :index
|
||||
|
||||
resources :relation_statuses, only: :index
|
||||
resources :relation_statuses, param: :codename, only: %i[index show]
|
||||
|
||||
resources :accounts, param: :nickname, only: %i[index show]
|
||||
|
||||
|
|
30
spec/requests/staff/relation_statuses/show_spec.rb
Normal file
30
spec/requests/staff/relation_statuses/show_spec.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'GET /staff/relation_statuses/:codename' do
|
||||
let(:current_account) { create :usual_account }
|
||||
|
||||
let!(:some_relation_status) { create :some_relation_status }
|
||||
|
||||
def make_request
|
||||
get "/staff/relation_statuses/#{some_relation_status.codename}"
|
||||
end
|
||||
|
||||
before do
|
||||
sign_in current_account.user if current_account&.user
|
||||
make_request
|
||||
end
|
||||
|
||||
for_account_types nil, :usual do
|
||||
specify do
|
||||
expect(response).to have_http_status :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
for_account_types :superuser do
|
||||
specify do
|
||||
expect(response).to have_http_status :ok
|
||||
end
|
||||
end
|
||||
end
|
Reference in a new issue