[MIG] auth_session_timeout: Migration to 10.0 - #875
Conversation
…r informations in README.rst - Import from same package on same line - Use CamelCase for class names
2d41a9a to
a848e87
Compare
yajo
left a comment
There was a problem hiding this comment.
Code needs a small refactor to make it more maintaiable 😉
| _inherit = 'ir.config_parameter' | ||
|
|
||
| @api.model | ||
| @tools.ormcache(skiparg=0) |
There was a problem hiding this comment.
Don't use skiparg, it's kept for backwards compatibility, but the new and preferred way of caching is by argument names.
In any case, IMHO this whole file is not needed. You should just use Odoo's native get_param method, which already has caching enabled.
| with registry(db).cursor() as cr: | ||
| env = Environment(cr, SUPERUSER_ID, {}) | ||
| param_obj = env['ir.config_parameter'] | ||
| delay, urls = param_obj.get_session_parameters(db) |
There was a problem hiding this comment.
Again, you'll have to change this for 2 calls to ir.config_parameter.get_param if you delete ir_config_parameter.py file as suggested above.
| @classmethod | ||
| def check(cls, db, uid, passwd): | ||
| res = super(ResUsers, cls).check(db, uid, passwd) | ||
| cls._check_session_validity(db, uid, passwd) |
There was a problem hiding this comment.
Why not just move all the code from _check_session_validity into this method? After all this one does nothing more...
Or even better, why not move these checks into check_credentials? That one is a normal method (not a @classmethod) and has a working self.env to work with.
|
@yajo Look at it now. Some notes:
|
| 'author': "ACSONE SA/NV, " | ||
| "Tecnativa, " | ||
| "Odoo Community Association (OCA)", | ||
| 'website': 'https://www.tecnativa.com', |
| <?xml version='1.0' encoding='UTF-8' ?> | ||
| <odoo> | ||
|
|
||
| <data noupdate="1"> |
There was a problem hiding this comment.
Why 2 data noupdate? Put all in the first tag (<odoo noupdate="1">)
| return | ||
| session = request.session | ||
| session_store = root.session_store | ||
| ipm = self.env['ir.config_parameter'] |
There was a problem hiding this comment.
You have removed the other model and it was introduced for having a cache mechanism to not query so many times the DB, so please restore it as it was.
There was a problem hiding this comment.
It was @yajo 's request, given that get_param has already a cached mechanism at its core: https://github.com/odoo/odoo/blob/10.0/odoo/addons/base/ir/ir_config_parameter.py#L53-L68
There was a problem hiding this comment.
OK, I see. Then it's enough indeed. Maybe it would be good to throw a comment saying that this is cached, so no performance penalty...
| if getmtime(path) < deadline: | ||
| if session.db and session.uid: | ||
| session.logout(keep_db=True) | ||
| elif http.request.httprequest.path not in urls: |
There was a problem hiding this comment.
This is totally wrong (not your fault, as it was the same on v8), but the intended behavior for this is not achieved here:
- This should be checked before doing anything. See that if the request has been inactive, you'll get logout anyway.
- What you have to check is if one of the ignored path keys (variable
urls) is not included in current http request, so the code should be something similar to:if any([url in http.request.httprequest.path for x in urls]): return
b77a623 to
3cdb809
Compare
|
@pedrobaeza Changes done |
| deadline = time() - delay | ||
| path = session_store.get_session_filename(session.sid) | ||
| try: | ||
| if any([url in http.request.httprequest.path for url in urls]): |
There was a problem hiding this comment.
Sorry, this is incorrect for 2 reasons:
- Performance-wise, doing
any([... for ...])makes the generator be converted in a list and then iterated again under theany. You can save several iterations by just dropping the[]characters. Not critical here since the list will be short, but keep it in mind. - If you have
/longpolling,/shop, then a request to/blog/longpolling-is-your-friendwill give a false positive.
Instead of this, do:
if any(map(http.request.httprequest.path.startswith, urls)):|
@yajo @pedrobaeza Changes done |
| self.ipm.set_param(DELAY_KEY, 1) | ||
| res = self.rus.authenticate(self.db, 'admin', 'admin', {}) | ||
| time.sleep(1.1) | ||
| res = self.rus.browse(res).check(self.db, res, 'admin') |
There was a problem hiding this comment.
You are actually not checking here anything, and you also don't have any request. Better to put that this is a TODO and include in "Known issues" to finish tests. Or @yajo, do you have a quick suggestion for testing this?
There was a problem hiding this comment.
To have full coverage, you can either mock the session or authenticate through an HttpCase.
Also, after this code (that checks you are OK), I'd try mocking also the method that checks if the session time is old to make it think it is, and then check that you are kicked off.
There was a problem hiding this comment.
I've commited a test with HttpCase but I still don't get a request. Can you provide an example to use as a guideline?
There was a problem hiding this comment.
Yes, you need to authenticate through an http request to get a working request (redundant, but that's it). Check this out: https://github.com/odoo/odoo/blob/10.0/odoo/tests/common.py#L270
There was a problem hiding this comment.
@yajo I still can't see how to do such request 😕
There was a problem hiding this comment.
Yes, it's what I tried in my last commit: https://github.com/Tecnativa/server-tools/blob/c32b5308088e736c2347965276235a6c1878287d/inactive_session_timeout/tests/test_inactive_session.py#L24
| return | ||
|
|
||
| @classmethod | ||
| def check(cls, db, uid, passwd): |
There was a problem hiding this comment.
Do not override this method. Override check_credentials. Raise an AccessDenied if the session is expired.
There was a problem hiding this comment.
No, the idea is to return to logout, disauthorizing future operations and returning to login
| self.assertTrue(self.ipm.get_param(DELAY_KEY), 1) | ||
| self.authenticate('admin', 'admin') | ||
| time.sleep(1.1) | ||
| res = self.rus.browse(1).check(self.db, 1, 'admin') |
There was a problem hiding this comment.
Assert that this should raise a AccessDenied exception
|
I have just found that the module was renamed to |
|
See also #887 |
|
@pedrobaeza Implemented some of the good ideas of #887 |
|
IMO we should complete #887 before a merge of this one just so we make sure we have a proper migration path |
|
Well, if this one includes the changes of that PR, we assure migration path, isn't it? |
|
This is true, however there were some PR review recommendations that I don't think were attended to here. Reviewing and modifying in two PRs seems like duplicating effort IMO (even though I'm totally guilty of submitting multiple active PRs against the same module, so kettle calling the pot black here). Also, the commit wasn't cherry picked so we've lost attribution + I'm not entirely certain which aspects of #887 were retained because the commit is squashed into another logical one & the comment noted that only some of the good ideas were implemented. |
|
OK, please try to speed up the other PR and we will wait for this. |
|
Hi, @lasley. Maybe the confusion has been originated because I didn't realize in first place that there was an already migrated version on v9. So now they have diverged quite a bit. From the last PR, I took the idea of split some of functionalities into separate methods and adapted it to my existing code. Although I've got no objection in giving fair attribution. Anyway I'll wait until the PR is fully reviewed 😃 👍 |
|
Closing in favor of #580 |
|
😆 did I seriously review a module that I also had an open PR for? whoops |
Syncing from upstream OCA/server-tools (15.0)
Auth Session Timeout
This module was written to be able to kill (logout) all inactive sessions since
a given delay. On each request the server checks if the session is yet valid
regarding the expiration delay. If not a clean logout is operated.
cc @Tecnativa