Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#dcc2983 - Fix for preventing adding a Contributor via Contributor #3071

Conversation

johnpinto1
Copy link
Contributor

form for Plan based on whether email and/or name are required.

Fix for DCC bug #2983

Changes:

  • Added two new properties to config/initializers/_dmproadmap.rb
    (both devault to false):
    config.x.application.require_contributor_name = false
    config.x.application.require_contributor_email = false
    -In Contributor model the private method name_or_email_presence()
    has been updated to take account of the above mentioned property
    settings.

Fixes # .

Changes proposed in this PR:

@johnpinto1 johnpinto1 force-pushed the bug_DCC2983-possible_to_add_contributor_without_a_name branch from ce790e5 to e747559 Compare November 23, 2021 13:50
@johnpinto1
Copy link
Contributor Author

johnpinto1 commented Nov 23, 2021

@briri & @raycarrick-ed This is attempt to address @briri comment #3062 (comment)
The default leaves the current contributor form validation unchanged.
@raycarrick-ed DCC will need to set properties below to address dcc bug #2983

# Setting require contributor requirement of contributor name and email
      config.x.application.require_contributor_name = true
      config.x.application.require_contributor_email = true

@johnpinto1 johnpinto1 force-pushed the bug_DCC2983-possible_to_add_contributor_without_a_name branch from e747559 to d6a81a8 Compare November 23, 2021 14:23
Copy link
Contributor

@briri briri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @johnpinto1!

@johnpinto1
Copy link
Contributor Author

@briri I like you to double-check the logic as it took me trial and error to get it to what seemed like "work". Thanks.

@briri
Copy link
Contributor

briri commented Nov 23, 2021

Hey @johnpinto1 upon further review and testing of different options I would suggest that we do the following:

  • Add the config options (just as you have them) ... but make the default require_contributor_name = true
  • Remove the current validation method and replace them with the ones below.
  • Update the email 'uniqueness' validator to allow nulls. See https://guides.rubyonrails.org/active_record_validations.html#allow-nil
  • Update the view to check the config setting to determine if the red asterisk should be displayed
  validates :name, presence: { message: PRESENCE_MESSAGE },
                   if: -> { Rails.configuration.x.application.require_contributor_name }

  validates :email, presence: { message: PRESENCE_MESSAGE },
                    if: -> { Rails.configuration.x.application.require_contributor_email }

@raycarrick-ed
Copy link
Contributor

Looks good overall.
Agree with @briri 's comments above.
I think the code can be simplified where you have:

Rails.configuration.x.application.foobar.present? && Rails.configuration.x.application.foobar

I think that is exactly the same as just

Rails.configuration.x.application.foobar

if it's not present it will return nil which is equivalent to false. That would cut out quite a few lines of code.

@raycarrick-ed
Copy link
Contributor

And another thing .....

when this change comes through we will need to add in the 2 new config setting. Is there an easy way to track this? I could just add them in now on the assumption that they won't have any effect until this comes through or I could leave a note for myself to watch out for it but those both seem quite clumsy ways to do it. Either of you know a better way to handle something like this?

@johnpinto1
Copy link
Contributor Author

@raycarrick-ed Adding the properties now seems a good idea. I have done something similar in another project to prevent forgetting about it in future.

@johnpinto1
Copy link
Contributor Author

@raycarrick-ed & @briri I will look at it again. I had issues with Rails.configuration.x.application.foobar
when property not in config. I play around to establish if I was seeing another issue.

form for Plan based on whether email and/or name are required.

Fix for DCC bug #2983

Changes:
 - Added two new properties to config/initializers/_dmproadmap.rb
   (both devault to false):
   config.x.application.require_contributor_name = false
   config.x.application.require_contributor_email = false
 -In Contributor model the private method name_or_email_presence()
  has been updated to take account of the above mentioned property
settings.
@johnpinto1 johnpinto1 force-pushed the bug_DCC2983-possible_to_add_contributor_without_a_name branch from d6a81a8 to db783fc Compare November 24, 2021 15:11
@johnpinto1
Copy link
Contributor Author

