? ? Pending

User tests: Successful: Unsuccessful:

avatar laoneo
laoneo
6 Apr 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.

avatar laoneo laoneo - open - 6 Apr 2022
avatar laoneo laoneo - change - 6 Apr 2022
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 6 Apr 2022
Category Administration com_content Libraries
avatar laoneo laoneo - change - 6 Apr 2022
The description was changed
avatar laoneo laoneo - edited - 6 Apr 2022
f173723 6 Apr 2022 avatar laoneo cs
avatar laoneo laoneo - change - 6 Apr 2022
Labels Added: ?
avatar brianteeman
brianteeman - comment - 7 Apr 2022

will you be replacing getIdentity everywhere?

avatar laoneo
laoneo - comment - 7 Apr 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.

avatar brianteeman
brianteeman - comment - 7 Apr 2022

Just when I thought I understood the reason for this PR

f29c086 19 Apr 2022 avatar laoneo tests
avatar joomla-cms-bot joomla-cms-bot - change - 19 Apr 2022
Category Administration com_content Libraries Administration com_content Libraries Unit Tests
avatar laoneo laoneo - change - 11 May 2022
Labels Added: ?
avatar rdeutz
rdeutz - comment - 11 May 2022

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

avatar laoneo
laoneo - comment - 11 May 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.

829d830 25 May 2022 avatar laoneo since
33dd209 25 May 2022 avatar laoneo cs
avatar joomla-cms-bot joomla-cms-bot - change - 26 May 2022
Category Administration com_content Libraries Unit Tests Administration com_content
avatar laoneo laoneo - change - 26 May 2022
Labels Removed: ?
avatar joomla-cms-bot joomla-cms-bot - change - 26 May 2022
Category Administration com_content Administration com_content Libraries Unit Tests
avatar laoneo laoneo - change - 26 May 2022
Labels Added: ?
avatar joomdonation
joomdonation - comment - 30 May 2022

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?

avatar joomdonation
joomdonation - comment - 30 May 2022

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

avatar laoneo
laoneo - comment - 30 May 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.

avatar joomdonation
joomdonation - comment - 30 May 2022

Yes, that's what I wanted to say.

avatar roland-d
roland-d - comment - 30 May 2022

@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)
5484ece 30 May 2022 avatar laoneo cs
avatar roland-d
roland-d - comment - 30 May 2022

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

avatar joomdonation
joomdonation - comment - 30 May 2022

@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 .

avatar roland-d roland-d - change - 30 May 2022
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2022-05-30 17:18:29
Closed_By roland-d
avatar roland-d roland-d - close - 30 May 2022
avatar roland-d roland-d - merge - 30 May 2022
avatar roland-d
roland-d - comment - 30 May 2022

Thanks everybody

Add a Comment

Login with GitHub to post a comment