diff --git a/app/helpers/plans_helper.rb b/app/helpers/plans_helper.rb index 8ac7e69..03c55c0 100644 --- a/app/helpers/plans_helper.rb +++ b/app/helpers/plans_helper.rb @@ -13,16 +13,6 @@ end end - # display the name of the owner of a plan - def display_owner(user) - if user == current_user - name = d_('dmpopidor', 'You') - else - name = user&.name(false) - end - return name - end - # display the visibility of the plan def display_visibility(val) case val @@ -31,8 +21,6 @@ when 'publicly_visible' return "#{_('Public')}" when 'privately_visible' - return "#{d_('dmpopidor', 'Administrator')}" - when 'privately_private_visible' return "#{_('Private')}" else return "#{_('Private')}" # Test Plans diff --git a/app/models/plan.rb b/app/models/plan.rb index 6f0d20f..6a19210 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -42,6 +42,7 @@ include ExportablePlan include ValidationMessages include ValidationValues + include Dmpopidor::Model::Plan # ============= # = Constants = diff --git a/app/views/plans/_share_form.html.erb b/app/views/plans/_share_form.html.erb index fed67a8..93edf04 100644 --- a/app/views/plans/_share_form.html.erb +++ b/app/views/plans/_share_form.html.erb @@ -3,15 +3,11 @@ <% commenter = Role.new(commenter: true) %>

<%= _('Set plan visibility') %>

-

<%= d_('dmpopidor', 'Public, Administrator or organisational visibility is intended for finished plans. You must answer at least %{percentage}%% of the questions to enable these options. Note: test plans are set to private visibility by default.') % { :percentage => Rails.application.config.default_plan_percentage_answered } %>

+

<%= _('Public or organisational visibility is intended for finished plans. You must answer at least %{percentage}%% of the questions to enable these options. Note: test plans are set to private visibility by default.') % { :percentage => Rails.application.config.default_plan_percentage_answered } %>

<% allow_visibility = @plan.visibility_allowed? %> <%= form_for(@plan, url: visibility_plan_path, method: :post, html: { id: 'set_visibility', remote: true }) do |f| %> -
> + >
-
- <%= f.label :visibility_privately_private_visible, raw("#{f.radio_button :visibility, :privately_private_visible}\ - #{d_('dmpopidor', 'Private: visible to me and specified collaborators')}") %> -
<%= f.label :visibility_privately_visible do %> <%= f.radio_button :visibility, :privately_visible %> diff --git a/lib/dmpopidor/controllers/plans.rb b/lib/dmpopidor/controllers/plans.rb index e733574..f14c39c 100644 --- a/lib/dmpopidor/controllers/plans.rb +++ b/lib/dmpopidor/controllers/plans.rb @@ -111,6 +111,25 @@ @export_settings = @plan.settings(:export) render "download" end + + # Removing test flag now put the plan in privately_private visibility + def set_test + plan = Plan.find(params[:id]) + authorize plan + plan.visibility = (params[:is_test] === "1" ? :is_test : :privately_private_visible) + # rubocop:disable Metrics/LineLength + if plan.save + render json: { + code: 1, + msg: (plan.is_test? ? _("Your project is now a test.") : _("Your project is no longer a test.")) + } + else + render status: :bad_request, json: { + code: 0, msg: _("Unable to change the plan's test status") + } + end + # rubocop:enable Metrics/LineLength + end end end end \ No newline at end of file diff --git a/lib/dmpopidor/helpers/plans.rb b/lib/dmpopidor/helpers/plans.rb new file mode 100644 index 0000000..804d61d --- /dev/null +++ b/lib/dmpopidor/helpers/plans.rb @@ -0,0 +1,48 @@ +module Dmpopidor + module Helper + module Plans + # display the name of the owner of a plan + # CHANGE : Added translation + def display_owner(user) + if user == current_user + name = d_('dmpopidor', 'You') + else + name = user&.name(false) + end + return name + end + + # display the visibility of the plan + # CHANGE : Added privately_private_visible visibility + def display_visibility(val) + case val + when 'organisationally_visible' + return "#{_('Organisation')}" + when 'publicly_visible' + return "#{_('Public')}" + when 'privately_visible' + return "#{d_('dmpopidor', 'Administrator')}" + when 'privately_private_visible' + return "#{_('Private')}" + else + return "#{_('Private')}" # Test Plans + end + end + + # CHANGE : Added privately_private_visible visibility + def visibility_tooltip(val) + case val + when 'organisationally_visible' + return _('Organisation: anyone at my organisation can view.') + when 'publicly_visible' + return _('Public: anyone can view.') + when 'privately_visible' + return d_('dmpopidor', 'Administrator: visible to me, specified collaborators and administrators at my organisation.') + else + return _('Private: restricted to me and people I invite.') + end + end + + end + end +end \ No newline at end of file diff --git a/lib/dmpopidor/models/plan.rb b/lib/dmpopidor/models/plan.rb new file mode 100644 index 0000000..23d2c6f --- /dev/null +++ b/lib/dmpopidor/models/plan.rb @@ -0,0 +1,22 @@ +module Dmpopidor + module Model + module Plan + # Deactivates the plan (sets all roles to inactive and visibility to :private) + # + # Returns Boolean + def deactivate! + # If no other :creator, :administrator or :editor is attached + # to the plan, then also deactivate all other active roles + # and set the plan's visibility to :private + # CHANGE : visibility setting to privately_private_visible + if authors.size == 0 + roles.where(active: true).update_all(active: false) + self.visibility = Plan.visibilities[:privately_private_visible] + save! + else + false + end + end + end + end +end \ No newline at end of file