diff --git a/Gemfile b/Gemfile index ae7d281..ebb1231 100644 --- a/Gemfile +++ b/Gemfile @@ -36,6 +36,10 @@ gem 'friendly_id' # ------------------------------------------------ +# BIT FIELDS +gem 'flag_shih_tzu' + +# ------------------------------------------------ # SUPER ADMIN SECTION gem 'activeadmin', github: 'activeadmin' @@ -64,9 +68,11 @@ gem 'jquery-rails' gem 'twitter-bootstrap-rails', '2.2.8' gem 'tinymce-rails' # WYSIWYG EDITOR +gem 'substance-rails', path: '../substance-rails' # SUBSTANCE EDITOR - WYSIWYG HTML EDITOR gem 'contact_us', '>= 1.2.0' # COULD BE EASILY REPLACED WITH OUR OWN CODE gem 'recaptcha' gem 'dragonfly' # LOGO UPLOAD +gem "substance-rails", path: "../substance-rails" # SUBSTANCE EDITOR # ------------------------------------------------ # EXPORTING diff --git a/Gemfile.lock b/Gemfile.lock index 855f159..1876112 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,6 +25,13 @@ rails (>= 3.0, < 5.1) rake (>= 0.8.7) +PATH + remote: ../substance-rails + specs: + substance-rails (0.0.2) + actionpack (>= 4.0) + railties (>= 4.0) + GEM remote: https://rubygems.org/ specs: @@ -138,6 +145,7 @@ faraday_middleware (~> 0.9) loofah (~> 2.0) sax-machine (~> 1.0) + flag_shih_tzu (0.3.15) formtastic (3.1.4) actionpack (>= 3.2.13) formtastic_i18n (0.6.0) @@ -368,6 +376,7 @@ devise_invitable dragonfly feedjira + flag_shih_tzu friendly_id htmltoword i18n-js (>= 3.0.0.rc11) @@ -395,6 +404,7 @@ sass-rails simplecov sqlite3 + substance-rails! swagger-docs therubyracer (>= 0.11.4) thin diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index e157e76..bd03be7 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -7,7 +7,12 @@ authorize @answer old_answer = @answer.plan.answer(@answer.question_id, false) proceed = false - @answer.text = params["answer-text-#{@answer.question_id}".to_sym] + +puts "NEW ANSWER" +puts @answer.inspect +puts "OLD ANSWER" +puts old_answer.inspect + if (old_answer.nil? && @answer.text != "") || ((!old_answer.nil?) && (old_answer.text != @answer.text)) then proceed = true end diff --git a/app/controllers/dmptemplates_controller.rb b/app/controllers/dmptemplates_controller.rb index 9c7f757..e4b8785 100644 --- a/app/controllers/dmptemplates_controller.rb +++ b/app/controllers/dmptemplates_controller.rb @@ -8,10 +8,17 @@ # GET /dmptemplates def admin_index authorize Dmptemplate - #institutional templates + +# TODO: Wouldn't make more sense here to just do the following (using new model names here)?: +# @dmptemplates_own = current_user.org.templates + @dmptemplates_own = Dmptemplate.own_institutional_templates(current_user.organisation_id) - #funders templates + +# TODO: Wouldn't make more sense here to just do the following?: +# @@dmptemplates_funders = Org.where(org_type: :funder).templates + @dmptemplates_funders = Dmptemplate.funders_templates + respond_to do |format| format.html # index.html.erb end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a653686..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 @@ -71,6 +68,10 @@ @always_guidance = get_always_available_guidance @institutions = orgs_of_type(constant("organisation_types.institution")) +# TODO: Would be better to determine if the user's org has templates here than in the view. +# Replace the if Dmptemplate.own_institutional_templates check in views/projects/new with: +# @own_org_has_templates = current_user.organisation.templates.empty? + respond_to do |format| format.html # new.html.erb end @@ -139,7 +140,7 @@ if user_signed_in? then attrs = project_params - + @project = Project.new(attrs) authorize @project @@ -183,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/answer.rb b/app/models/answer.rb index a989c8f..9d2c914 100644 --- a/app/models/answer.rb +++ b/app/models/answer.rb @@ -6,6 +6,13 @@ belongs_to :plan has_and_belongs_to_many :options, join_table: "answers_options" - - attr_accessible :text, :plan_id, :question_id, :user_id, :option_ids , :as => [:default, :admin] + +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :text, :plan_id, :question_id, :user_id, :option_ids, :plan, :user, :question, + :as => [:default, :admin] + + validates :user, :plan, :question, :text, presence: true + + # Make sure there is only one answer per question! +# validates :question, uniqueness: {scope: [:user, :plan], message: I18n.t('helpers.errors.answer.only_one_per_question')} end diff --git a/app/models/comment.rb b/app/models/comment.rb index b4af9f9..a2e2ea2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,12 +1,15 @@ class Comment < ActiveRecord::Base #associations between tables + belongs_to :user + belongs_to :plan belongs_to :question - #fields - attr_accessible :question_id, :text, :user_id, :archived, :plan_id, :archived_by, :as => [:default, :admin] +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :question_id, :text, :user_id, :archived, :plan_id, :archived_by, + :user, :plan, :question, :as => [:default, :admin] - + validates :user, :question, :plan, :text, presence: true def to_s "#{text}" diff --git a/app/models/dmptemplate.rb b/app/models/dmptemplate.rb index 1ef460c..2289167 100644 --- a/app/models/dmptemplate.rb +++ b/app/models/dmptemplate.rb @@ -1,33 +1,37 @@ class Dmptemplate < ActiveRecord::Base - include GlobalHelpers + include GlobalHelpers - attr_accessible :id, :organisation_id, :description, :published, :title, :user_id, :locale, - :phases, :projects, :organisation, - :is_default, :guidance_group_ids, :as => [:default, :admin] +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :id, :organisation_id, :description, :published, :title, :user_id, :locale, + :phases, :projects, :organisation, + :is_default, :guidance_group_ids, :as => [:default, :admin] - #associations between tables - has_many :phases - has_many :versions, through: :phases - has_many :sections, through: :versions - has_many :questions, through: :sections - has_many :projects + #associations between tables + has_many :phases + has_many :versions, through: :phases + has_many :sections, through: :versions + has_many :questions, through: :sections + has_many :projects - #has_many :guidances needs to be removed and checked + #has_many :guidances needs to be removed and checked - belongs_to :organisation + belongs_to :organisation has_and_belongs_to_many :guidance_groups, join_table: "dmptemplates_guidance_groups" - accepts_nested_attributes_for :guidance_groups - accepts_nested_attributes_for :phases - accepts_nested_attributes_for :organisation - accepts_nested_attributes_for :projects +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + accepts_nested_attributes_for :guidance_groups + accepts_nested_attributes_for :phases + accepts_nested_attributes_for :organisation + accepts_nested_attributes_for :projects has_settings :export, class_name: 'Settings::Dmptemplate' do |s| s.key :export, defaults: Settings::Dmptemplate::DEFAULT_SETTINGS end + validates :organisation, :title, presence: true + ## # Converts a DMPtemplate object into a string containing it's title # @@ -36,6 +40,13 @@ "#{title}" end + +# TODO: Remove the following methods ... they are never called by anything and don't make sense here anyway: +# self.templates_org_type +# self.funders_templates +# self.own_institutional_templates +# self.funders_and_own_templates + ## # takes a type or organisation and returns all published templates from # organisations of that type @@ -116,6 +127,7 @@ return templates_list end +# TODO: Remove this! We should not be attempting to access an Org attribute through this class ## # Returns the string name of the organisation type of the organisation who # owns this dmptemplate diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index 3782b52..8cc149f 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -1,7 +1,8 @@ class ExportedPlan < ActiveRecord::Base include GlobalHelpers - attr_accessible :plan_id, :user_id, :format, :as => [:default, :admin] +# TODO: REMOVE AND HANDLE ATTRIBUTE SECURITY IN THE CONTROLLER! + attr_accessible :plan_id, :user_id, :format, :user, :plan, :as => [:default, :admin] #associations between tables belongs_to :plan @@ -10,6 +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, :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 @@ -18,6 +20,9 @@ s.key :export, defaults: Settings::Dmptemplate::DEFAULT_SETTINGS end +# TODO: Consider removing the accessor methods, they add no value. The view/controller could +# just access the value directly from the project/plan: exported_plan.plan.project.title + # Getters to match Settings::Dmptemplate::VALID_ADMIN_FIELDS def project_name name = self.plan.project.title diff --git a/app/models/plan.rb b/app/models/plan.rb index f25998c..96d3aea 100644 --- a/app/models/plan.rb +++ b/app/models/plan.rb @@ -1,6 +1,7 @@ class Plan < ActiveRecord::Base - attr_accessible :locked, :project_id, :version_id, :version, :plan_sections, :as => [:default, :admin] + attr_accessible :locked, :project_id, :version_id, :version, :plan_sections, + :Exported_plans, :as => [:default, :admin] A4_PAGE_HEIGHT = 297 #(in mm) A4_PAGE_WIDTH = 210 #(in mm) @@ -13,6 +14,7 @@ belongs_to :version has_many :answers has_many :plan_sections + has_many :exported_plans # accepts_nested_attributes_for :project accepts_nested_attributes_for :answers diff --git a/app/models/project.rb b/app/models/project.rb index 06e51ec..6af3276 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,13 +1,11 @@ class Project < ActiveRecord::Base include GlobalHelpers - + extend FriendlyId #associations between tables belongs_to :dmptemplate belongs_to :organisation - - belongs_to :visibility has_many :plans has_many :project_groups, :dependent => :destroy @@ -15,6 +13,9 @@ friendly_id :title, use: [:slugged, :history, :finders] + # 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 398c264..bc8da32 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,7 +15,7 @@ has_many :user_org_roles has_many :project_groups, :dependent => :destroy has_many :user_role_types, through: :user_org_roles - + has_many :exported_plans has_many :user_identifiers has_many :identifier_schemes, through: :user_identifiers @@ -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/models/visibility.rb b/app/models/visibility.rb deleted file mode 100644 index 26f7270..0000000 --- a/app/models/visibility.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Visibility < ActiveRecord::Base - has_many :projects - - validates :name, uniqueness: true, presence: true -end \ No newline at end of file diff --git a/app/views/dmptemplates/_show_question.html.erb b/app/views/dmptemplates/_show_question.html.erb index df79c2b..03ee743 100644 --- a/app/views/dmptemplates/_show_question.html.erb +++ b/app/views/dmptemplates/_show_question.html.erb @@ -19,7 +19,7 @@ <%= raw question.text %>
- <% q_format = question.question_format %> + <% q_format = question.question_format || QuestionFormat.first %> <% 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%>