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

How to make config dynamic #62

Closed
timsatterfield opened this issue Oct 26, 2018 · 10 comments
Closed

How to make config dynamic #62

timsatterfield opened this issue Oct 26, 2018 · 10 comments
Assignees
Labels
#️⃣.#️⃣ Minor added functionality in a backwards-compatible manner ✨ enhancement
Projects
Milestone

Comments

@timsatterfield
Copy link

Wondering how to best make the config attributes dynamic per instance of a model.

Example: for a given Model which belongs to a specific Organization might have different password validation requirements or password expiry length.

Overriding password_complexity, password_length or other methods in the Model doesn't seem to do anything. Any help here?

@olbrich
Copy link
Contributor

olbrich commented Oct 26, 2018

Can you give me a made up code example of what you would like to be able to do?

@timsatterfield
Copy link
Author

class Manager < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :trackable,
         :confirmable, :lockable,
         :secure_validatable

  belongs_to :team

  # Override password_length enforced by secure_validatable
  def password_length
  	team.password_length | # return value from the devise config file
  end

  def password_complexity
  	team.password_complexity | # return value from the devise config file
  end

  # Have similar overrides for other module rules etc

end

@olbrich
Copy link
Contributor

olbrich commented Oct 26, 2018

On the surface this seems like it could work, but I suspect what is happening is that those methods are being evaluated at the time the class is loaded and never again after that. I'll dig into it some more and see if we can verify this and modify this so that it can be a proc or something.

@rmorlok
Copy link

rmorlok commented May 14, 2019

Is there any way that something like this could make its way into the gem? I have a similar requirement where I have customers with sets of users that have differing IT policies on things like password complexity requirements, etc.

@olbrich
Copy link
Contributor

olbrich commented May 14, 2019

@rmorlok yes, I'll update #63 and see if we can get this working again.

@olbrich olbrich self-assigned this May 14, 2019
@olbrich olbrich added this to the 0.15.0 milestone May 14, 2019
@olbrich olbrich added #️⃣.#️⃣ Minor added functionality in a backwards-compatible manner ✨ enhancement labels May 14, 2019
@AndrewJGregory
Copy link

Any updates on this?

@olbrich olbrich added this to To do in v0.17.0 May 16, 2020
@olbrich olbrich pinned this issue Sep 12, 2020
@olbrich olbrich moved this from To do to In progress in v0.17.0 Sep 12, 2020
@dillonwelch dillonwelch modified the milestones: 0.15.0, 0.16.0 Jan 13, 2021
@dillonwelch dillonwelch modified the milestones: 0.16.0, 0.17.0 May 3, 2021
@shiraz-khan-ror
Copy link

Hey guyz whats the status for this task

@WilfredRuck
Copy link

Hey, I could also make use of this. Any updates or in between solutions available?

@dillonwelch
Copy link
Contributor

Chipping away at this. Will be making some smaller PRs over the next few days hopefully.

@dillonwelch dillonwelch self-assigned this Oct 11, 2021
dillonwelch added a commit that referenced this issue Oct 27, 2021
* Refactor tests for SecureValidatable module

While working on
#62, I noticed
that there were a lot of edge cases that either weren't tested at all or
did not consider all cases. I wanted to address this issue before
finalizing my changes so that I have greater confidence that the changes
do not break existing functionality in the module.

This commit changes the following:
* Removes the unnecessary devise modules from the User class so that we
  can be sure only functionality related to this module is being tested.
* Removes a bunch of save commands, as writing to the DB slows tests
  down and most of the functionality could be tested without that.
* Cleans up language of test descriptions.
* Adds consistency to emails, passwords, and formatting for asserts.

This commit adds the following tests:
* Allow email to be blank if email is not required
* Fail if updating email from non-blank to blank
* Fail if password is blank on creation
* Fail if password is updated to blank
* Fail if password_confirmation does not match password or is blank
* Allow password_confirmation to be skipped
* Fail if new password equals existing password
* Fail if module is included in a class that doesn't support the
  validates API

This used #63 as
a starting point.

Co-authored-by: Kevin Olbrich <kevin.olbrich@gmail.com>
@olbrich olbrich unpinned this issue Dec 19, 2021
@dillonwelch
Copy link
Contributor

This will be released in 0.17.0 shortly.

v0.17.0 automation moved this from In progress to Done Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
#️⃣.#️⃣ Minor added functionality in a backwards-compatible manner ✨ enhancement
Projects
No open projects
v0.17.0
  
Done
7 participants