-
Notifications
You must be signed in to change notification settings - Fork 140
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
Supporting custom 'EXPIRE_AFTER' value (use case: user-defined expiration value) #20
Conversation
I would suggest to redesign WARN_AFTER field or at least add alternative. Currently, you have to specify two values, but for me logically it looks better to have WARN_AFTER as delta of the expiration field in seconds or in percents. It will make user-specific autologout time easier to implement. |
@Sapphire64: having a single setting value serving two purposes not only makes it confusing but would also break backward compatibility. I'm pretty sure that @jpic: I'll add the unittests shortly. |
I think he was thinking about a scenario such as this:
In this case, If a multiplier such as |
@yscumc, @Sapphire64: I misread |
The problem with this PR is that JS side notifications will never work right. If custom value is less than warning from settings, user will not be redirected to login page, but all AJAX calls will fail. If custom value is larger user will be warned as usual and even redirected to login page without real reason. |
@Sapphire64: what is the current behavior when you set |
I'm not sure, but it looks like it will not show notification warning. Only front end whistle. But I realised another possible problem. UI will redirect user to login page after system's default logout value. If user's logout value is bigger this redirect will be understood on middleware level as user activity during active session. It means larger values will never work and logout will never occur. |
|
If it's a pre-existing issue, then I would prefer to push this PR through first and then have a follow-up PR to address that issue specifically. Does that sound fair, @yscumc & @Sapphire64? |
Well I wouldn't call it a pre-existing issue because normally, the The problem is when the Regardless of the above issue, I think that |
@yscumc: You're right, |
…om/user-defined use cases;All tests passed
…s an int and above 60 seconds
…used warnings though
EXPIRE_AFTER_CUSTOM_SESSION_KEY | ||
) | ||
|
||
if type(expire_after_value) == int and expire_after_value > 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isinstance, can it be float? Should we log somewhere that value is not valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make this change to use isinstance for int checking. I think fraction of second is an edge case at this point.
I've made two branches: I'm going to test my branches now. |
@Sapphire64: I made the change to the int checking to use
Last but not least, none of your changes in both branches actually pass tests (you're running into circular import problems). Try running tests on your local changes and of course you can always make a PR with your changes. |
@jpic: added test to middleware as you suggested. I think we should try to speed it up by lowering the setting values but perhaps it's for a follow up PR. To summarize my changes, I simply added a way for people to set an EXPIRE_AFTER per user session. Developers can simply hook to In supporting this use-case, I've also added I've attempted to only make changes where necessary. There are a couple more improvements I would suggest, but I'll keep those for separate future PRs. Just an aside, while running |
@VuongN thanks for checking, I published changes faster for you to check first. Do you think you should keep "business" logic inside of settings? |
Excellent work guys !! I submitted a fix for the circular import in @Sapphire64's master branch, but it didn't do the trick. All Python improvements are welcome in our codebase, I learnt great things by reviewing your code live Using the user_logged_in signal is really elegant BTW, although settings.py might not be the best place for business logic. It's funny how the WARN_BEFORE came back to life after 2 years: 130da20 It is gone because it made the codebase more complex and was not required, although it was intuitive. That said, here are my conclusions in terms of requirements:
Maybe it would all be easier if we moved all the logic in the middleware, then we could provide other middlewares and even mixins like Then you could choose the logic you want by choosing the midldeware you add to Sorry for the late reply, looking forward to read your feedback ! |
@jpic Great to hear from you, James :) thanks for checking my branch. Last time I was thinking that to make it good we need to follow some of the django's practices. We may create interface with probably few base methods: is_session_expired, update_activity. By implementing your own classes or by including standard .contrib. classes (like request.session code from @VuongN ) you will be able to parse request through different layers of session_security checks, like django does with middlewares. To include them we can add to options something like this:
By reading this options our code in def is_session_expired(self, request, current_time, last_activity_time): will loop through handlers and if any of them will return True we will exit and log user out. I've just imagined that by doing like this developers can attach all kinds of logic here: like if user didn't paid for subscription he will be logged out. But for this we need to think in advance about such things like custom warning templates and custom logout templates. We can attach them to that interface as a fields with value like expire_template_url='', warning_template_url=''. All ping requests should be provided to handler's implemented methods to make their own updates. Many of the things, requires lot of work, but I think that's the way to make this project real shine :) What do you think? |
Hi all, I'm really sorry but I merged the PR by mistake (actually I merged it locally a while ago, and started working on a maintainance release locally yesterday ...) and I had to revert the merge commit. Bummer ... I got the maintenance release out but the PR is definitely closed due to my mistake (merged locally then reverted merge commit). To be clear, it's not because your contributions were refused. As a matter of fact, all code improvements are welcome ! But it's better if they are submitted in one PR per topic. I will eventuelly get to cherry-pick code improvement commits but I can't right now: django-cities-light (which has a badass mysql bug to figure out) and django-autocomplete-light (which has 43 open issues and 12 prs ....) also need a maintenance release. Basically if you want to make it really easy to merge some of your changes immediatly and other later, it's better to make one PR per topic (why not try "feature branches" ?). Back to your use cases: django-session-security really needs an official hooking method, I'm thinking about #9 and #29 which also represent different use cases we have no reason not to support, but were not thought of during design of django-session-security. It's what I meant in my previous post:
Very important note for new features: it would be great to open an issue first and discuss implementation details before diving into actual code implementations. Again, I apologize for closing this PR by inadvertance and for my lack of time in general to find out a satisfying solution for all those cool use cases. Sincerely James |
@Sapphire64 Overall I agree with your last post, however:
I learnt from this dev process and I think we would need at least need a requirements and a design document for django-session-security 3.0. Any help will be appreciated ! Please try to keep topics as much isolated from each other as possible ;) |
I've summarized the guidelines we should follow to avoid such a debacle (partly caused by me, sorry !): http://docs.yourlabs.org/ It's hosted on rtfd/github so feel free to request changes. Also, if we're going to start all over for this PR, we should follow these guidelines to make it easier. Thanks B) |
@jpic hello there. So how can I help you now? Create new bug and start discussion? So you say that the kind of attachment I proposed is covered basically by django-signals? |
Hello @Sapphire64 , a discussion in a separate issue would be great, we've got to define the exact requirements for the new kind of attachement, which we could call something like "Plugin API" or something technical like that ;) |
No description provided.