diff --git a/app/controllers/guidances_controller.rb b/app/controllers/guidances_controller.rb index 8df36eb..cebd30d 100644 --- a/app/controllers/guidances_controller.rb +++ b/app/controllers/guidances_controller.rb @@ -1,11 +1,11 @@ class GuidancesController < ApplicationController after_action :verify_authorized - + # GET /guidances def admin_index authorize Guidance @guidances = policy_scope(Guidance) - @guidance_groups = GuidanceGroup.where('organisation_id = ?', current_user.organisation_id ) + @guidance_groups = GuidanceGroup.where('org_id = ?', current_user.org_id ) respond_to do |format| format.html # index.html.erb end @@ -23,7 +23,7 @@ def admin_new @guidance = Guidance.new authorize @guidance - @dmptemplates = Dmptemplate.funders_and_own_templates(current_user.organisation_id) + @dmptemplates = Dmptemplate.funders_and_own_templates(current_user.org_id) @phases = nil @dmptemplates.each do |template| if @phases.nil? then diff --git a/app/models/guidance.rb b/app/models/guidance.rb index 929690d..c5c6566 100644 --- a/app/models/guidance.rb +++ b/app/models/guidance.rb @@ -31,11 +31,9 @@ # # @param org_id [Integer] the integer id for an organisation # @return [Boolean] true if this guidance is in a group belonging to the specified organisation, false otherwise - def in_group_belonging_to?(organisation_id) - guidance_groups.each do |guidance_group| - if guidance_group.organisation_id == organisation_id - return true - end + def in_group_belonging_to?(org_id) + if guidance_group.org_id == org_id + return true end return false end @@ -48,7 +46,7 @@ def self.by_organisation(org_id) org_guidance = [] Org.find_by(id: org_id).guidance_groups.each do |group| - org_guidance += group.guidances + org_guidance += Guidance.where(guidance_group_id: group.id) end return org_guidance end @@ -87,9 +85,8 @@ guidance.guidance_groups.each do |guidance_group| # guidances are viewable if they are owned by any of the user's organisations - user.organisations.each do |organisation| - - if guidance_group.organisation.id == organisation.id + user.org do |org| + if guidance_group.org.id == org.id viewable = true end end diff --git a/app/policies/guidance_policy.rb b/app/policies/guidance_policy.rb index e527c4a..6fdab13 100644 --- a/app/policies/guidance_policy.rb +++ b/app/policies/guidance_policy.rb @@ -8,15 +8,15 @@ end def admin_show? - user.can_modify_guidance? && guidance.in_group_belonging_to?(user.organisation_id) + user.can_modify_guidance? && guidance.in_group_belonging_to?(user.org_id) end def admin_edit? - user.can_modify_guidance? && guidance.in_group_belonging_to?(user.organisation_id) + user.can_modify_guidance? && guidance.in_group_belonging_to?(user.org_id) end def admin_update? - user.can_modify_guidance? && guidance.in_group_belonging_to?(user.organisation_id) + user.can_modify_guidance? && guidance.in_group_belonging_to?(user.org_id) end def admin_index? @@ -32,7 +32,7 @@ end def admin_destroy? - user.can_modify_guidance? && guidance.in_group_belonging_to?(user.organisation_id) + user.can_modify_guidance? && guidance.in_group_belonging_to?(user.org_id) end def update_phases? @@ -53,7 +53,7 @@ class Scope < Scope def resolve - scope = Guidance.by_organisation(user.organisation_id) + scope = Guidance.by_organisation(user.org_id) end end end \ No newline at end of file diff --git a/app/views/guidances/admin_index.html.erb b/app/views/guidances/admin_index.html.erb index 76acaf2..49abb68 100644 --- a/app/views/guidances/admin_index.html.erb +++ b/app/views/guidances/admin_index.html.erb @@ -11,12 +11,12 @@
- <%= link_to t("org_admin.guidance_group.add_guidance_group"), admin_new_guidance_group_path(), :class => "btn btn-primary" %> + <%= link_to t("org_admin.guidance_group.add_guidance_group"), admin_new_guidance_group_path(), class: "btn btn-primary" %>
- + -<% if @guidance_groups.count > 0 then%> +<% if @guidance_groups.count > 0 then%> @@ -31,64 +31,43 @@ <% !@guidance_groups.each do |guidance_gr| %> - - <% guidance_group_temp = guidance_gr.dmptemplate_ids %> - <% if guidance_group_temp != [] then %> - - <%else%> - - <%end%> - - - - - - - - <%end%> + + + + + + + + <% end %>
- <%= guidance_gr.name %> - - <% i = 1 %> - <% guidance_group_temp.each do |t| %> - <% temp = Dmptemplate.find(t) %> - <%= temp.title %> - - <% if guidance_group_temp.count > i then%> - , - <% i +=1 %> - <% end %> - <%end%> - - <%= t("org_admin.guidance_group.all_temp")%> - - <%if guidance_gr.published.nil? || guidance_gr.published == false then%> - <%= t("helpers.no_label")%> - <%else%> - <%= t("helpers.yes_label")%> - <%end%> - - <%if guidance_gr.optional_subset.nil? || guidance_gr.optional_subset == false then%> - <%= t("helpers.no_label")%> - <%else%> - <%= t("helpers.yes_label")%> - <%end%> - - <%= l guidance_gr.updated_at.to_date, :formats => :short %> - - <%= link_to t("helpers.view"), admin_show_guidance_group_path(guidance_gr), :class => "dmp_table_link"%>
- <%= link_to t("helpers.submit.edit"), admin_edit_guidance_group_path(guidance_gr), :class => "dmp_table_link"%>
- <%= link_to t("helpers.submit.delete"), admin_destroy_guidance_group_path(guidance_gr), - :data => {:confirm => t("org_admin.guidance_group.delete_message", :guidance_group_name => guidance_gr.name )}, :method => :delete, :class => "dmp_table_link"%> -
+ <%= guidance_gr.name %> + + <% if guidance_gr.published.nil? || guidance_gr.published == false then%> + <%= t("helpers.no_label")%> + <% else %> + <%= t("helpers.yes_label")%> + <% end %> + + <% if guidance_gr.optional_subset.nil? || guidance_gr.optional_subset == false then%> + <%= t("helpers.no_label")%> + <% else %> + <%= t("helpers.yes_label")%> + <% end %> + + <%= l guidance_gr.updated_at.to_date, formats: :short %> + + <%= link_to t("helpers.view"), admin_show_guidance_group_path(guidance_gr), class: "dmp_table_link"%>
+ <%= link_to t("helpers.submit.edit"), admin_edit_guidance_group_path(guidance_gr), class: "dmp_table_link"%>
+ <%= link_to t("helpers.submit.delete"), admin_destroy_guidance_group_path(guidance_gr), data: {confirm: t("org_admin.guidance_group.delete_message", guidance_group_name: guidance_gr.name )}, method: :delete, class: "dmp_table_link"%> +
-<%end%> +<%end%>

- <%= t("org_admin.guidance.guidance_list") %> + <%= t("org_admin.guidance.guidance_list") %>

@@ -99,14 +78,14 @@
<%= link_to t("org_admin.guidance.add_guidance"), admin_new_guidance_path(), - :class => "btn btn-primary" %> + class: "btn btn-primary" %>
-<% if @guidances.count > 0 then%> +<% if @guidances.count > 0 then%> @@ -120,7 +99,7 @@ <% @guidances.each do |guidance| %> - <% if guidance.in_group_belonging_to?(current_user.organisation_id) then %> + <% if guidance.in_group_belonging_to?(current_user.org_id) then %> - <%else%> + <% else %> - <%end%> + <% end %> <% if !guidance.question_id.nil? then %> - <%else%> + <% else %> - <%end%> - <% if guidance.guidance_groups != [] then %> - - <%else%> + <% end %> + <% if guidance.guidance_group.present? then %> + + <% else %> - <%end%> + - + + <% end %> - <%end%> - <%end%> + <% end %> + <% end %>
<%= guidance.text.html_safe%> @@ -129,46 +108,46 @@ <% guidance.themes.each do |th| %> <%= th.title %> - <%end%> + <% end %> - <%= raw guidance.question.text.truncate(70, omission: t('helpers.truncate_continued')) %> - - <% guidance.guidance_groups.each do |p|%> - <%= p.name %> - <%end%> - + <% guidance.guidance_group do |p|%> + <%= p.name %> + <% end %> + - - - - <%= l guidance.updated_at.to_date, :formats => :short %> + <%= l guidance.updated_at.to_date, formats: :short %> - <%= link_to t("helpers.view"), admin_show_guidance_path(guidance), :class => "dmp_table_link"%>
- <%= link_to t("helpers.submit.edit"), admin_edit_guidance_path(guidance), :class => "dmp_table_link"%>
+ <%= link_to t("helpers.view"), admin_show_guidance_path(guidance), class: "dmp_table_link"%>
+ <%= link_to t("helpers.submit.edit"), admin_edit_guidance_path(guidance), class: "dmp_table_link"%>
<%= link_to t("helpers.submit.delete"), admin_destroy_guidance_path(guidance), - :data => {:confirm => t("org_admin.guidance.delete_message_html", :guidance_summary => truncate(sanitize(guidance.text,:tags => %w(br a)), :length => 20 , :omission => t('helpers.truncate_continued')) )}, :method => :delete, :class => "dmp_table_link"%> + data: {confirm: t("org_admin.guidance.delete_message_html", guidance_summary: truncate(sanitize(guidance.text,tags: %w(br a)), length: 20 , omission: t('helpers.truncate_continued')) )}, method: :delete, class: "dmp_table_link"%>
-<%end%> +<% end %>