Commit 6e8d75f1 authored by Chrysanthi Lagodimou's avatar Chrysanthi Lagodimou
Browse files

policies

parent c5cc0b40
......@@ -40,7 +40,7 @@ class ApplicationPolicy
end
def volunteer_related?
record.volunteer.user_id == user.id
volunteer? && record.volunteer.user_id == user.id
end
def superadmin_or_record_owner?
......@@ -60,7 +60,7 @@ class ApplicationPolicy
end
def superadmin_or_volunteer_related?
superadmin? || volunteer? && volunteer_related?
superadmin? || volunteer_related?
end
alias_method :index?, :deny_all!
......
......@@ -7,9 +7,9 @@ class HourPolicy < ApplicationPolicy
alias_method :index?, :superadmin?
alias_method :show?, :superadmin_or_volunteer_related?
alias_method :new?, :superadmin_or_volunteer_related?
alias_method :edit?, :superadmin_or_volunteer_related?
alias_method :create?, :superadmin_or_volunteer_related?
alias_method :update?, :superadmin_or_volunteer_related?
alias_method :destroy?, :superadmin?
alias_method :new?, :volunteer_related?
alias_method :edit?, :volunteer_related?
alias_method :create?, :volunteer_related?
alias_method :update?, :volunteer_related?
alias_method :destroy?, :volunteer_related?
end
td= link_to t_action(:show), subject
- unless controller_name == 'hours'
td= link_to t_action(:print), { controller: controller_name, action: :show, id: subject.id, print: 'true' }, target: '_blank'
td= link_to t_action(:print), { controller: controller_name, action: :show, id: subject.id, print: 'true' }, target: '_blank'
- if ['clients', 'volunteers'].include? controller_name
td= link_to t_model(Journal), { controller: 'journals', action: 'index', "#{controller_name.singularize}_id": subject.id }
- if policy(subject.class).index?
......
......@@ -3,7 +3,8 @@
table.table.table-striped
thead
tr
th= t_model(Volunteer)
- if policy(Hour).index?
th= t_model(Volunteer)
th= t_model(Client)
th= t_attr(:meeting_date, Hour)
th= t_attr(:duration, Hour)
......@@ -13,3 +14,6 @@
tbody
= render hours
- if current_user.volunteer?
= button_link t_title(:new, Hour), new_hour_url(volunteer_id: current_user.volunteer.id)
......@@ -3,5 +3,3 @@
h1= t_title
= render 'hours_block', hours: @hours
= form_navigation_btn :new
......@@ -3,9 +3,10 @@
.table-responsive
table.table.table-no-border-top
tbody
tr
td= t_model(Volunteer)
td= @hour.assignment.volunteer.contact.full_name
- if policy(Hour).index?
tr
td= t_model(Volunteer)
td= @hour.assignment.volunteer.contact.full_name
tr
td= t_model(Client)
td= @hour.assignment.client.contact.full_name
......@@ -22,8 +23,8 @@
td= t_attr(:comments)
td= @hour.comments
= form_navigation_btn :edit
- if policy(Hour).index?
= form_navigation_btn :back
- else
= form_navigation_btn :edit
= button_link t_action(:back), volunteer_hours_volunteer_path(@hour.volunteer)
......@@ -5,6 +5,7 @@ nav.navbar.section-navigation
li= button_link t_title(:new), new_volunteer_path, 'success', dimension: 'sm'
- if policy(Volunteer).destroy?
li= button_link t('seeking_clients'), seeking_clients_volunteers_url, dimension: 'sm'
li= button_link t_title(:index, Hour), hours_path, dimension: 'sm'
li |
li= button_link t_model(VolunteerEmail), volunteer_emails_path, dimension: 'sm'
......
......@@ -11,10 +11,10 @@
.col-xs-12.col-md-4
= button_link t_title(:new, Assignment), new_assignment_path(volunteer_id: @volunteer)
- if @volunteer.assignments.any?
.col-xs-12.col-md-4
= button_link t_title(:new, Hour), new_hour_url(volunteer_id: @volunteer)
.col-xs-12.col-md-4
= button_link t_title(:index, Hour), volunteer_hours_volunteer_path(@volunteer)
.col-xs-12.col-md-4
= button_link t_title(:new, Hour), new_hour_url(volunteer_id: @volunteer)
- if policy(Volunteer).checklist?
h3= t('checklist')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment