Skip to content

[4.2] Add interfaces for the objects who need a user#37498

Merged
roland-d merged 21 commits intojoomla:4.2-devfrom
Digital-Peak:j4/user/current
May 30, 2022
Merged

[4.2] Add interfaces for the objects who need a user#37498
roland-d merged 21 commits intojoomla:4.2-devfrom
Digital-Peak:j4/user/current

Conversation

@laoneo
Copy link
Copy Markdown
Member

@laoneo laoneo commented Apr 6, 2022

Summary of Changes

As many classes need a user to check permissions or get an email address from it, there is no common way to get a current user instance. This pr introduces a new interface and trait to get/set a current user on an object. The identity aware trait offers a similar functionality but is intended to be used on applications only. But I'm open here for suggestions if we should reuse the identity trait or go with the approach in this pr.

Also I'm not sure about the name of the new interface or trait, also here open for suggestions.

This pr is mainly needed as @wilsonge doesn't want to inject the application into the models or views. If the app would be available, then we can just load the identity from it.

Testing Instructions

In the back end, open the articles list.

Actual result BEFORE applying this Pull Request

Works.

Expected result AFTER applying this Pull Request

Works.

@brianteeman
Copy link
Copy Markdown
Contributor

will you be replacing getIdentity everywhere?

@laoneo
Copy link
Copy Markdown
Member Author

laoneo commented Apr 7, 2022

Not really as this is different than getIdentity in terms of logic. GetIdentity is basically the identity of the application which comes from the authentication process. While this here can be anything where the view or model should work with. But as I said, I'm open here for suggestions as the similarities are very obvious.

@brianteeman
Copy link
Copy Markdown
Contributor

Just when I thought I understood the reason for this PR

@rdeutz
Copy link
Copy Markdown
Contributor

rdeutz commented May 11, 2022

Why not make a trait to get the application object and the go from there?

@laoneo
Copy link
Copy Markdown
Member Author

laoneo commented May 11, 2022

Don't think so it would be a good decision to pass around the application in whole core. Like that there is only a dependency to a simple user and not the app. It brings the benefit to be usable on places where no application is available.

@joomdonation
Copy link
Copy Markdown
Contributor

Here, the current user object will only be available in model if the model is created by our normal MVC workflow (users access to the component via web browser). What if model is created by by MVCFactory ? In this case, getCurrentUser() would return null and we will get error (fatal error or at least logical error). Am I right?

@laoneo
Copy link
Copy Markdown
Member Author

laoneo commented May 30, 2022

@joomdonation
Copy link
Copy Markdown
Contributor

That's not current user, but an empty user object?

@laoneo
Copy link
Copy Markdown
Member Author

laoneo commented May 30, 2022

After reading your comment a couple of times I think I do understand what you mean now. So when an extension is loading a model like $app->bootComponent('content')->getMVCFactory()->createModel('Article', 'Administrator') then the user is not the identity from the global application object. Is this what you mean? In this case I would probably fallback to Factory::getApplication()->getIdentity() here instead of an empty user and deprecate that usage for 5.

@joomdonation
Copy link
Copy Markdown
Contributor

Yes, that's what I wanted to say.

@roland-d
Copy link
Copy Markdown
Contributor

@laoneo We have a codestyle failure:

FILE: /********/src/libraries/src/User/CurrentUserTrait.php

----------------------------------------------------------------------

FOUND 1 ERROR AFFECTING 1 LINE

----------------------------------------------------------------------

 43 | ERROR | [x] No space found after comma in argument list

    |       |     (Generic.Functions.FunctionCallArgumentSpacing.NoSpaceAfterComma)

@roland-d
Copy link
Copy Markdown
Contributor

@joomdonation Is everything OK for you now on this PR?

@joomdonation
Copy link
Copy Markdown
Contributor

@roland-d The logical bug I concerned before is fixed with latest change, so it is fine now. The architecture change in this PR, right or wrong, I'm not qualify enough to say, sorry. So it's up to you to decide :D .

@roland-d roland-d merged commit d61a7c5 into joomla:4.2-dev May 30, 2022
@roland-d roland-d deleted the j4/user/current branch May 30, 2022 17:18
@roland-d
Copy link
Copy Markdown
Contributor

Thanks everybody

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants