Skip to content

[MIG][10.0] auth_session_timeout - #580

Merged
pedrobaeza merged 3 commits into
OCA:10.0from
LasLabs:release/10.0/auth_session_timeout
Nov 9, 2017
Merged

[MIG][10.0] auth_session_timeout#580
pedrobaeza merged 3 commits into
OCA:10.0from
LasLabs:release/10.0/auth_session_timeout

Conversation

@lasley

@lasley lasley commented Oct 21, 2016

Copy link
Copy Markdown
Contributor

WIP - I need to add test coverage for res.users

  • Bump versions
  • Installable to True
  • Add Usage section to ReadMe w/ Runbot link
  • _crypt_context now directly exposes the CryptContext
  • Change all instances of openerp to odoo
  • Add test coverage to IrConfigParameter

@lasley lasley added this to the 10.0 milestone Oct 21, 2016
@lasley lasley changed the title [MIG] password_security: Migrate to v10 [MIG][10.0] password_security Oct 21, 2016
@lasley lasley changed the title [MIG][10.0] password_security [MIG][10.0] auth_session_timeout Oct 21, 2016
@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch from 002d954 to e50a728 Compare October 21, 2016 01:52
@pedrobaeza pedrobaeza mentioned this pull request Oct 21, 2016
63 tasks
@@ -1,23 +0,0 @@
# Translation of Odoo Server.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza - I could have sworn I saw the removal of PO files from migrations somewhere, but I now can't remember where. Am I being stupid here, or are these actually supposed to be removed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove POT files, not PO ones. Having PO files, although outdated, allow to reuse the sentences that haven't changed. Next Transifex synchronization will wipe out the non existing terms comparing with the newest POT file.

@atchuthan proposed in OCA/maintainer-tools#232 that we should avoid the commits that updates the languages in the migration process, but I'm evaluating if this is a good idea at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation @pedrobaeza - I think that the issue that you linked is the one that made me think this way. I'll add back 😄

@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch 2 times, most recently from 41fd23c to 85182ac Compare October 21, 2016 18:47
@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch 7 times, most recently from bed5b78 to 9f80777 Compare October 21, 2016 21:32
@lasley

lasley commented Oct 21, 2016

Copy link
Copy Markdown
Contributor Author

Coverage added in all but res.users.check, which was going to be a real hassle. The logic is simple enough that I don't think it will be a problem.

Ready for review

@elicoidal elicoidal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Usage
=====

Setup the session parameters as described above.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to move the above section in this one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it, but I'm honestly torn. They are more of a configuration instruction vs usage. Maybe instead I add Use system like normal in place of the note to configure using instructions?

@moylop260

Copy link
Copy Markdown
Contributor

+1

@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch from 9f80777 to 3807cce Compare December 20, 2016 08:44
@lasley

lasley commented Dec 20, 2016

Copy link
Copy Markdown
Contributor Author

Good to merge?

@yajo yajo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little thing, not requirement.

_inherit = 'ir.config_parameter'

@api.model
@tools.ormcache(skiparg=0)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should be the cache key? skiparg is deprecated. Better use @tools.ormcache("self.env.db") IMHO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK so I'm a bit confused here & I am pretty sure this is what is causing the current error.

What are we going for with this cache? Do you maybe have an example of some other code that does something similar, or would mind giving a quick breakdown for me? My google-fu is turning up zilch here.

session = http.request.session
session_store = http.root.session_store
ConfigParam = http.request.env['ir.config_parameter']
delay, urls = ConfigParam.get_session_parameters(db)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for the db parameter anymore, right?

@lasley

lasley commented Dec 23, 2016

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews @yajo & @nilshamerlinck - both points fixed.

@yajo

yajo commented Dec 27, 2016

Copy link
Copy Markdown
Member

Bots still ❌

@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch from e914399 to 21e6177 Compare December 28, 2016 20:41
cr.close()
return delay, urls
@api.model
@tools.ormcache('self.env.db')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lasley, about #580 (comment) (I answer here so this does not get hidden)...

I learned the hard way to use ormcache when developing website_sale_wishlist. It turns out it's a pretty neat tool. It creates a key by the arguments you pass to it, and stores the method result in a cache attached to your current self.env, so further calls to the method return the cached result instead of executing the method again and again.

It's most useful when a method is CPU-expensive, is called quite often, and it returns a predictable result based on the incoming arguments/environment.

In old api, we had the skipargs, which was used to skip a number of arguments and use the rest to make a cache. For instance, if your method had cr, uid, ids, key, context=None and the result was the same no matter the cr, uid, you'd say skipargs=2.

Since v9, we have the new notation where you give the name of the arguments that form the cache key. Since self is always the first argument, you can use that one (and properties of it) to form a key.

When you change your env (like self.with_context(goal="I wanna be a pirate")), cache is empty. This is logical because a different context/cr/uid usually yields different results almost everywhere. However, when you apply cache to a method, it gets a clear_cache() method that you can use later to clear it without having to change your environment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the excellent explanation @yajo - this totally clarifies what we are going for here & I think points me in the right direction. I'll make the update soon 😄

@lasley

lasley commented Jan 28, 2017

Copy link
Copy Markdown
Contributor Author

Oops seems I forgot about this. With the excellent explanation @yajo gave regarding the cache, I abstracted that a decent replacement for the db arg we had previously is now self.cr.dbname.

It seems OCA/OCB just synced up with odoo/odoo though, so now we're red for other reasons. Oh the joy!

@chienandalu chienandalu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lasley Well, sorry for my part of contribution to this confusion...

Anyway, are you going to implement any of the changes made on #887 or #875?

@lasley

lasley commented Sep 6, 2017

Copy link
Copy Markdown
Contributor Author

Anyway, are you going to implement any of the changes made on #887 or #875?

I'm going to have to go through the diffs to understand the changes. I'm hoping maybe a cherry pick of some stuff will do it 😆

@pedrobaeza

Copy link
Copy Markdown
Member

@lasley can you finish this integrating #887 ?

@lasley

lasley commented Nov 3, 2017

Copy link
Copy Markdown
Contributor Author

Cherry picked. My bad, I forgot this

@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch from a331714 to 779c01a Compare November 3, 2017 19:06
@pedrobaeza

Copy link
Copy Markdown
Member

I'm getting this error installing this module:

Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/ir/ir_http.py", line 103, in _authenticate
    request.session.check_security()
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1058, in check_security
    security.check(self.db, self.uid, self.password)
  File "/opt/odoo/custom/src/odoo/odoo/service/security.py", line 13, in check
    return res_users.check(db, uid, passwd)
TypeError: unbound method check() must be called with res.users instance as first argument (got unicode instance instead)

@lasley

lasley commented Nov 6, 2017

Copy link
Copy Markdown
Contributor Author

Oops this also reminded me that some of these methods needed to be switched around now that we're not worrying about compat. I'll submit a fix in about 30m

@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch 2 times, most recently from f9aeace to 6c01b29 Compare November 6, 2017 16:42
@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch 2 times, most recently from 518bf14 to b1dfeb2 Compare November 6, 2017 18:08
@lasley

lasley commented Nov 6, 2017

Copy link
Copy Markdown
Contributor Author

Alright we're ready for a final review here, then I'll squash up

@yajo

yajo commented Nov 7, 2017

Copy link
Copy Markdown
Member

Still no luck with tests 😕

@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch from 8446a1a to ea711ff Compare November 7, 2017 15:38
@lasley

lasley commented Nov 7, 2017

Copy link
Copy Markdown
Contributor Author

Still no luck with tests 😕

Yeah got me dude. It seems we're fighting an uphill battle with Travis and I am damned close to just removing tests from multiple PRs until 🍏

@lasley

lasley commented Nov 7, 2017

Copy link
Copy Markdown
Contributor Author

Yup I've got nothing - it's failing on a bunch of modules unrelated to me. The option I see is to remove all tests from this module, but we obviously still have a timebomb on our hands.

From a global perspective, this is an issue I am encountering in numerous places. My immediate thought on a solution is that all modules should be tested independently from each other, instead of inline with each other. That covers up incompatibility problems though, so I'm at a loss.

@hbrunn

hbrunn commented Nov 7, 2017

Copy link
Copy Markdown
Member

exclude/include is no solution?

@lasley

lasley commented Nov 7, 2017

Copy link
Copy Markdown
Contributor Author

It is technically, but we've already done this in server-tools, so we're just N+1ing IMO. It's also damned near impossible to find the failing/conflicting module without a bunch of hunt/pecking with includes and excludes.

Biggest issue though is that only the first test case is available on Runbot, so we miss out on functional review of anything excluded.

@lasley

lasley commented Nov 7, 2017

Copy link
Copy Markdown
Contributor Author

Welp exclude is what I went with - better than removing tests. Thanks for reminding me that exists Holger.

Hopefully our server-tools split helps with this. Or our MQT redesign. Or something.

Furthermore, we are finally 🍏 (+1y1m later 😆 )

@yajo

yajo commented Nov 8, 2017

Copy link
Copy Markdown
Member

Yikes, It's not fun having tests that get broken when an addon is installed... Well, in any case could you squash the migration commits for merge?

lasley and others added 3 commits November 8, 2017 08:03
* Bump versions
* Installable to True
* Add Usage section to ReadMe w/ Runbot link
* `_crypt_context` now directly exposes the `CryptContext`
* Change all instances of openerp to odoo
* Add test coverage to IrConfigParameter
* Add test coverage for res.users
* Remove db from `get_session_parameters` method call
* Remove deprecated skiparg for ormcache
* Fix tests & lint
* Switch cache to use self.cr.dbname
* Fix ormcache
* Module auth_session_timeout:
---------------------------

* Refactor to allow other modules to inherit and augment or override the following:
** Session expiry time (deadline) calculation
** Ignored URLs
** Final session expiry (with possibility to late-abort)
* Re-ordered functionality to remove unnecessary work, as this code is called very often.
* Do not expire a session if delay gets set to zero (or unset / false)

* WIP

* Fixed flake8 lint errors

* Fixed flake8 lint errors

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* Module: auth-session-timeout: Refactor ResUser tests to use `unittest.mock` patching

* Module: auth_session_timeout: Fixed flake8 lint errors

* Module: auth_session_timeout: Fixed flake8 lint errors
* Deprecate backwards compatibility methods that were retained during v9 rework
* Upgrade API and rename a few things for PEP-8
* Switch to HttpCase for tests
* Switch to isolated build
@lasley
lasley force-pushed the release/10.0/auth_session_timeout branch from daad3fa to 00e7930 Compare November 8, 2017 16:04
@lasley

lasley commented Nov 8, 2017

Copy link
Copy Markdown
Contributor Author

Squashed!

@pedrobaeza
pedrobaeza merged commit cbf0747 into OCA:10.0 Nov 9, 2017
@lasley
lasley deleted the release/10.0/auth_session_timeout branch November 9, 2017 13:21
SiesslPhillip pushed a commit to grueneerde/OCA-server-tools that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-tools (13.0)
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.