diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 9e7a7d5..4519ea4 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -2,14 +2,18 @@ require 'pp' helper SettingsTemplateHelper - after_action :verify_authorized + after_action :verify_authorized, except: ['public_index', 'public_export'] def index authorize Plan @plans = current_user.plans end - + # GET /plans/public_index + # ------------------------------------------------------------------------------------ + def public_index + @plans = Plan.publicly_visible + end # GET /plans/new # ------------------------------------------------------------------------------------ @@ -235,96 +239,6 @@ end end - -# TODO: Remove these endpoints now that we're no longer using them -=begin - def section_answers - @plan = Plan.find(params[:id]) - authorize @plan - respond_to do |format| - format.json { render json: @plan.section_answers(params[:section_id]) } - end - end - - def locked - @plan = Plan.find(params[:id]) - authorize @plan - if !@plan.nil? && user_signed_in? && @plan.readable_by(current_user.id) then - respond_to do |format| - format.json { render json: @plan.locked(params[:section_id],current_user.id) } - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - def delete_recent_locks - @plan = Plan.find(params[:id]) - authorize @plan - if user_signed_in? && @plan.editable_by(current_user.id) then - respond_to do |format| - if @plan.delete_recent_locks(current_user.id) - format.html { render action: "edit" } - else - format.html { render action: "edit" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - def unlock_all_sections - @plan = Plan.find(params[:id]) - authorize @plan - if user_signed_in? && @plan.editable_by(current_user.id) then - respond_to do |format| - if @plan.unlock_all_sections(current_user.id) - format.html { render action: "edit" } - else - format.html { render action: "edit" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - def lock_section - @plan = Plan.find(params[:id]) - authorize @plan - if user_signed_in? && @plan.editable_by(current_user.id) then - respond_to do |format| - if @plan.lock_section(params[:section_id], current_user.id) - format.html { render action: "edit" } - else - format.html { render action: "edit" } - format.json { render json: @plan.errors, status: :unprocessable_entity } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end - - def unlock_section - @plan = Plan.find(params[:id]) - authorize @plan - if user_signed_in? && @plan.editable_by(current_user.id) then - respond_to do |format| - if @plan.unlock_section(params[:section_id], current_user.id) - format.html { render action: "edit" } - - else - format.html { render action: "edit" } - end - end - else - render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false) - end - end -=end - def answer @plan = Plan.find(params[:id]) authorize @plan @@ -393,6 +307,52 @@ end end + # GET /plans/[:plan_slug]/public_export + # ------------------------------------------------------------- + def public_export + @plan = Plan.find(params[:id]) + + # If the plan has multiple phases we should export each + @plan.phases.each do |phase| + @exported_plan = ExportedPlan.new.tap do |ep| + ep.plan = @plan + ep.phase_id = phase.id + ep.format = :pdf + plan_settings = @plan.settings(:export) + + Settings::Template::DEFAULT_SETTINGS.each do |key, value| + ep.settings(:export).send("#{key}=", plan_settings.send(key)) + end + end + + begin + @exported_plan.save! + # If the template has multiple phases then append the phase title to the filename + if @plan.phases.count > 1 + file_name = "#{@plan.title.gsub(/ /, "_")}-#{phase.title}" + else + file_name = @plan.title.gsub(/ /, "_") + end + + respond_to do |format| + format.pdf do + @formatting = @plan.settings(:export).formatting + render pdf: file_name, + margin: @formatting[:margin], + footer: { + center: _('This document was generated by %{application_name}') % {application_name: Rails.configuration.branding[:application][:name]}, + font_size: 8, + spacing: (@formatting[:margin][:bottom] / 2) - 4, + right: '[page] of [topage]' + } + end + end + rescue ActiveRecord::RecordInvalid => e + redirect_to show_export_plan_path(@plan), notice: _('Unable to download the DMP at this time.') + end + end + end + def duplicate plan = Plan.find(params[:id]) authorize plan diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 78ecb7c..540d199 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -2,6 +2,7 @@ class RegistrationsController < Devise::RegistrationsController def edit + @user.create_default_preferences @languages = Language.all.order("name") @orgs = Org.where(parent_id: nil).order("name") @other_organisations = Org.where(parent_id: nil, is_other: true).pluck(:id) diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index 6f38009..d111b3f 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -15,59 +15,4 @@ def roadmap end - - def public_plans - @plans = Plan.publicly_visible - end - - # GET /plans/[:plan_slug]/public_export - # ------------------------------------------------------------- - def public_export - redirect_to public_plans_path, notice: _('Exporting public plan is under development. Apologies for any inconvience.') - #@plan = Plan.find(params[:id]) - - # Force PDF response - #request.format = :pdf - - # if the project is designated as public - #if @plan.visibility == :publicly_visible - # if !@plan.nil? - # @exported_plan = ExportedPlan.new.tap do |ep| - # ep.plan = @plan - # ep.user = current_user ||= nil - # #ep.format = request.format.try(:symbol) - # ep.format = request.format.to_sym - # plan_settings = @plan.settings(:export) - - # Settings::Dmptemplate::DEFAULT_SETTINGS.each do |key, value| - # ep.settings(:export).send("#{key}=", plan_settings.send(key)) - # end - # end - - # @exported_plan.save! # FIXME: handle invalid request types without erroring? - # file_name = @exported_plan.project_name - - # respond_to do |format| - # format.pdf do - # @formatting = @plan.settings(:export).formatting - # render pdf: file_name, - # margin: @formatting[:margin], - # footer: { - # center: t('helpers.plan.export.pdf.generated_by'), - # font_size: 8, - # spacing: (@formatting[:margin][:bottom] / 2) - 4, - # right: '[page] of [topage]' - # } - # end - # end - - # else - # the project has no plans for some reason - # redirect_to public_plans_path, notice: _('The plan is incomplete.') - # end - #else - # Otherwise redirect to the home page with an unauthorized message - # redirect_to public_plans_path, notice: _('This account does not have access to that plan.') - #end - end end \ No newline at end of file diff --git a/app/models/user.rb b/app/models/user.rb index 9103a5e..08ed05b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -283,8 +283,10 @@ ## # User Notification Preferences def create_default_preferences - # Set the default preferences if this is a new user - self.prefs = self.class.create_default_preferences if self.id.nil? + # Set the default preferences for a new user or if existing user if null + if self.id.nil? || self.prefs == {} + self.prefs = self.class.create_default_preferences + end end def self.create_default_preferences diff --git a/app/views/devise/registrations/edit.html.erb b/app/views/devise/registrations/edit.html.erb index 8762484..8cb10ea 100644 --- a/app/views/devise/registrations/edit.html.erb +++ b/app/views/devise/registrations/edit.html.erb @@ -34,7 +34,6 @@ -
diff --git a/app/views/layouts/_navigation.html.erb b/app/views/layouts/_navigation.html.erb index c980f4f..75d285a 100644 --- a/app/views/layouts/_navigation.html.erb +++ b/app/views/layouts/_navigation.html.erb @@ -36,6 +36,10 @@ <%= link_to _('Home'), root_path %> <% end %> + +
  • > + <%= link_to _('Public DMPs'), public_plans_path %> +
  • > <%= link_to _('About'), about_us_path %> @@ -48,22 +52,25 @@
  • > <%= link_to _('Help'), help_path %>
  • - <% if MANY_LANGUAGES %> - - - <% end %> + + <% if !user_signed_in? %> + <% if MANY_LANGUAGES %> + + + <% end %> + <% end %> <% end %>
    diff --git a/app/views/plans/index.html.erb b/app/views/plans/index.html.erb index 9d77329..b40d24f 100644 --- a/app/views/plans/index.html.erb +++ b/app/views/plans/index.html.erb @@ -3,76 +3,93 @@ <% javascript "plans/index.js" %>

    - <%= _('My plans') %> + <%= _('My plans') %>

    <% if @plans.count > 0 %> -

    - <%= raw _('

    The table below lists the plans that you have created, and any that have been shared with you by others.
    These can be edited, shared, exported or deleted at anytime.

    ')%> -

    +

    + <%= raw _('

    The table below lists the plans that you have created, and any that have been shared with you by others.
    These can be edited, shared, exported or deleted at anytime.

    ')%> +

    - <%= render(partial: "toolbar") %> - - - - - - - - - - - + <%= render(partial: "toolbar") %> +
    <%= _('Plan') %><%= _('Template') %><%= _('Edited') %><%= _('Role') %><%= _('Visibility') %><%= _('Test') %><%= _('Select an Action') %>
    + + + + + + + + + + + + <% @plans.each do |plan| %> - - - - - - - - + + + + + + + - + <% if plan.owned_by?(current_user.id) then %> + <%= link_to _('Delete'), + plan_path(plan), + class: "dmp_table_link", + method: :delete, + data: {confirm: _('Are you sure you wish to delete this plan? If the plan is being shared with other users, by deleting it from your list, the plan will be deleted from their plan list as well')} %> + + <% end %> + <% else %> + <%= link_to _('View'), + plan_path(plan), + class: "dmp_table_link" %> + + <%= link_to _('Export'), + show_export_plan_path(plan), + class: "dmp_table_link" %> + <% end %> + + <% end %> - -
    <%= _('Plan') %><%= _('Template') %><%= _('Edited') %><%= _('Role') %><%= _('Visibility') %><%= _('Test') %><%= _('Select an Action') %>
    <%= plan.title %><%= plan.template.title %><%= l(plan.latest_update.to_date, formats: :short) %><%= display_role(plan.roles.find_by(user: current_user)) %><%= display_visibility(plan.visibility) %> - <%= plan.administerable_by?(current_user.id) ? '' : 'disabled="true"' %> /> - - <% if plan.editable_by?(current_user.id) then %> - <%= link_to _('Edit'), plan_path(plan), :class => "dmp_table_link"%> +
    <%= plan.title %><%= plan.template.title %><%= l(plan.latest_update.to_date, formats: :short) %><%= display_role(plan.roles.find_by(user: current_user)) %><%= display_visibility(plan.visibility) %> + <%= plan.administerable_by?(current_user.id) ? '' : 'disabled="true"' %> /> + + <% if plan.editable_by?(current_user.id) then %> + <%= link_to _('Edit'), + plan_path(plan), + class: "dmp_table_link" %> - <% if plan.administerable_by?(current_user.id) then %> - <%= link_to _('Share'), share_plan_path(plan), :class => "dmp_table_link"%> - <% end %> + <% if plan.administerable_by?(current_user.id) then %> + <%= link_to _('Share'), + share_plan_path(plan), + class: "dmp_table_link" %> + <% end %> - <%= link_to _('Export'), show_export_plan_path(plan), :class => "dmp_table_link"%> + <%= link_to _('Export'), + show_export_plan_path(plan), + class: "dmp_table_link" %> - <%= link_to _('Duplicate'), duplicate_plan_path(plan), method: :post, remote: true, :class => "dmp_table_link"%> + <%= link_to _('Duplicate'), + duplicate_plan_path(plan), + class: "dmp_table_link" %> - <% if plan.owned_by?(current_user.id) then %> - <%= link_to _('Delete'), plan_path(plan), :class => "dmp_table_link", - :method => :delete, :data => { - :confirm => _('Are you sure you wish to delete this plan? If the plan is being shared with other users, by deleting it from your list, the plan will be deleted from their plan list as well') - }%> - <% end %> - <% else %> - <%= link_to _('View'), plan_path(plan), :class => "dmp_table_link"%> - <%= link_to _('Export'), show_export_plan_path(plan), :class => "dmp_table_link"%> - <% end %> -
    - + + + <% else %> -

    - <%= raw _("

    Welcome.
    You are now ready to create your first DMP.
    Click the 'Create plan' button below to begin.

    ")%> -

    +

    + <%= raw _("

    Welcome.
    You are now ready to create your first DMP.
    Click the 'Create plan' button below to begin.

    ")%> +

    <% end %>

    - <%= link_to _('Create plan'), + <%= link_to _('Create plan'), new_plan_path, class: "btn btn-primary" %> diff --git a/app/views/plans/public_export.pdf.erb b/app/views/plans/public_export.pdf.erb new file mode 100644 index 0000000..b9ab084 --- /dev/null +++ b/app/views/plans/public_export.pdf.erb @@ -0,0 +1,68 @@ + + + + + + <%= @plan.title %> + + + + +

    <%= @plan.title %>

    + <% @exported_plan.admin_details.each do |field| + value = @exported_plan.send(field) + if value.present? %> +

    <%= admin_field_t(field.to_s) -%> <%= value -%>

    + <% else %> +

    <%= admin_field_t(field.to_s) -%> <%= _('-') %>

    + <% end %> + <% end %> + + <% @exported_plan.sections.each do |section| %> + <% questions = @exported_plan.questions_for_section(section.id) + if questions.present? + %> +

    <%= section.title %>

    + <% questions.each do |question| %> +
    +

    <%= raw question.text %>

    + <% answer = @plan.answer(question.id, false) %> + <% if answer.nil? then %> +

    <%= _('Question not answered.') -%>

    + <% else %> + <% q_format = question.question_format %> + <% if q_format.option_based? %> + + + <% if question.option_comment_display == true then%> + <% if !answer.text.nil? then %> + <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> + <%end%> + <%end%> + <%else%> + + <% if !answer.text.nil? then %> + <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> + <%end%> + <% end %> + <% end %> +
    + <% end %> + <% end %> + <% end %> + + \ No newline at end of file diff --git a/app/views/plans/public_index.html.erb b/app/views/plans/public_index.html.erb new file mode 100644 index 0000000..895f0b9 --- /dev/null +++ b/app/views/plans/public_index.html.erb @@ -0,0 +1,45 @@ +<%- model_class = Plan -%> +<% javascript "toolbar.js" %> + +

    + <%= raw _('Public DMPs') %> +

    + + +<% if @plans.count > 0 %> +

    + <%= _('Public DMPs are plans created using the %{application_name} and shared publicly by their owners. They are not vetted for quality, completeness, or adherence to funder guidelines.') % {application_name: Rails.application.config.branding[:application][:name]} %> +

    + + <%= render(partial: "toolbar") %> + + + + + + + + + + + + <% @plans.each do |plan| %> + + + + + + + + <% end %> + +
    <%= _('Plan') %><%= _('Template') %><%= _('Organisation') %><%= _('Owner') %><%= _('Download') %>
    <%= plan.title %><%= plan.template.title %><%= plan.owner.org.nil? ? _('Not Applicable') : plan.owner.org.name %><%= plan.owner.name %> + <%= link_to _('PDF'), + public_export_path(plan, format: :pdf), + class: "dmp_table_link" %> +
    +<% else %> +

    + <%= _("There are currently no public DMPs.")%> +

    +<% end %> diff --git a/app/views/static_pages/public_export.html.erb b/app/views/static_pages/public_export.html.erb deleted file mode 100644 index 37f1a18..0000000 --- a/app/views/static_pages/public_export.html.erb +++ /dev/null @@ -1,41 +0,0 @@ -<%- model_class = Project -%> - - -<%= render :partial => "/projects/project_title", locals: {project: @project} %> - - -<%= render :partial => "project_nav_tabs", locals: {project: @project, active: "export_page"} %> - - -
    - - <%= raw t('helpers.project.export_text_html')%> - - - <% if @project.plans.any? %> - <% if @project.plans.count == 1 then %> - <% @project.plans.each do |plan| %> - <%= render :partial => "/shared/export_links", locals: {plan: plan} %> - <% end %> - <%else%> - <% @project.plans.each do |plan| %> -
    -
    - -
    -
    - <%= render :partial => "/shared/export_links", locals: {plan: plan} %> -
    -
    -
    -
    - <%end%> - <%end%> - <%end%> - -
    \ No newline at end of file diff --git a/app/views/static_pages/public_export.pdf.erb b/app/views/static_pages/public_export.pdf.erb deleted file mode 100644 index 77d68cb..0000000 --- a/app/views/static_pages/public_export.pdf.erb +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - <% if @plan.project.dmptemplate.phases.count > 1 then %> - <%= "#{@plan.project.title} - #{@plan.title}" %> - <% else %> - <%= @plan.project.title %> - <% end %> - - - - -

    <%= @plan.title %>

    - <% @exported_plan.admin_details.each do |field| - value = @exported_plan.send(field) - if value.present? - %> -

    <%= t("helpers.plan.export.#{field}") -%> <%= value -%>

    - <% end %> - <% end %> - - <% @exported_plan.sections.each do |section| %> -

    <%= section.title %>

    - <% questions = @exported_plan.questions_for_section(section.id) %> - <% questions.each_with_index do |question, idx| %> -
    - <% unless idx == 0 && question.text == section.title %> -

    <%= raw question.text %>

    - <% end %> - <% answer = @plan.answer(question.id, false) %> - <% if answer.nil? then %> -

    <%= t('helpers.plan.export.pdf.question_not_answered') -%>

    - <% else %> - <% q_format = question.question_format%> - - <% if q_format.title == t("helpers.checkbox") || q_format.title == t("helpers.multi_select_box") || - q_format.title == t("helpers.radio_buttons") || q_format.title == t("helpers.dropdown") then%> - - - <% if question.option_comment_display == true then%> - <% if !answer.text.nil? then %> - <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> - <%end%> - <%end%> - <%else%> - - <% if !answer.text.nil? then %> - <%= raw answer.text.gsub(/(\s||<\/td>| )*(<\/tr>|)/,"") %> - <%end%> - <% end %> - <% end %> -
    - <% end %> - <% end %> - - \ No newline at end of file diff --git a/app/views/static_pages/public_plans.html.erb b/app/views/static_pages/public_plans.html.erb deleted file mode 100644 index 6a14750..0000000 --- a/app/views/static_pages/public_plans.html.erb +++ /dev/null @@ -1,39 +0,0 @@ -<%- model_class = Plan -%> -

    - <%= raw _('Public DMPs') %> -

    - - -<% if @plans.count > 0 %> -

    - <%= _('Public DMPs are plans created using the DMPTool and shared publicly by their owners. They are not vetted for quality, completeness, or adherence to funder guidelines.') %> -

    - - - - - - - - - - - - - <% @plans.each do |plan| %> - - <% ['non_link_name', 'template', 'organisation', 'owner'].each do |column| %> - <%= plan_list_column_body(column, plan) %> - <% end %> - - - - - <% end %> - -
    <%= _('Name') %><%= _('Template') %><%= _('Organization') %><%= _('Owner') %>
    -<% else %> -

    - <%= _("There are no public DMPs.")%> -

    -<% end %> diff --git a/config/routes.rb b/config/routes.rb index c2e9f61..1cd4960 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -78,8 +78,8 @@ get "help" => 'static_pages#help' get "roadmap" => 'static_pages#roadmap' get "terms" => 'static_pages#termsuse' - get "public_plans" => 'static_pages#public_plans' - get "public_export/:id" => 'static_pages#public_export', as: 'public_export' + get "public_plans" => 'plans#public_index' + get "public_export/:id" => 'plans#public_export', as: 'public_export' get "existing_users" => 'existing_users#index' #post 'contact_form' => 'contacts', as: 'localized_contact_creation' diff --git a/lib/assets/javascripts/toolbar.js b/lib/assets/javascripts/toolbar.js index 219084d..6ffa33f 100644 --- a/lib/assets/javascripts/toolbar.js +++ b/lib/assets/javascripts/toolbar.js @@ -1,76 +1,6 @@ $(document).ready(function() { - - var toolbar = $('.dmp_toolbar').first(), - form = null; - - $('#toolbar_configure').click(function(e) { - e.preventDefault(); - - if (form) { - form.toggle(); - } else { - $.get('/settings/projects.json') - .done(buildSettingsForm) - .fail(function(data) { - // Handle failure? - }); - } - }); - - // FIXME: it would be simpler just to return the partial from - // Settings::ProjectsController#show, but that would perhaps - // mean responding to a JSON request with HTML. - function buildSettingsForm(data) { - if (!form) - form = $('
    '); - - var table = $('
    ').appendTo(form), - thead = $('').appendTo(table), - tbody = $('').appendTo(table), - tfoot = $('').appendTo(table), - cols = data.all_columns, - selected = []; - - // grab the keys from the data.selected_columns hash - $.each(data.selected_columns, function(k,v){ - selected.push(k); - }); - - table.before(''); // PUT not POST - table.before(''); // Auth token - table.after('

    ' + __('The items you select here will be displayed in the table below. You can sort the data by each of these headings or filter by entering a text string in the search box.') + '

    '); - - // Default name column - table.before(''); - thead.append(''); - tbody.append('') - - for (var i = 0, len = cols.length; i < len; i++) { - var title = cols[i].replace(/^\w|_/g, function(c) { return c === '_' ? ' ' : c.toUpperCase(); }), - label = $('').appendTo(thead), - container = $('').appendTo(tbody), - input = $('').appendTo(container); - - if (selected.indexOf(cols[i]) > -1) - input.attr('checked', 'checked'); - } - - thead.append(''); - tbody.append('') - - var submit = $('').appendTo(tfoot); - cancel = $('' + __('Cancel') + '').appendTo(tfoot); - - cancel.click(function(e) { - e.preventDefault(); - form.toggle(); - }); - - toolbar.before(form); - } - /* - 'My plans' filtering + 'Plans' filtering */ var no_matches_message = $('' + __('No matches') + '').appendTo($('#dmp_table tbody')), rows = $('#dmp_table tbody tr'), diff --git a/lib/assets/stylesheets/roadmap-form.scss b/lib/assets/stylesheets/roadmap-form.scss index 9f717a7..e457bda 100644 --- a/lib/assets/stylesheets/roadmap-form.scss +++ b/lib/assets/stylesheets/roadmap-form.scss @@ -146,7 +146,7 @@ color: $reverse-text; padding: 4px 12px; font-size: 14px; - margin-top: 15px; + margin: 5px 10px; -webkit-border-radius: 5px; -moz-border-radius: 5px; diff --git a/lib/assets/stylesheets/roadmap-tabs.scss b/lib/assets/stylesheets/roadmap-tabs.scss index 99cbab2..0b386fd 100644 --- a/lib/assets/stylesheets/roadmap-tabs.scss +++ b/lib/assets/stylesheets/roadmap-tabs.scss @@ -47,11 +47,11 @@ } .tabbed-area div.tab-panel { padding: 10px 10px; - min-height: 300px; + min-height: 400px; position: absolute; top: -1px; left: 0; - width: inherit; + width: 100%; border: 1px solid $primary-color; border-top-left-radius: 0; border-top-right-radius: 5px; diff --git a/lib/assets/stylesheets/roadmap.scss b/lib/assets/stylesheets/roadmap.scss index daad890..be91597 100644 --- a/lib/assets/stylesheets/roadmap.scss +++ b/lib/assets/stylesheets/roadmap.scss @@ -59,7 +59,7 @@ div.header_left { width: auto; - + .home_logo { margin: 0 10px 0 0; } @@ -103,25 +103,25 @@ div.roadmap-info-box { position: absolute; - float: right; + float: right; top: 180px; right: 12%; background-color: $white; padding: 8px 20px; border-radius: 5px; - vertical-align: middle; - - span { - padding-left: 30px; - } - .fa { - position: absolute; - top: 10px; - background: transparent; - color: $black; - font-size: 16pt; - margin-right: 15px; - } + vertical-align: middle; + + span { + padding-left: 30px; + } + .fa { + position: absolute; + top: 10px; + background: transparent; + color: $black; + font-size: 16pt; + margin-right: 15px; + } } table.dmp_table{ @@ -132,26 +132,30 @@ margin-bottom: 20px; table-layout: fixed; - thead th, tbody td { - padding: 6px 15px 6px 6px; - overflow: hidden; - } + thead th, tbody td { + padding: 6px 15px 6px 6px; + overflow: hidden; + } - .col-tiny { - width: 5%; - } - .col-small { - width: 10%; - } - .col-medium { - width: 20%; - } - th.col-large { - width: 35%; - } + .col-tiny { + width: 5%; + } + .col-small { + width: 10%; + } + .col-medium { + width: 20%; + } + th.col-large { + width: 35%; + } + + a.dmp_table_link i { + font-size: 14pt; + margin-right: 5px; + } } - .checkbox-label { display: inline-block; font-size: 1em; diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 2a1947a..a0718b3 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -4,8 +4,8 @@ def setup scaffold_plan - - @user = User.create(email: 'me@example.edu', + + @user = User.create(email: 'me@example.edu', password: 'password', password_confirmation: 'password', firstname: 'Test', @@ -25,7 +25,7 @@ assert_not User.new(firstname: 'test', surname: 'user').valid? assert_not User.new(firstname: 'test', surname: 'user', password: 'password').valid? assert_not User.new(firstname: 'test', surname: 'user', email: 'me@example.org').valid? - + # Ensure the bar minimum and complete versions are valid a = User.new(email: 'me_testing@example.edu', password: 'password') assert a.valid?, "expected 'email' and 'password' to be enough to create a User - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" @@ -43,7 +43,7 @@ assert_not User.new(email: 'me@example.org', password: 'pass12').valid? assert_not User.new(email: 'me@example.org', password: 'Pass12').valid? assert_not User.new(email: 'me@example.org', password: 'Pass12*').valid? - + assert User.new(email: 'me@example.org', password: 'Password12*').valid? assert User.new(email: 'me@example.org', password: 'passwords').valid? assert User.new(email: 'me@example.org', password: 'Password').valid? @@ -51,13 +51,13 @@ # --------------------------------------------------- test "name returns the correct value" do - # Name should return 'First Last' if we do not specify email + # Name should return 'First Last' if we do not specify email assert @user.name(false).include?(@user.firstname), "expected the first name to be included when specifying non-email" assert @user.name(false).include?(@user.surname), "expected the last name to be included when specifying non-email" - + # Should return email if we do not pass in a variable assert_equal @user.email, @user.name, "expected the email by default" - + # Name should return the email if no first and last are present @user.firstname = nil @user.surname = nil @@ -67,69 +67,69 @@ # --------------------------------------------------- test "only accepts valid email addresses" do assert @user.valid? - + @user.email = 'testing' assert_not @user.valid? @user.email = 'testing.tester.org' assert_not @user.valid? @user.email = 'testing@tester' assert_not @user.valid? - + @user.email = 'testing@tester.org' assert @user.valid? end - + # --------------------------------------------------- test "api token is removed after call to remove_token" do @user.api_token = 'ABCDEFGHIJKLMNOP' @user.save! assert_equal 'ABCDEFGHIJKLMNOP', @user.reload.api_token, "expected the api_token to have been initialized" - + @user.remove_token! assert_equal '', @user.reload.api_token, "expected the api_token to have been removed" end - + # --------------------------------------------------- test "api token gets kept or created" do @user.api_token = 'ABCDEFGHIJKLMNOP' @user.save! assert_equal 'ABCDEFGHIJKLMNOP', @user.reload.api_token, "expected the api_token to have been initialized" - + @user.keep_or_generate_token! assert_equal 'ABCDEFGHIJKLMNOP', @user.reload.api_token, "expected the api_token to have been kept" @user.remove_token! assert_equal '', @user.reload.api_token, "expected the api_token to have been removed" - + @user.keep_or_generate_token! assert_not_equal '', @user.reload.api_token, "expected the api_token to have been generated" end - + # --------------------------------------------------- test "responds to all of the authentication options" do super_admins = User.joins(:perms).where('perms.name = ?', 'add_organisations').to_a org_admins = User.joins(:perms).where('perms.name = ?', 'modify_templates').to_a users = User.includes(:perms).where(perms: {id: nil}).to_a - + # remove all of the users who also have super_admin privileges org_admins = org_admins.delete_if{|u| super_admins.include?(u) } admin_methods = [:can_add_orgs?, :can_change_org?, :can_grant_api_to_orgs?] - - org_admin_methods = [:can_grant_permissions?, :can_modify_templates?, + + org_admin_methods = [:can_grant_permissions?, :can_modify_templates?, :can_modify_guidance?, :can_use_api?, :can_modify_org_details?] - + [:can_super_admin?, :can_org_admin?].each do |auth| assert_respond_to super_admins.first, auth, "expected User to respond to #{auth}" end - + # Super Admin - permission checks admin_methods.each do |auth| #assert super_admins.first.send(auth), "expected that Super Admin #{auth}" assert_not org_admins.first.send(auth), "did NOT expect that Organisation Admin #{auth}" assert_not @user.send(auth), "did NOT expect that User #{auth}" end - + # Organisational Admin - permission checks org_admin_methods.each do |auth| #assert super_admins.first.send(auth), "expected that the Super Admin #{auth}" @@ -137,29 +137,29 @@ assert_not @user.send(auth), "did NOT expect that User #{auth}" end end - + # --------------------------------------------------- test "can only have one identifier per IdentifierScheme" do @scheme = IdentifierScheme.first - + count = @user.user_identifiers.count @user.user_identifiers << UserIdentifier.new(identifier_scheme: @scheme, identifier: 'abc') @user.save! @user.reload - + assert_equal (count + 1), @user.user_identifiers.count, "Expected the initial identifier to be saved" - + @user.user_identifiers << UserIdentifier.new(identifier_scheme: @scheme, identifier: 'abc') assert_not @user.valid?, "Expected to NOT be able to add more than one identifier for the same scheme" assert_equal (count + 1), @user.user_identifiers.count, "Expected the initial identifier to be saved" end - + # --------------------------------------------------- test "can find a user via an OAuth response" do scheme = IdentifierScheme.create!(name: 'tester', active: true) @user.user_identifiers << UserIdentifier.new(identifier_scheme: scheme, identifier: '12345') @user.save! - + class Auth def provider "tester" @@ -168,9 +168,9 @@ "12345" end end - + assert_equal @user, User.from_omniauth(Auth.new) - + class UnknownAuth def provider "unknown" @@ -179,12 +179,12 @@ "12345" end end - + assert_raise "'Unknown OAuth provider: unknown" do User.from_omniauth(UnknownAuth.new) end end - + # --------------------------------------------------- test "Plans query filter is working properly" do 3.times do |i| @@ -196,28 +196,28 @@ plan = @user.plans.filter("2").first assert_equal "My test 2", plan.title, "Expected the plans filter to search the title" end - + # --------------------------------------------------- test "Returns the appropriate identifier for the specified scheme" do 3.times do |i| scheme = IdentifierScheme.create!({name: "test-#{i}", active: true}) - + @user.user_identifiers << UserIdentifier.new(identifier_scheme: scheme, identifier: i.to_s) end @user.save! - + 3.times do |i| scheme = IdentifierScheme.find_by(name: "test-#{i}") - + assert_equal i.to_s, @user.identifier_for(scheme).identifier, "expected the identifier for #{scheme.name} to be '#{i.to_s}'" end end - + # --------------------------------------------------- test "can_super_admin is properly set" do perms = Perm.where('name IN (?)', ['add_organisations', 'change_org_affiliation', 'grant_api_to_orgs']) user = User.create!(email: 'tester@example.edu', password: 'password') - + assert_not user.can_super_admin?, "expected a user with no permissions to NOT be a super_admin" perms.each do |p| @@ -225,23 +225,23 @@ user.perms.delete(last) unless last.nil? user.perms << p user.save! - + assert user.can_super_admin?, "expected the addition of the #{p.name} perm to enable the user to become a super_admin" end - + user.perms = [] user.save! - + user.perms = perms user.save! assert user.can_super_admin?, "expected the addition of all the super_admin perms to allow the user to be a super_admin" end - + # --------------------------------------------------- test "can_org_admin is properly set" do perms = Perm.where('name IN (?)', ['grant_permissions', 'modify_templates', 'modify_guidance', 'change_org_details']) user = User.create!(email: 'tester@example.edu', password: 'password') - + assert_not user.can_org_admin?, "expected a user with no permissions to NOT be a org_admin" perms.each do |p| @@ -249,18 +249,18 @@ user.perms.delete(last) unless last.nil? user.perms << p user.save! - + assert user.can_org_admin?, "expected the addition of the #{p.name} perm to enable the user to become a org_admin" end - + user.perms = [] user.save! - + user.perms = perms user.save! assert user.can_org_admin?, "expected the addition of all the super_admin perms to allow the user to be a org_admin" end - + # --------------------------------------------------- test "can CRUD" do usr = User.create(email: 'test@testing.org', password: 'testing1234') @@ -270,51 +270,51 @@ usr.save! usr.reload assert_equal 'Tester', usr.firstname, "Was expecting to be able to update the firstname of the User!" - + assert usr.destroy!, "Was unable to delete the User!" end - + # --------------------------------------------------- test "can manage has_many relationship with Perms" do perm = Perm.new(name: 'Added through test') verify_has_many_relationship(@user, perm, @user.perms.count) end - + # --------------------------------------------------- test "can manage has_many relationship with UserIdentifiers" do id = UserIdentifier.new(identifier_scheme: IdentifierScheme.first, identifier: 'tester') verify_has_many_relationship(@user, id, @user.user_identifiers.count) end - + # --------------------------------------------------- test "can manage has_many relationship with Roles" do role = Role.new(plan: @plan, access: 1) verify_has_many_relationship(@user, role, @user.roles.count) - end - + end + # --------------------------------------------------- test "can manage has_many relationship with Answers" do - answer = Answer.new(plan: @plan, - question: @plan.template.phases.first.sections.first.questions.first, + answer = Answer.new(plan: @plan, + question: @plan.template.phases.first.sections.first.questions.first, text: 'Testing') verify_has_many_relationship(@user, answer, @user.answers.count) end - + # --------------------------------------------------- test "can manage has_many relationship with Notes" do - answer = Answer.create(plan: @plan, - question: @plan.template.phases.first.sections.first.questions.first, + answer = Answer.create(plan: @plan, + question: @plan.template.phases.first.sections.first.questions.first, text: 'Testing') note = Note.new(answer: answer, text: 'Testing') verify_has_many_relationship(@user, note, @user.notes.count) end - + # --------------------------------------------------- test "can manage has_many relationship with ExportedPlans" do plan = ExportedPlan.new(plan: @plan, format: ExportedPlan::VALID_FORMATS.last) verify_has_many_relationship(@user, plan, @user.exported_plans.count) end - + # --------------------------------------------------- test "can manage belongs_to relationship with Org" do org = Org.new(name: 'Tester', abbreviation: 'TST') @@ -327,4 +327,10 @@ verify_belongs_to_relationship(@user, language) end + # --------------------------------------------------- + test "can create default notification preferences when user is created" do + user = User.create(email: 'test@testing.org', password: 'testing1234') + user.save + assert_not_nil(user.prefs) + end end