diff --git a/Gemfile.lock b/Gemfile.lock index a330277..2c2ea35 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,7 +100,7 @@ activesupport (>= 4.2.0) hashdiff (0.3.7) hashie (3.5.7) - htmltoword (0.7.0) + htmltoword (1.0.0) actionpack nokogiri rubyzip (>= 1.0) diff --git a/app/controllers/org_admin/phases_controller.rb b/app/controllers/org_admin/phases_controller.rb index 827f4f3..ed47690 100644 --- a/app/controllers/org_admin/phases_controller.rb +++ b/app/controllers/org_admin/phases_controller.rb @@ -26,12 +26,9 @@ def edit phase = Phase.includes(:template).find(params[:id]) authorize phase - if !phase.template.latest? - flash[:notice] = _('You are viewing a historical version of this template. You will not be able to make changes.') - end section = params.fetch(:section, nil) # User cannot edit a phase if its a customization so redirect to show - if phase.template.customization_of.present? + if phase.template.customization_of.present? || !phase.template.latest? redirect_to org_admin_template_phase_path(template_id: phase.template, id: phase.id, section: section) else render('container', diff --git a/app/controllers/org_admin/sections_controller.rb b/app/controllers/org_admin/sections_controller.rb index 27e1b14..38bfd62 100644 --- a/app/controllers/org_admin/sections_controller.rb +++ b/app/controllers/org_admin/sections_controller.rb @@ -36,7 +36,8 @@ def edit section = Section.includes({phase: :template}, questions: [:question_options, { annotations: :org }]).find(params[:id]) authorize section - render partial: 'edit', + # User cannot edit a section if its not modifiable or the template is not the latest redirect to show + render partial: (section.modifiable? && section.phase.template.latest? ? 'edit' : 'show'), locals: { template: section.phase.template, phase: section.phase, diff --git a/app/controllers/org_admin/templates_controller.rb b/app/controllers/org_admin/templates_controller.rb index bea37d6..826dcd1 100644 --- a/app/controllers/org_admin/templates_controller.rb +++ b/app/controllers/org_admin/templates_controller.rb @@ -96,13 +96,14 @@ order('phases.number', 'sections.number', 'questions.number', 'question_options.number'). select('phases.title', 'phases.description', 'sections.title', 'questions.text', 'question_options.text') if !template.latest? - flash[:notice] = _("You are viewing a historical version of this #{template_type(template)}. You will not be able to make changes.") + redirect_to org_admin_template_path(id: template.id) + else + render 'container', locals: { + partial_path: 'edit', + template: template, + phases: phases, + referrer: get_referrer(template, request.referrer) } end - render 'container', locals: { - partial_path: 'edit', - template: template, - phases: phases, - referrer: get_referrer(template, request.referrer) } end # GET /org_admin/templates/new diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c759af8..5482157 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -91,7 +91,7 @@ def update_email_preferences prefs = params[:prefs] - authorize current_user, :update? + authorize User pref = current_user.pref # does user not have prefs? if pref.blank? diff --git a/app/policies/user_policy.rb b/app/policies/user_policy.rb index e55a870..4a3bc31 100644 --- a/app/policies/user_policy.rb +++ b/app/policies/user_policy.rb @@ -1,43 +1,52 @@ class UserPolicy < ApplicationPolicy + attr_reader :signed_in_user attr_reader :user - def initialize(user, users) - raise Pundit::NotAuthorizedError, "must be logged in" unless user + def initialize(signed_in_user, user) + raise Pundit::NotAuthorizedError, "must be logged in" unless signed_in_user + @signed_in_user = signed_in_user @user = user - @users = users - end - - def admin_index? - @user.can_grant_permissions? end def index? admin_index? end + def admin_index? + signed_in_user.can_grant_permissions? + end + def admin_grant_permissions? - @user.can_grant_permissions? && ((@users.org_id == @user.org_id) || @user.can_super_admin?) + (signed_in_user.can_grant_permissions? && user.org_id == signed_in_user.org_id) || signed_in_user.can_super_admin? end def admin_update_permissions? - @user.can_grant_permissions? && ((@users.org_id == @user.org_id) || @user.can_super_admin?) + (signed_in_user.can_grant_permissions? && user.org_id == signed_in_user.org_id) || signed_in_user.can_super_admin? end # Allows the user to swap their org affiliation on the fly def org_swap? - user.can_super_admin? + signed_in_user.can_super_admin? end def activate? - user.can_super_admin? + signed_in_user.can_super_admin? end def edit? - user.can_super_admin? + signed_in_user.can_super_admin? end def update? - user.can_super_admin? + signed_in_user.can_super_admin? + end + + def update_email_preferences? + true + end + + def acknowledge_notification? + true end class Scope < Scope @@ -45,8 +54,4 @@ scope.where(org_id: user.org_id) end end - - def acknowledge_notification? - true - end end diff --git a/app/views/plans/_overview_details.html.erb b/app/views/plans/_overview_details.html.erb index 6949ebf..cd3fe05 100644 --- a/app/views/plans/_overview_details.html.erb +++ b/app/views/plans/_overview_details.html.erb @@ -20,6 +20,7 @@ <% else %>
<%= _("Last modified: ") + l(@plan.updated_at.to_date, formats: :short) %>
<%= _("Copyright information:") %>
-<%= _(" The above plan creator(s) have agreed that others may use as much of the text of this plan as they would like in their own plans, and customise it as necessary. You do not need to credit the creator(s) as the source of the language used, but using any of the plan's text does not imply that the creator(s) endorse, or have any relationship to, your project or proposal") %>
<%= _("Copyright information:") %>
+<%= _(" The above plan creator(s) have agreed that others may use as much of the text of this plan as they would like in their own plans, and customise it as necessary. You do not need to credit the creator(s) as the source of the language used, but using any of the plan's text does not imply that the creator(s) endorse, or have any relationship to, your project or proposal") %>