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

Update authentication module to utilise get_custom_file_if_exists #8736

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

markvp
Copy link

@markvp markvp commented May 21, 2020

Description

The authentication module has many local file includes which makes it very challenging to customise any of the functionality in the /custom folder.
This PR replaces all local includes/requires to use the get_custom_file_if_exists util function allowing any individual file to be customised.
There is also a lot of repetition of folder names that I have extracted into constants to avoid magic-strings.

Motivation and Context

It is really frustrating to customise any files in this module without having to replicate the entire module into the custom folder.
For me this was related to implementing this: #6850 (comment)

How To Test This

Standard login / logout through each of the authentication modules.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Final checklist

  • My code follows the code style of this project found here.
  • My change requires a change to the documentation.
  • I have read the How to Contribute guidelines.

@codecov-commenter
Copy link

Codecov Report

Merging #8736 into master will decrease coverage by 0.00%.
The diff coverage is 0.00%.

@@             Coverage Diff              @@
##             master    #8736      +/-   ##
============================================
- Coverage     11.33%   11.33%   -0.01%     
+ Complexity    41552    41549       -3     
============================================
  Files          3291     3291              
  Lines        244949   244953       +4     
============================================
  Hits          27765    27765              
- Misses       217184   217188       +4     

@pgorod
Copy link
Contributor

pgorod commented May 22, 2020

We shouldn't add get_custom_file_if_exists in places where customization by overriding classes is possible. We shouldn't encourage an inferior type of customization (replacing the entire file) in place of a superior one (inheritance, partial redefinition, ability to call parent, ability to consolidate changes from several sources into a single coherent whole).

Did you try the class override? what problems did you run into?

@chris001
Copy link
Contributor

The core sugar specs require that when a user installs custom code into the custom directory, that the core detect this and automatically load the custom class instead of the core class file. This should be consistently working everywhere. PSR-0 and PSR-4 should also be working everywhere. One should take precedence over the other.
A good reference to pattern after by default would be the Sugar 9.0 developer guide where it explains how Sugar 9 uses a custom handler with composer for auto loading code etc:
https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.0/Introduction/Composer/

@markvp
Copy link
Author

markvp commented Aug 26, 2020

@pgorod can you please be specific where you think that applies here?
I need to customise the onelogin/settings.php file but because of the inconsistent retrieval of custom files, I have to customise SAML2Authenticate.php to load that custom file, but then because it uses relative directory references, I have to copy SugarAuthenticate.php to the custom folder as well. I don't see how overriding a class is the simplest or best solution here? All I want to do is customise a settings file...
With this code change, I am ensuring that any file can be placed in the custom folder and it will be retrieved correctly.

@chris001 I agree, any custom code should be loaded. That's what I'm trying to implement here. Can you give me an example of the pattern you're referring to? I can't see a pattern in your reference.

@SuiteBot
Copy link

SuiteBot commented Aug 27, 2020

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ markvp
❌ Mark van Proctor


Mark van Proctor seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@pgorod
Copy link
Contributor

pgorod commented Aug 27, 2020

@markvp my comment was preliminary and was more of a question than a statement. If you (or we) conclude that this is the right way to do it, great. I don't see any problem in using a get_custom_file_if_exists for a settings file.

I am not sufficiently familiar with the architecture at this point in the app to have a final opinion on this...

My only objection would be to replacing a superior customization scheme with an inferior one, if that was the case. For example, customizing single methods in controllers via the Extension Framework is easy, and shouldn't be replaced with a get_custom_file_if_exists of the entire controller file. As long as you check that none of your changes are of this kind, I'm fine with them 👍

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.

None yet

5 participants