diff --git a/app/models/plan.rb b/app/models/plan.rb index f66fe78..7cc6aa9 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -102,6 +102,8 @@ has_many :roles + belongs_to :feedback_requestor, class_name: "User", :foreign_key => 'feedback_requestor' + # RESEARCH OUTPUTS has_many :research_outputs, dependent: :destroy, inverse_of: :plan do # Returns the default research output @@ -321,6 +323,7 @@ # emails confirmation messages to owners # emails org admins and org contact # adds org admins to plan with the 'reviewer' Role + # SEE MODULE def request_feedback(user) Plan.transaction do begin @@ -347,6 +350,7 @@ # Finalizes the feedback for the plan: Emails confirmation messages to owners # sets flag on plans.feedback_requested to false removes org admins from the # 'reviewer' Role for the Plan. + # SEE MODULE def complete_feedback(org_admin) Plan.transaction do begin diff --git a/app/views/branded/org_admin/plans/index.html.erb b/app/views/branded/org_admin/plans/index.html.erb index 67cbcb2..a6bc431 100644 --- a/app/views/branded/org_admin/plans/index.html.erb +++ b/app/views/branded/org_admin/plans/index.html.erb @@ -16,7 +16,7 @@ <%= _('Plan') %> <%= d_('dmpopidor', 'Template') %> <%= _('Requestor') %> - <%= _('Type') %> + <%= d_('dmpopidor', 'Request Date') %> <%= _('Actions') %> @@ -26,8 +26,8 @@ <%= link_to notice.name, plan_path(notice) %> <%= notice.template.title %> - <%= notice.owner&.name(false) %> - <%= _('Feedback requested') %> + <%= notice.feedback_requestor&.name(false) %> + <%= l(notice.feedback_request_date.to_date, formats: :short) if notice.feedback_request_date %> <%= link_to _('Complete'), feedback_complete_org_admin_plan_path(notice), 'data-toggle': 'tooltip', title: _('Notify the plan owner that I have finished providing feedback') %> <% end %> diff --git a/config/locale/dmpopidor.pot b/config/locale/dmpopidor.pot index 88ab630..9eb2047 100644 --- a/config/locale/dmpopidor.pot +++ b/config/locale/dmpopidor.pot @@ -460,4 +460,5 @@ msgid "You are about to archive %{user_name}. This will remove their personal information. This user will be unable to use their DMP OPIDoR account and the plans they created or shared by their colleagues. Are you sure?" msgstr "" - +msgid "Request Date" +msgstr "" \ No newline at end of file diff --git a/config/locale/en_GB/dmpopidor.po b/config/locale/en_GB/dmpopidor.po index 2cae1ab..d470ee1 100644 --- a/config/locale/en_GB/dmpopidor.po +++ b/config/locale/en_GB/dmpopidor.po @@ -454,4 +454,7 @@ msgstr "PLEASE CHOOSE AN ORGANISATION IN YOUR PROFILE" msgid "You are about to archive %{user_name}. This will remove their personal information. This user will be unable to use their DMP OPIDoR account and the plans they created or shared by their colleagues. Are you sure?" -msgstr "You are about to archive %{user_name}. This will remove their personal information. This user will be unable to use their DMP OPIDoR account and the plans they created or shared by their colleagues. Are you sure?" \ No newline at end of file +msgstr "You are about to archive %{user_name}. This will remove their personal information. This user will be unable to use their DMP OPIDoR account and the plans they created or shared by their colleagues. Are you sure?" + +msgid "Request Date" +msgstr "Request Date" \ No newline at end of file diff --git a/config/locale/fr_FR/app.po b/config/locale/fr_FR/app.po index 53768e1..fb5ba0d 100644 --- a/config/locale/fr_FR/app.po +++ b/config/locale/fr_FR/app.po @@ -2529,7 +2529,7 @@ msgstr "Statistiques de vos modèles" msgid "No. plans created based off your templates" -msgstr "Nombre de plan créé à partir de vos modèles" +msgstr "Nbre de plans créés à partir de vos modèles" msgid "csv download field separator" msgstr "séparateur csv" diff --git a/config/locale/fr_FR/dmpopidor.po b/config/locale/fr_FR/dmpopidor.po index 58b04bc..cbe3e01 100644 --- a/config/locale/fr_FR/dmpopidor.po +++ b/config/locale/fr_FR/dmpopidor.po @@ -456,4 +456,7 @@ msgstr "MERCI DE CHOISIR UN ORGANISME DANS VOTRE PROFIL" msgid "You are about to archive %{user_name}. This will remove their personal information. This user will be unable to use their DMP OPIDoR account and the plans they created or shared by their colleagues. Are you sure?" -msgstr "Vous êtes sur le point d’archiver %{user_name}. Les informations personnelles de ce compte seront anonymisées. Par conséquent cet utilisateur ne pourra plus accéder à son compte DMP OPIDoR et aux plans qu’il aura créés, ni à ceux partagés avec lui par ses collègues. Etes-vous sûr ?" \ No newline at end of file +msgstr "Vous êtes sur le point d’archiver %{user_name}. Les informations personnelles de ce compte seront anonymisées. Par conséquent cet utilisateur ne pourra plus accéder à son compte DMP OPIDoR et aux plans qu’il aura créés, ni à ceux partagés avec lui par ses collègues. Etes-vous sûr ?" + +msgid "Request Date" +msgstr "Date de la demande" \ No newline at end of file diff --git a/db/migrate/20200515113700_add_columns_to_plans.rb b/db/migrate/20200515113700_add_columns_to_plans.rb new file mode 100644 index 0000000..b5af9f8 --- /dev/null +++ b/db/migrate/20200515113700_add_columns_to_plans.rb @@ -0,0 +1,6 @@ +class AddColumnsToPlans < ActiveRecord::Migration + def change + add_column :plans, :feedback_requestor, :integer + add_column :plans, :feedback_request_date, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 97a3431..7d85978 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20200128100507) do +ActiveRecord::Schema.define(version: 20200515113700) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -241,6 +241,8 @@ t.string "principal_investigator_phone" t.boolean "feedback_requested", default: false t.boolean "complete", default: false + t.integer "feedback_requestor" + t.datetime "feedback_request_date" end add_index "plans", ["template_id"], name: "plans_template_id_idx", using: :btree diff --git a/lib/dmpopidor/controllers/feedback_requests.rb b/lib/dmpopidor/controllers/feedback_requests.rb index 65fd410..d19a211 100644 --- a/lib/dmpopidor/controllers/feedback_requests.rb +++ b/lib/dmpopidor/controllers/feedback_requests.rb @@ -1,6 +1,8 @@ module Dmpopidor module Controllers module FeedbackRequests + ALERT = _("Unable to submit your request for feedback at this time.") + ERROR = _("An error occurred when requesting feedback for this plan.") # CHANGES : Changed feedback request message def create @plan = Plan.find(params[:plan_id]) @@ -12,7 +14,7 @@ redirect_to request_feedback_plan_path(@plan), alert: ALERT end rescue Exception - redirect_to request_feedback_plan_path(@plan), alert: ERROR + redirect_to request_feedback_plan_path(@plan), alert: ERROR end end end diff --git a/lib/dmpopidor/controllers/org_admin/plans.rb b/lib/dmpopidor/controllers/org_admin/plans.rb index 98f67ea..89de7af 100644 --- a/lib/dmpopidor/controllers/org_admin/plans.rb +++ b/lib/dmpopidor/controllers/org_admin/plans.rb @@ -5,14 +5,15 @@ # GET org_admin/plans # In the Org Admin page, Private and Test plans won't be displayed + # CHANGES : Feedbacks plans are plans where the requestor belongs to the current_user's org def index unless current_user.present? && current_user.can_org_admin? raise Pundit::NotAuthorizedError end feedback_ids = Role.joins(:user,:plan) - .where('users.org_id = ? AND plans.feedback_requested is TRUE AND roles.active is TRUE', - current_user.org_id).pluck(:plan_id) + .where('plans.feedback_requestor IN (?) AND plans.feedback_requested is TRUE AND roles.active is TRUE', + current_user.org.users.pluck(:id).uniq).pluck(:plan_id) @feedback_plans = Plan.where(id: feedback_ids).reject{|p| p.nil?} @plans = current_user.org.plans.where.not(visibility: [Plan.visibilities[:privately_visible], Plan.visibilities[:is_test]]).page(1) end diff --git a/lib/dmpopidor/models/plan.rb b/lib/dmpopidor/models/plan.rb index 4efc511..7d83c0c 100644 --- a/lib/dmpopidor/models/plan.rb +++ b/lib/dmpopidor/models/plan.rb @@ -60,6 +60,67 @@ reviewer.can_review_plans? end + ## + # Sets up the plan for feedback: + # emails confirmation messages to owners + # emails org admins and org contact + # adds org admins to plan with the 'reviewer' Role + # CHANGES : Added feedback_requestor & request_date columns + def request_feedback(user) + ::Plan.transaction do + begin + self.feedback_requested = true + self.feedback_requestor = user + self.feedback_request_date = DateTime.current() + if save! + # Send an email to the org-admin contact + if user.org.contact_email.present? + contact = ::User.new(email: user.org.contact_email, + firstname: user.org.contact_name) + UserMailer.feedback_notification(contact, self, user).deliver_now + end + return true + else + return false + end + rescue Exception => e + Rails.logger.error e + return false + end + end + end + + ## + # Finalizes the feedback for the plan: Emails confirmation messages to owners + # sets flag on plans.feedback_requested to false removes org admins from the + # 'reviewer' Role for the Plan. + # CHANGES : Added feedback_requestor & request_date columns + def complete_feedback(org_admin) + ::Plan.transaction do + begin + self.feedback_requested = false + self.feedback_requestor = nil + self.feedback_request_date = nil + if save! + # Send an email confirmation to the owners and co-owners + deliver_if(recipients: owner_and_coowners, + key: "users.feedback_provided") do |r| + UserMailer.feedback_complete( + r, + self, + org_admin).deliver_now + end + true + else + false + end + rescue ArgumentError => e + Rails.logger.error e + false + end + end + end + # The number of research outputs for a plan. # # Returns Integer