diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2acb8c3..0d54c3e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -39,9 +39,6 @@ @show_form = true end - @visibilities = Visibility.all - @default_visibility = @visibilities.select{ |v| v.default }.first - if user_signed_in? && @project.readable_by(current_user.id) then respond_to do |format| format.html # show.html.erb @@ -143,7 +140,7 @@ if user_signed_in? then attrs = project_params - + @project = Project.new(attrs) authorize @project @@ -187,8 +184,6 @@ if user_signed_in? && @project.editable_by(current_user.id) then attrs = project_params - attrs[:visibility] = Visibility.find(attrs[:visibility]) unless attrs[:visibility].nil? - if @project.update_attributes(attrs) respond_to do |format| format.html { redirect_to({:action => "show", :id => @project.slug, notice: I18n.t('helpers.project.success_update') }) } diff --git a/app/controllers/static_pages_controller.rb b/app/controllers/static_pages_controller.rb index c55f473..e9d109a 100644 --- a/app/controllers/static_pages_controller.rb +++ b/app/controllers/static_pages_controller.rb @@ -18,8 +18,7 @@ # GET /projects/publicly_available # ----------------------------------------------------------- def public_plans - public_visibility = Visibility.find_by(name: 'public') - @projects = Project.where(visibility: public_visibility).order(title: :asc) + @projects = Project.publicly_visible.order(title: :asc) end # GET /projects/[:project_slug]/public_export @@ -31,7 +30,7 @@ request.format = :pdf # if the project is designated as public - if @project.visibility == Visibility.find_by(name: 'public') + if @project.visibility == :publicly_visible @plan = @project.plans.first if !@plan.nil? diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 88848b8..84c458d 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -45,7 +45,7 @@ text = shared_num > 0 ? (t("helpers.yes_label") + " (with #{shared_num} people) ") : t("helpers.no_label") [ "dmp_td_small", text ] when 'visibility' - ["dmp_td_small", (project.is_public? ? t("helpers.project.public_visibility") : (project.is_test? ? t("helpers.project.test_visibility") : t("helpers.project.default_visibility")))] + ["dmp_td_small", (project.visibility.nil? ? I18n.t("helpers.project.visibilities.labels.organisationally_visible") : I18n.t("helpers.project.visibilities.labels.#{project.visibility}"))] when 'last_edited' [ "dmp_td_small", l(project.latest_update.to_date, formats: :short) ] when 'description' diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index f2707f3..8cc149f 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -11,7 +11,7 @@ VALID_FORMATS = ['csv', 'html', 'json', 'pdf', 'text', 'xml', 'docx'] validates :format, inclusion: { in: VALID_FORMATS, message: I18n.t('helpers.plan.export.not_valid_format') } - validates :plan, :user, :format, presence: true + validates :plan, :format, presence: true # Store settings with the exported plan so it can be recreated later # if necessary (otherwise the settings associated with the plan at a diff --git a/app/models/project.rb b/app/models/project.rb index 81dff56..6af3276 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,6 +1,5 @@ class Project < ActiveRecord::Base include GlobalHelpers - include FlagShihTzu extend FriendlyId @@ -13,11 +12,9 @@ has_and_belongs_to_many :guidance_groups, join_table: "project_guidance" friendly_id :title, use: [:slugged, :history, :finders] - - has_flags 1 => :organisational_visibility, - 2 => :public_visibility, - 3 => :private_visibility, - column: 'visibility' + + # public is a Ruby keyword so using publicly + enum visibility: [:organisationally_visible, :publicly_visible, :is_test, :privately_visible] ## # returns the title of the project diff --git a/app/models/user.rb b/app/models/user.rb index cfba711..bc8da32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,7 +5,7 @@ # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :invitable, :database_authenticatable, :registerable, :recoverable, - :rememberable, :trackable, :validatable, :confirmable, :exported_plans, + :rememberable, :trackable, :validatable, :confirmable, :omniauthable, omniauth_providers: [:orcid] #associations between tables @@ -51,7 +51,7 @@ :firstname, :last_login,:login_count, :orcid_id, :password, :shibboleth_id, :user_status_id, :surname, :user_type_id, :organisation_id, :skip_invitation, :other_organisation, :accept_terms, :role_ids, :dmponline3, :api_token, - :organisation, :language, :language_id + :organisation, :language, :language_id, :exported_plans validates :email, email: true, allow_nil: true, uniqueness: true diff --git a/app/views/projects/_project_details.html.erb b/app/views/projects/_project_details.html.erb index 8c77cd5..d9db9a1 100644 --- a/app/views/projects/_project_details.html.erb +++ b/app/views/projects/_project_details.html.erb @@ -77,7 +77,7 @@
<%= t("helpers.plan.export.#{field}") -%> <%= value -%>
- <% end %> - <% end %> - - <% @exported_plan.sections.each do |section| %> -<%= 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%> -<%= t("helpers.plan.export.#{field}") -%> <%= value -%>
+ <% end %> + <% end %> + + <% @exported_plan.sections.each do |section| %> +<%= 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%> +Willkommen. Sie können nun ihren ersten DMP erstellen. Wählen Sie 'Plan erstellen' weiter unten aus, um zu beginnen.
" diff --git a/config/locales/en-UK.yml b/config/locales/en-UK.yml index 814afe1..fc6afca 100644 --- a/config/locales/en-UK.yml +++ b/config/locales/en-UK.yml @@ -338,7 +338,7 @@ about_us_label: "About" roadmap_label: "Future plans" help_label: "Help" - publicly_plans_label: "Public DMPs" + public_plans_label: "Public DMPs" contact_label: "Contact" jisc: "The %{organisation_abbreviation} is funded by" @@ -582,10 +582,17 @@ visibility: "Visibility" visibilities: - test: "Test or Practice Plan" - private: "Private (owners, co-owners, and admins only) See our Terms of Use." - organisational: "With others within your organization" - public: "Publicly on the web. Your DMP will appear on the Public DMPs page of this site." + labels: + privately_visible: "Private" + organisationally_visible: "Organisational" + publicly_visible: "Public" + is_test: "Test/Practice" + help_texts: + privately_visible: "Private (owners, co-owners, and administrators only) See our Terms of Use." + organisationally_visible: "Organisational (visibile to others within your organisation)" + publicly_visible: "Public (Your DMP will appear on the Public DMPs page of this site)" + is_test: "Test/Practice (your plan is not visible to other users) See our Terms of Use." + not_set: "Not specified (will be visible to others within your organisation by default)" project_settings_text: "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." project_text_when_no_project: "Welcome. You are now ready to create your first DMP.Click the 'Create plan' button below to begin.
" diff --git a/config/locales/en-US.yml b/config/locales/en-US.yml index 5bc3a01..f3f02ba 100644 --- a/config/locales/en-US.yml +++ b/config/locales/en-US.yml @@ -567,10 +567,17 @@ visibility: "Visibility" visibilities: - test: "Test or Practice Plan" - private: "Private (owners, co-owners, and admins only) See our Terms of Use." - organisational: "With others within your organization" - public: "Publicly on the web. Your DMP will appear on the Public DMPs page of this site." + labels: + privately_visible: "Private" + organisationally_visible: "Organizational" + publicly_visible: "Public" + is_test: "Test/Practice" + help_texts: + privately_visible: "Private (owners, co-owners, and administrators only) See our Terms of Use." + organisationally_visible: "Organizational (visibile to others within your organization)" + publicly_visible: "Public (Your DMP will appear on the Public DMPs page of this site)" + is_test: "Test/Practice (your plan is not visible to other users) See our Terms of Use." + not_set: "Not specified (will be visible to others within your organization by default)" project_settings_text: "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." project_text_when_no_project: "Welcome. You are now ready to create your first DMP.Click the 'Create plan' button below to begin.
" diff --git a/config/locales/es.yml b/config/locales/es.yml index 87d3142..fd9fa5b 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -455,12 +455,20 @@ project_static_info: "Este plan está basado en:" projects_title: "Mis planes" + test: "Plan de prueba o práctica" visibility: "Visibilidad" visibilities: - test: "Plan de prueba o práctica" - private: "Privado (propietarios, copropietarios y administradores solamente) Consulte nuestras Condiciones de uso." - organisational: "Con otros miembros de su organización" - public: "Publicamente en la web. Su DMP aparecerá en la página Public DMPs de este sitio." + labels: + privatelt_visible: "Privado" + organisationally_visible: "Organizativo" + publicly_visible: "Público" + is_test: "Prueba/Práctica" + help_texts: + privately_visible: "Privado (propietarios, copropietarios y administradores solamente) Consulte nuestras Condiciones de uso." + organisationally_visible: "Con otros miembros de su organización" + publicly_visible: "Publicamente en la web. Su DMP aparecerá en la página Public DMPs de este sitio." + is_test: "Prueba / Práctica (su plan no es visible para otros usuarios) Vea nuestras Condiciones de uso." + not_set: "No especificado (será visible para otros dentro de su organización de forma predeterminada)" project_settings_text: "Los items que seleccione se mostarán en la siguiente tabla. Puede ordenar los datos según sus encabezados o filtrar tecleando textos en la caja de búsqueda." project_text_when_no_project: "Bienvenido. Ya está listo para crear su primer PGD.Haga clic en el botón 'Crear un plan' para comenzar.
" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 84f60a2..eb50920 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -459,14 +459,21 @@ project_identifier_help_text: "Un identifiant approprié conforme aux prescriptions de l'organisme financeur ou de l'établissement." project_static_info: "Ce plan s'inspire de :" projects_title: "Mes plans" - + visibility: "Visibilité" visibilities: - test: "Test ou plan de pratique" - private: "Privé (propriétaires, copropriétaires et administrateurs uniquement) Consultez nos Conditions d'utilisation." - organisational: "Avec d'autres membres de votre organisation" - public: "Publiquement sur le web. Votre DMP apparaîtra sur la page Public DMPs de ce site." - + labels: + privately_visible: "Privé" + organisationally_visible: "Organisationnel" + publicly_visible: "Public" + is_test: "Test/Pratique" + help_texts: + privately_visible: "Privé (propriétaires, copropriétaires et administrateurs uniquement) Consultez nos Conditions d'utilisation." + organisationally_visible: "Avec d'autres membres de votre organisation" + publicly_visible: "Publiquement sur le web. Votre DMP apparaîtra sur la page Public DMPs de ce site." + is_test: "Test / Practice (votre plan n'est pas visible aux autres utilisateurs) Voir nos Conditions d'utilisation." + not_set: "Non spécifié (sera visible par d'autres personnes au sein de votre organisation par défaut)" + project_settings_text: "Les éléments que vous sélectionnez ici s'afficherontt dans le tableaiu ci-après. Vous pouvez trier les données à partir de chacune de ces en-tête ou les filtrer en tapant une chaîne de caractères dans la zone de recherche." project_text_when_no_project: "Bienvenue. Vous voilà prêt à créer votre premier DMP.Cliquez sur le bouton 'Créer un plan' ci-dessous pour commencer.
" project_text_when_project: "Dans le tableau ci-dessous figurent les plans que vous avez créés, ainsi que ceux que vous partagez avec d'autres.Vous pouvez à tout moment les modifier, les partager, les exporter, les effacer...
" diff --git a/config/locales/static_pages/de.static.yml.example b/config/locales/static_pages/de.static.yml.example index 3bf5260..bc6987b 100644 --- a/config/locales/static_pages/de.static.yml.example +++ b/config/locales/static_pages/de.static.yml.example @@ -188,4 +188,4 @@ public_plans_page: title: "Öffentliche DMPs" no_plans_body_text_html: "Es wurden noch keine DMPs veröffentlicht." - body_text_html: "Öffentliche DMPs sind Pläne, die mit dem DMPTool erstellt und öffentlich von ihren Eigentümern veröffentlicht werden. Sie werden nicht auf Qualität, Vollständigkeit oder die Einhaltung der funder Richtlinien überprüft." + body_text_html: "Öffentliche DMPs sind Pläne, die mit dem DMPTool erstellt und öffentlich von ihren Eigentümern veröffentlicht werden. Sie werden nicht auf Qualität, Vollständigkeit oder die Einhaltung der funder Richtlinien überprüft." \ No newline at end of file diff --git a/config/locales/static_pages/en-UK.static.yml.example b/config/locales/static_pages/en-UK.static.yml.example index 54e5f2a..8a7d774 100644 --- a/config/locales/static_pages/en-UK.static.yml.example +++ b/config/locales/static_pages/en-UK.static.yml.example @@ -218,5 +218,5 @@ public_plans_page: title: "Public DMPs" - no_plans_body_text_html: "No DMPs have been made public yet." body_text_html: "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." + no_plans_body_text_html: "There are no public DMPs." \ No newline at end of file diff --git a/config/locales/static_pages/en-US.static.yml.example b/config/locales/static_pages/en-US.static.yml.example index fa41df8..3f9f003 100644 --- a/config/locales/static_pages/en-US.static.yml.example +++ b/config/locales/static_pages/en-US.static.yml.example @@ -218,4 +218,5 @@ public_plans_page: title: "Public DMPs" - body_text_html: "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." \ No newline at end of file + body_text_html: "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." + no_plans_body_text_html: "There are no public DMPs." \ No newline at end of file diff --git a/db/migrate/20170110092511_add_is_test_and_visibility_to_projects.rb b/db/migrate/20170110092511_add_is_test_and_visibility_to_projects.rb index 7621f8f..b20e27a 100644 --- a/db/migrate/20170110092511_add_is_test_and_visibility_to_projects.rb +++ b/db/migrate/20170110092511_add_is_test_and_visibility_to_projects.rb @@ -1,6 +1,5 @@ class AddIsTestAndVisibilityToProjects < ActiveRecord::Migration def change - add_column :projects, :is_test, :boolean, default: false - add_column :projects, :visibility, :integer, default: 0 + add_column :projects, :visibility, :integer, null: false, default: 0 end end diff --git a/lib/assets/javascripts/projects.js b/lib/assets/javascripts/projects.js index 1319733..0645304 100644 --- a/lib/assets/javascripts/projects.js +++ b/lib/assets/javascripts/projects.js @@ -205,14 +205,22 @@ // ---------------------------------------------------------- $("#project_is_test").click(function(e){ if(this.checked){ - $("#project_is_public").prop('checked', false); + $("input[name='project[visibility]']").prop('disabled', true); + $(".is-test-label").show(); + }else{ + $("input[name='project[visibility]']").prop('disabled', false); + $(".is-test-label").hide(); } }); + // Handle the 'test' flag on page load // ---------------------------------------------------------- - $("#project_is_public").click(function(e){ - if(this.checked){ - $("#project_is_test").prop('checked', false); - } - }); + if($("#project_is_test").checked){ + $("input[name='project[visibility]']").prop('disabled', true); + $(".is-test-label").show(); + }else{ + $("input[name='project[visibility]']").prop('disabled', false); + $(".is-test-label").hide(); + } + }); diff --git a/lib/assets/stylesheets/bootstrap_and_overrides.css.less b/lib/assets/stylesheets/bootstrap_and_overrides.css.less index e71ec49..f6c099e 100644 --- a/lib/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/lib/assets/stylesheets/bootstrap_and_overrides.css.less @@ -744,6 +744,10 @@ margin-top:4px; } +.radio-label { + margin-left: 10px; +} + .sign_up_org_label{ margin: 0 0 6px 0; float:left; diff --git a/test/functional/static_pages_controller_test.rb b/test/functional/static_pages_controller_test.rb index 3450cc5..11efee1 100644 --- a/test/functional/static_pages_controller_test.rb +++ b/test/functional/static_pages_controller_test.rb @@ -3,17 +3,31 @@ include Devise::Test::IntegrationHelpers setup do - @project = Project.first + @public_project = Project.create!({title: 'Public Test Project', + dmptemplate: Dmptemplate.first, + organisation: Organisation.first, + visibility: :publicly_visible}) + end + + # ---------------------------------------------------------- + test "should only return plans with public visibility" do + get public_plans_path(locale: I18n.locale) - @test_visibility = Visibility.find_by(name: 'test') - @public_visibility = Visibility.find_by(name: 'public') + assert_response :success + assert_not_nil assigns(:projects) + + all_public = true + + assigns(:projects).each do |project| + all_public = false unless project.publicly_visible? + end + + assert all_public, "expected all of the plans to have public visibility!" end # ---------------------------------------------------------- test "should export the publicly available plan" do - @project.visibility = @public_visibility - @project.save! - + # get public_export_path(locale: I18n.locale, id: @project) # Should be redirected to the plans controller's export function @@ -28,21 +42,21 @@ # ---------------------------------------------------------- test "should NOT export a non-public plan to unauthorized users" do # Set the is_public flag to false and try to access it when not logged in - @project.visibility = @test_visibility - @project.save! + @public_project.visibility = :privately_visible + @public_project.save! - get public_export_path(locale: I18n.locale, id: @project) + get public_export_path(locale: I18n.locale, id: @public_project) assert_redirected_to "#{public_plans_path}", "expected to be redirected to the home page!" assert_equal I18n.t('helpers.settings.plans.errors.no_access_account'), flash[:notice], "Expected an unauthorized message when trying to export a plan (via the public_export route) when the plan is not actually public" # Set the is_public flag to false and assign ownership to a different user and then try to access it as a non-owner - @project.assign_creator(User.last) - @project.save! + @public_project.assign_creator(User.last) + @public_project.save! sign_in User.first - get public_export_path(locale: I18n.locale, id: @project) + get public_export_path(locale: I18n.locale, id: @public_project) assert_redirected_to "#{public_plans_path}", "expected to be redirected to the home page!" assert_equal I18n.t('helpers.settings.plans.errors.no_access_account'), flash[:notice], "Expected an unauthorized message when trying to export a plan (via the public_export route) when the plan is not actually public" diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index c4c1f20..510845f 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -36,17 +36,15 @@ # --------------------------------------------------- test "can CRUD Comment" do - [@text_area_question, @text_field_question].each do |q| - cmnt = Comment.create(user: @user, plan: @plan, question: q, text: 'Tested ABC') - assert_not cmnt.id.nil?, "was expecting to be able to create a new Comment for a #{q.question_format.title} question: #{cmnt.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" + cmnt = Comment.create(user: @user, plan: @plan, question: @text_area_question, text: 'Tested ABC') + assert_not cmnt.id.nil?, "was expecting to be able to create a new Comment: #{cmnt.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" - cmnt.text = 'Testing an update' - cmnt.save! - cmnt.reload - assert_equal 'Testing an update', cmnt.text, "Was expecting to be able to update the text of the Comment for a #{q.question_format.title} question!" - - assert cmnt.destroy!, "Was unable to delete the Comment for a #{q.question_format.title} question!" - end + cmnt.text = 'Testing an update' + cmnt.save! + cmnt.reload + assert_equal 'Testing an update', cmnt.text, "Was expecting to be able to update the text of the Comment!" + + assert cmnt.destroy!, "Was unable to delete the Comment!" end end diff --git a/test/unit/exported_plan_test.rb b/test/unit/exported_plan_test.rb index fcb163a..00ef9cb 100644 --- a/test/unit/exported_plan_test.rb +++ b/test/unit/exported_plan_test.rb @@ -23,12 +23,11 @@ # --------------------------------------------------- test "required fields are required" do assert_not ExportedPlan.new.valid? - assert_not ExportedPlan.new(user: @user, format: ExportedPlan::VALID_FORMATS.last).valid?, "expected the 'plan' field to be required" - assert_not ExportedPlan.new(plan: @plan, format: ExportedPlan::VALID_FORMATS.last).valid?, "expected the 'user' field to be required" - assert_not ExportedPlan.new(user: @user, plan: @plan).valid?, "expected the 'format' field to be required" + assert_not ExportedPlan.new(format: ExportedPlan::VALID_FORMATS.last).valid?, "expected the 'plan' field to be required" + assert_not ExportedPlan.new(plan: @plan).valid?, "expected the 'format' field to be required" # Ensure the bar minimum and complete versions are valid - a = ExportedPlan.new(user: @user, plan: @plan, format: ExportedPlan::VALID_FORMATS.last) + a = ExportedPlan.new(plan: @plan, format: ExportedPlan::VALID_FORMATS.last) assert a.valid?, "expected the 'plan', 'user' and 'format' fields to be enough to create an ExportedPlan! - #{a.errors.map{|f, m| f.to_s + ' ' + m}.join(', ')}" end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index fe4a712..194cd8b 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -188,7 +188,7 @@ project = Project.new(title: 'Test Project', dmptemplate_id: @dmptemplate.id) plan = Plan.new(project: project) question = Question.new(text: 'testing question') - answer = Answer.new(plan: plan, question: question) + answer = Answer.new(plan: plan, question: question, text: "Here's my answer") verify_has_many_relationship(@super, answer, @super.answers.count) end