@briri & @raycarrick-ed I have updated code based on your comments and my experimenting with nil (when a property is missing by usiing ! or !! (if I want current value or nil -> false)
irb(main):001:0> nil
=> nil
irb(main):002:0> !nil
=> true
irb(main):003:0> nil == true
=> false
Method now

def name_or_email_presence
  return true unless (name.blank? && email.blank?) ||
                      (!!Rails.configuration.x.application.require_contributor_name &&
                      name.blank?) ||
                      (!!Rails.configuration.x.application.require_contributor_email &&
                      email.blank?)

  # Error messages for case where name.blank? and email.blank? and
  # properties Rails.configuration.x.application.require_contributor_name and
  # Rails.configuration.x.application.require_contributor_email both not set (i.e, nil) or false.
  if (name.blank? && email.blank?) &&
     !Rails.configuration.x.application.require_contributor_name &&
     !Rails.configuration.x.application.require_contributor_email
    errors.add(:name, _("can't be blank if no email is provided."))
    errors.add(:email, _("can't be blank if no name is provided."))
  else

    # Error messages cases where enither ame.blank? or email.blank?
    if name.blank? && !!Rails.configuration.x.application.require_contributor_name
      errors.add(:name, _("can't be blank."))
    end

    if email.blank? && !!Rails.configuration.x.application.require_contributor_email
      errors.add(:email, _("can't be blank."))
    end
  end
end

John Pinto and others added 15 commits January 5, 2022 10:08
    pagination of user's plans broken.

    Fix for issue #3069 and DCC issue
    https://github.com/DigitalCurationCentre/DMPonline-Service/issues/675.

    Changes:
      - Replaced view files /paginable/plans/org_admin_other_user with /paginable/plans/_index.html.erb
        with extra checks for plan.owner.present? as missing plan.owner broke a DCC user's plans being render by org_admin.
      - Replaced partial with '/paginable/plans/org_admin_other_user'  with '/paginable/plans/index',
         replaced action'org_admin_other_user' with 'index' in paginable_renderiser() method in views
        /org_admin/users/edit.html.erb. /org_admin/users/plans.html.erb and /super_admin/users/edit.html.erb.
      - In Paginable::PlansController replaced -
        # GET /paginable/plans/org_admin/:page  with # GET /paginable/users/:id/plans
        associated with method org_admin_other_user()  renamed index()
      - Routes replaced
        get "org_admin_other_user/:page", action: :org_admin_other_user,
                                        on: :collection, as: :org_admin_other_user
        # Paginable actions for users
        resources :users, only: [] do
          get "index/:page", action: :index, on: :collection, as: :index

        with

        resources :users, only: %i[index] do
           member do
             resources :plans, only: %(index)
           end
        end
… Org.

Fixes issues:
https://github.com/DigitalCurationCentre/DMPonline-Service/issues/592
https://github.com/DigitalCurationCentre/DMPonline-Service/issues/645
https://github.com/DigitalCurationCentre/DMPonline-Service/issues/641

The reason we are seeing deleted (de-activated) Plans is that there is
no filter for plans with Roles active in the Org model's
org_admin_plans() method.

Change added .where(roles: { active: true }) to filter plans in
org_admin_plans() method of Org model.
exception occuring for an answer with question options selected but text
nil. Link to issue
https://github.com/DigitalCurationCentre/DMPonline-Service/issues/674

Change to app/models/concerns/exportable_plan.rb,
we replaced line
   answer_text += answer.text if answer.answered?
with answer.text present check
   answer_text += answer.text if answer.answered? && answer.text.present?
Orgs.

Fix for DCC issue https://github.com/DigitalCurationCentre/DMPonline-Service/issues/679

Changes:
- in app/controllers/super_admin/orgs_controller.rb added missing params
to orgs_params method
     :funder, :institution, :organisation
- in app/models/org.rb removed (as it is never set on Org creation)
      validates :abbreviation, presence: { message: PRESENCE_MESSAGE }
- in app/views/orgs/_profile_form.html.erb removed :abbreviation required
      "aria-required": true
- in app/views/shared/org_selectors/_external_only.html.erb renamed wrongly named text field :org_name to :name
      <%= form.label :name, label %>
      <%= form.text_field :name, class: "form-control autocomplete",
Orgs.

Fix for DCC issue https://github.com/DigitalCurationCentre/DMPonline-Service/issues/679

Changes:
- in app/controllers/super_admin/orgs_controller.rb added missing params
to orgs_params method
     :funder, :institution, :organisation
- in app/models/org.rb removed (as it is never set on Org creation)
      validates :abbreviation, presence: { message: PRESENCE_MESSAGE }
- in app/views/orgs/_profile_form.html.erb removed :abbreviation required
      "aria-required": true
- in app/views/shared/org_selectors/_external_only.html.erb renamed wrongly named text field :org_name to :name
      <%= form.label :name, label %>
      <%= form.text_field :name, class: "form-control autocomplete",
…s' of github.com:DMPRoadmap/roadmap into bug-dcc-679-super-admins-unable-to-add-new-organisations
look at what comes out of safe_save
Schrodinger's cat, it seems
in org model spec
org spec failing with no abbrev for some reason.
Used to be that org had to have an abbrev. That stopped the Super Admin creating the org so was removed. Remove check from this test.
…ble-to-add-new-organisations

DCC Issue 679 - Fix for issue that Super Admins unable to create new
John Pinto and others added 20 commits February 1, 2022 12:28
… Org.

Fixes issues:
https://github.com/DigitalCurationCentre/DMPonline-Service/issues/592
https://github.com/DigitalCurationCentre/DMPonline-Service/issues/645
https://github.com/DigitalCurationCentre/DMPonline-Service/issues/641

The reason we are seeing deleted (de-activated) Plans is that there is
no filter for plans with Roles active in the Org model's
org_admin_plans() method.

Change added .where(roles: { active: true }) to filter plans in
org_admin_plans() method of Org model.
…g_admins' of github.com:DMPRoadmap/roadmap into bug_dcc_592_and_645_deleted-private_plans_visible_to_org_admins
…private_plans_visible_to_org_admins

Bug DCC Issues 592, 645 - Fix for Org Admins seeing deleted Plans for…
…hub.com:DMPRoadmap/roadmap into bug_dcc_674_csv_download_plans_fails_for_admins
…ns_fails_for_admins

Issue DCC-674: Fix for broken CSV Download noticed because a nil
    pagination of user's plans broken.

    Fix for issue #3069 and DCC issue
    https://github.com/DigitalCurationCentre/DMPonline-Service/issues/675.

    Changes:
      - Replaced view files /paginable/plans/org_admin_other_user with /paginable/plans/_index.html.erb
        with extra checks for plan.owner.present? as missing plan.owner broke a DCC user's plans being render by org_admin.
      - Replaced partial with '/paginable/plans/org_admin_other_user'  with '/paginable/plans/index',
         replaced action'org_admin_other_user' with 'index' in paginable_renderiser() method in views
        /org_admin/users/edit.html.erb. /org_admin/users/plans.html.erb and /super_admin/users/edit.html.erb.
      - In Paginable::PlansController replaced -
        # GET /paginable/plans/org_admin/:page  with # GET /paginable/users/:id/plans
        associated with method org_admin_other_user()  renamed index()
      - Routes replaced
        get "org_admin_other_user/:page", action: :org_admin_other_user,
                                        on: :collection, as: :org_admin_other_user
        # Paginable actions for users
        resources :users, only: [] do
          get "index/:page", action: :index, on: :collection, as: :index

        with

        resources :users, only: %i[index] do
           member do
             resources :plans, only: %(index)
           end
        end
…esults_on_plans_org_admin_other_user_breaks

 Issue#3069 - (DCC Issue 675) - Org Admin and Super Admin searches and
form for Plan based on whether email and/or name are required.

Fix for DCC bug #2983

Changes:
 - Added two new properties to config/initializers/_dmproadmap.rb
   (both devault to false):
   config.x.application.require_contributor_name = false
   config.x.application.require_contributor_email = false
 -In Contributor model the private method name_or_email_presence()
  has been updated to take account of the above mentioned property
settings.
… of github.com:DMPRoadmap/roadmap into bug_DCC2983-possible_to_add_contributor_without_a_name
typo
rubocop stuff. Single line ifs and use of zero?
@raycarrick-ed raycarrick-ed merged commit ec68303 into development Feb 2, 2022
@raycarrick-ed raycarrick-ed deleted the bug_DCC2983-possible_to_add_contributor_without_a_name branch February 2, 2022 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants