diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 27731cc..2c30573 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,10 +17,10 @@ On your local machine, add a remote that points to the original DMPRoadmap codebase. This will allow you to pull down the latest changes and sync up your forked repository -Run the following from your local clone of the repository to setup a remote that will allow you to pull down the latest changes from DMPRoadmap. Then pull down the contributions branch: +Run the following from your local clone of the repository to setup a remote that will allow you to pull down the latest changes from DMPRoadmap. Then pull down the development branch: ```bash git remote add upstream https://github.com/DMPRoadmap/roadmap.git -git fetch contributions +git fetch development ``` ### Pulling down the latest changes from DMPRoadmap into your fork @@ -31,12 +31,12 @@ ### Create a new feature/bug fix/translations branch -You should always base your new branch off of the contributions branch. We keep this branch up to date with the latest release. Checkout the contributions branch, sync it with DMPRoadmap and then push the latest up to your own fork: +You should always base your new branch off of the development branch. We keep this branch up to date with the latest release. Checkout the development branch, sync it with DMPRoadmap and then push the latest up to your own fork: ```bash -git checkout contributions -git pull upstream contributions -git push origin contributions +git checkout development +git pull upstream development +git push origin development git checkout -b [my-branch] ``` @@ -50,7 +50,7 @@ When you are finished making changes, we ask that all contributors squash their commits into a single git commit. This helps us keep the git history clean and makes it easier to revert any changes if necessary. -_Note that if this is your first time rebasing a branch we recommend making a buckup of the branch first since a rebase creates the potential for you to lose your changes if its done incorrectly: `git checkout -b [feature branch]-bak && git checkout [feature branch]`_ +_Note that if this is your first time rebasing a branch we recommend making a backup of the branch first since a rebase creates the potential for you to lose your changes if its done incorrectly: `git checkout -b [feature branch]-bak && git checkout [feature branch]`_ To rebase your feature branch you should follow this example: @@ -130,7 +130,7 @@ Once your changes are complete, push your branch up to your fork, `git push origin [my-branch]` -Then login to Github and go to your fork. Select your branch from the list and click 'New Pull Request'. On the page that opens, select the 'contributions' branch on the DMPRoadmap section. +Then login to Github and go to your fork. Select your branch from the list and click 'New Pull Request'. On the page that opens, select the 'development' branch on the DMPRoadmap section. Then review your code and provide us with detailed comments about what the changes are doing (e.g. adding a new feature, fixing a recorded bug, etc.). If you are working off of one of our Github issues, then please note that in the PR message with a `Fixes #1234`. @@ -142,11 +142,11 @@ ### Acceptence of your PR -Once your code has been approved a member of the core development team will merge it into the contributions branch and then into development when we are ready to include it in a sprint. +Once your code has been approved a member of the core development team will merge it into the development branchand include it in an upcoming release. At this point its a good idea to delete the branch from your fork in Github and also delete it from your local machine via: ```bash -git checkout contributions +git checkout development git branch -D [my-branch] ``` diff --git a/app/controllers/concerns/paginable.rb b/app/controllers/concerns/paginable.rb index 0c58199..ef6fcc9 100644 --- a/app/controllers/concerns/paginable.rb +++ b/app/controllers/concerns/paginable.rb @@ -96,7 +96,7 @@ if @paginable_params[:sort_field] == sort_field className = upcasing_sort_direction == 'ASC'? 'fa-sort-asc' : 'fa-sort-desc' end - return raw("") + return raw("Sort by #{sort_field.split('.').first}") end # Returns the sort url for a given sort_field. def sort_link_url(sort_field) diff --git a/app/controllers/org_admin/questions_controller.rb b/app/controllers/org_admin/questions_controller.rb index 555b105..69d008b 100644 --- a/app/controllers/org_admin/questions_controller.rb +++ b/app/controllers/org_admin/questions_controller.rb @@ -1,7 +1,7 @@ module OrgAdmin class QuestionsController < ApplicationController include Versionable - + respond_to :html after_action :verify_authorized @@ -9,32 +9,32 @@ def show question = Question.includes(:annotations, :question_options, section: { phase: :template }).find(params[:id]) authorize question - render partial: 'show', locals: { - template: question.section.phase.template, + render partial: 'show', locals: { + template: question.section.phase.template, section: question.section, - question: question + question: question } end - + # GET /org_admin/templates/[:template_id]/phases/[:phase_id]/sections/[:section_id]/question/[:id]/edit def edit question = Question.includes(:annotations, :question_options, section: { phase: :template }).find(params[:id]) authorize question - render partial: 'edit', locals: { - template: question.section.phase.template, + render partial: 'edit', locals: { + template: question.section.phase.template, section: question.section, - question: question + question: question } end - + # GET /org_admin/templates/[:template_id]/phases/[:phase_id]/sections/[:section_id]/questions/new def new section = Section.includes(:questions, phase: :template).find(params[:section_id]) nbr = section.questions.maximum(:number) question = Question.new({ section_id: section.id, question_format: QuestionFormat.find_by(title: 'Text area'), number: nbr.present? ? nbr + 1 : 1 }) authorize question - render partial: 'form', locals: { - template: section.phase.template, + render partial: 'form', locals: { + template: section.phase.template, section: section, question: question, method: 'post', @@ -66,12 +66,15 @@ authorize question begin question = get_modifiable(question) - # Need to reattach the incoming annotation's and question_options to the + # Need to reattach the incoming annotation's and question_options to the # modifiable (versioned) question attrs = question_params attrs = transfer_associations(question) if question.id != params[:id] # If the user unchecked all of the themes set the association to an empty array - attrs[:theme_ids] = [] unless attrs[:theme_ids].present? + # add check for number present to ensure this is not just an annotation + if attrs[:theme_ids].blank? && attrs[:number].present? + attrs[:theme_ids] = [] + end if question.update!(attrs) flash[:notice] = success_message(_('question'), _('updated')) else @@ -83,14 +86,14 @@ end if question.section.phase.template.customization_of.present? redirect_to org_admin_template_phase_path({ - template_id: question.section.phase.template.id, - id: question.section.phase.id, + template_id: question.section.phase.template.id, + id: question.section.phase.id, section: question.section.id }) else redirect_to edit_org_admin_template_phase_path({ - template_id: question.section.phase.template.id, - id: question.section.phase.id, + template_id: question.section.phase.template.id, + id: question.section.phase.id, section: question.section.id }) end @@ -112,8 +115,8 @@ flash[:alert] = _('Unable to create a new version of this template.') end redirect_to edit_org_admin_template_phase_path({ - template_id: section.phase.template.id, - id: section.phase.id, + template_id: section.phase.template.id, + id: section.phase.id, section: section.id }) end @@ -122,23 +125,23 @@ def question_params params.require(:question).permit(:number, :text, :question_format_id, :option_comment_display, :default_value, question_options_attributes: [:id, :number, :text, :is_default, :_destroy], annotations_attributes: [:id, :text, :org_id, :org, :type], theme_ids: []) end - - # When a template gets versioned by changes to one of its questions we need to loop + + # When a template gets versioned by changes to one of its questions we need to loop # through the incoming params and ensure that the annotations and question_options # get attached to the new question def transfer_associations(question) attrs = question_params if attrs[:annotations_attributes].present? attrs[:annotations_attributes].each_key do |key| - old_annotation = question.annotations.select do |a| - a.org_id.to_s == attrs[:annotations_attributes][key][:org_id] && a.type.to_s == attrs[:annotations_attributes][key][:type] + old_annotation = question.annotations.select do |a| + a.org_id.to_s == attrs[:annotations_attributes][key][:org_id] && a.type.to_s == attrs[:annotations_attributes][key][:type] end attrs[:annotations_attributes][key][:id] = old_annotation.first.id unless old_annotation.empty? end end # TODO: This question_options id swap feel fragile. We cannot really match on any of the # data elements because the user may have changed them so we rely on its position - # within the array/query since they should be equivalent. + # within the array/query since they should be equivalent. if attrs[:question_options_attributes].present? attrs[:question_options_attributes].each_key do |key| attrs[:question_options_attributes][key][:id] = question.question_options[key.to_i].id.to_s if question.question_options[key.to_i].present? @@ -147,4 +150,4 @@ attrs end end -end \ No newline at end of file +end diff --git a/app/controllers/orgs_controller.rb b/app/controllers/orgs_controller.rb index 6376398..fc734e3 100644 --- a/app/controllers/orgs_controller.rb +++ b/app/controllers/orgs_controller.rb @@ -29,11 +29,11 @@ # Only allow super admins to change the org types and shib info if current_user.can_super_admin? # Handle Shibboleth identifiers if that is enabled - if Rails.application.config.shibboleth_use_filtered_discovery_service + if Rails.application.config.shibboleth_use_filtered_discovery_service && params[:shib_id].present? shib = IdentifierScheme.find_by(name: 'shibboleth') shib_settings = @org.org_identifiers.select{ |ids| ids.identifier_scheme == shib}.first - if params[:shib_id].present? || params[:shib_domain].present? + if !params[:shib_id].blank? shib_settings = OrgIdentifier.new(org: @org, identifier_scheme: shib) unless shib_settings.present? shib_settings.identifier = params[:shib_id] shib_settings.attrs = {domain: params[:shib_domain]} @@ -81,7 +81,7 @@ session['org_id'] = params[:org_name] scheme = IdentifierScheme.find_by(name: 'shibboleth') - shib_entity = OrgIdentifier.where(org_id: params[:org_name], identifier_scheme: scheme) + shib_entity = OrgIdentifier.where(org_id: params['shib-ds'][:org_id], identifier_scheme: scheme) if !shib_entity.empty? # Force SSL @@ -104,6 +104,6 @@ private def org_params params.require(:org).permit(:name, :abbreviation, :logo, :contact_email, :contact_name, :remove_logo, :org_type, - :feedback_enabled, :feedback_email_subject, :feedback_email_msg, :banner_text) + :feedback_enabled, :feedback_email_msg) end end diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 6cba2fb..a5deb9a 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -3,6 +3,8 @@ require 'pp' helper PaginableHelper helper SettingsTemplateHelper + include FeedbacksHelper + after_action :verify_authorized, except: [:overview] def index @@ -165,6 +167,7 @@ guidance_groups_ids = plan.guidance_groups.collect(&:id) guidance_groups = GuidanceGroup.where(published: true, id: guidance_groups_ids) + # Since the answers have been pre-fetched through plan (see Plan.load_for_phase) # we create a hash whose keys are question id and value is the answer associated answers = plan.answers.reduce({}){ |m, a| m[a.question_id] = a; m } @@ -354,18 +357,19 @@ end def request_feedback - plan = Plan.find(params[:id]) - authorize plan + @plan = Plan.find(params[:id]) + authorize @plan alert = _('Unable to submit your request for feedback at this time.') begin - if plan.request_feedback(current_user) - redirect_to share_plan_path(plan), notice: _('Your request for feedback has been submitted.') + if @plan.request_feedback(current_user) + redirect_to share_plan_path(@plan), + notice: _(request_feedback_flash_notice) else - redirect_to share_plan_path(plan), alert: alert + redirect_to share_plan_path(@plan), alert: alert end rescue Exception - redirect_to share_plan_path(plan), alert: alert + redirect_to share_plan_path(@plan), alert: alert end end @@ -451,4 +455,15 @@ end plan.delete(src_plan_key) end + + # Flash notice for successful feedback requests + # + # @return [String] + def request_feedback_flash_notice + # Use the generic feedback confirmation message unless the Org has + # specified one + text = current_user.org.feedback_email_msg || + feedback_confirmation_default_message + feedback_constant_to_text(text, current_user, @plan, current_user.org) + end end diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb index 3d69e9e..bd73760 100644 --- a/app/controllers/roles_controller.rb +++ b/app/controllers/roles_controller.rb @@ -7,7 +7,7 @@ registered = true @role = Role.new(role_params) authorize @role - + access_level = params[:role][:access_level].to_i @role.set_access_level(access_level) message = '' @@ -30,7 +30,8 @@ if @role.save if registered deliver_if(recipients: user, key: 'users.added_as_coowner') do |r| - UserMailer.sharing_notification(@role, r, current_user).deliver_now + UserMailer.sharing_notification(@role, r, inviter: current_user) + .deliver_now end end flash[:notice] = message @@ -73,7 +74,7 @@ end redirect_to controller: 'plans', action: 'share', id: @role.plan.id end - + # This function makes user's role on a plan inactive - i.e. "removes" this from their plans def deactivate role = Role.find(params[:id]) diff --git a/app/helpers/feedbacks_helper.rb b/app/helpers/feedbacks_helper.rb new file mode 100644 index 0000000..15fca1b --- /dev/null +++ b/app/helpers/feedbacks_helper.rb @@ -0,0 +1,18 @@ +module FeedbacksHelper + def feedback_confirmation_default_subject + _('%{application_name}: Your plan has been submitted for feedback') + end + + def feedback_confirmation_default_message + _('
Hello %{user_name}.
'\ + 'Your plan "%{plan_name}" has been submitted for feedback from an administrator at your organisation. '\ + 'If you have questions pertaining to this action, please contact us at %{organisation_email}.
') + end + + def feedback_constant_to_text(text, user, plan, org) + _("#{text}") % {application_name: Rails.configuration.branding[:application][:name], + user_name: user.name, + plan_name: plan.title, + organisation_email: org.contact_email} + end +end diff --git a/app/helpers/mailer_helper.rb b/app/helpers/mailer_helper.rb index a7ee2df..d837693 100644 --- a/app/helpers/mailer_helper.rb +++ b/app/helpers/mailer_helper.rb @@ -1,21 +1,5 @@ module MailerHelper include PermsHelper - def feedback_confirmation_default_subject - _('%{application_name}: Your plan has been submitted for feedback') - end - - def feedback_confirmation_default_message - _('Hello %{user_name}.
'\ - 'Your plan "%{plan_name}" has been submitted for feedback from an administrator at your organisation. '\ - 'If you have questions pertaining to this action, please contact us at %{organisation_email}.
') - end - - def feedback_constant_to_text(text, user, plan, org) - _("#{text}") % {application_name: Rails.configuration.branding[:application][:name], - user_name: user.name, - plan_name: plan.title, - organisation_email: org.contact_email} - end # Returns an unordered HTML list with the permissions associated to the user passed def privileges_list(user) @@ -23,7 +7,7 @@ names = name_and_text r= "| <%= _('Plan') %> | -<%= _('Requestor') %> | -<%= _('Type') %> | -<%= _('Actions') %> | +<%= _('Plan') %> | +<%= _('Requestor') %> | +<%= _('Type') %> | +<%= _('Actions') %> | <% @feedback_plans.each do |notice| %> diff --git a/app/views/branded/plans/_edit_details.html.erb b/app/views/branded/plans/_edit_details.html.erb index 5673d7b..1e29743 100644 --- a/app/views/branded/plans/_edit_details.html.erb +++ b/app/views/branded/plans/_edit_details.html.erb @@ -5,12 +5,12 @@
|---|