Skip to content
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

Ks 2022 01 store token in session #4134

Merged
merged 5 commits into from
Jan 7, 2022

Conversation

Rineee
Copy link
Contributor

@Rineee Rineee commented Jan 4, 2022

This now stores the token itself in the session instead of its pk which is probably safer!

When there are several modules with possible tokens, the token form is shown if the token in the session is not valid for this module. Once another token is entered, this one is saved and the old one removed. When testing this (so you entered a token in module 2 and want to make sure that the token in module 1 is removed), be careful that you dont just reload the page, because that will resend the token form in module 1 and thus the old token is there again. Hope that makes sense 🙈

This behaviour is not ideal, but I guess fine for an itenmediate step?

@github-actions
Copy link

github-actions bot commented Jan 4, 2022

Coverage report

Total coverage

Status Category Percentage Covered / Total
🔴 Statements 9.11% 153/1679
🔴 Branches 7.01% 69/984
🔴 Functions 9.52% 52/546
🔴 Lines 13.83% 697/5040

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Report generated by 🧪jest coverage report action from cb763fe

Copy link
Contributor

@fuzzylogic2000 fuzzylogic2000 left a comment

Choose a reason for hiding this comment

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

Looks good!
So, now the token is only shown when it matches the module? And when I go to another budgeting, the token is not shown, but overwritten when I add a new one? I will try that out!

Copy link
Contributor

@fuzzylogic2000 fuzzylogic2000 left a comment

Choose a reason for hiding this comment

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

I get an error, when I add a proposal while the voting phase is active. Probably not because of this PR. Will investigate later and also maybe still merge as that is an admin-edge-case anyway.



Template error:
In template /home/katharina/a4-meinberlin/meinberlin/templates/base.html, error at line 0
   local variable 'token' referenced before assignment
   1 : <!DOCTYPE html>
   2 : {% load i18n static contrib_tags wagtailuserbar %}
   3 : {% get_current_language as LANGUAGE_CODE %}
   4 : <html lang="{{ LANGUAGE_CODE }}">
   5 : <head>
   6 :     <meta charset="utf-8" />
   7 :     <meta http-equiv="X-UA-Compatible" content="IE=edge" />
   8 :     <title>{% block title %}{% trans 'meinBerlin' %}{% endblock %}</title>
   9 :     <link rel="shortcut icon" type="image/x-icon" href="{% static 'images/favicon.ico' %}?v=2" />
   10 :     {% block extra_css %}


Traceback (most recent call last):
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 204, in _get_response
    response = response.render()
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/test/utils.py", line 100, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/test/utils.py", line 100, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/test/utils.py", line 100, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/test/utils.py", line 100, in instrumented_test_render
    return self.nodelist.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/defaulttags.py", line 312, in render
    return nodelist.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/defaulttags.py", line 312, in render
    return nodelist.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/home/katharina/a4-meinberlin/venv/lib/python3.8/site-packages/django/template/library.py", line 192, in render
    output = self.func(*resolved_args, **resolved_kwargs)
  File "/home/katharina/a4-meinberlin/meinberlin/apps/budgeting/templatetags/react_proposals_vote.py", line 40, in react_proposals_vote
    serializer = VotingTokenSerializer(token)

Exception Type: UnboundLocalError at /budgeting/2022-00040/
Exception Value: local variable 'token' referenced before assignment

@Rineee
Copy link
Contributor Author

Rineee commented Jan 5, 2022

@fuzzylogic2000 Oh no, I think the problem is, that I was only handling the API View, but not the normal list view with the form.. so I'll look into it!

@Rineee Rineee changed the title Ks 2022 01 store token in session WIP Ks 2022 01 store token in session Jan 5, 2022
@fuzzylogic2000
Copy link
Contributor

@fuzzylogic2000 Oh no, I think the problem is, that I was only handling the API View, but not the normal list view with the form.. so I'll look into it!

@Rineee I found out more: it happens when there is a token in the session and you try to add a proposal in another module not belonging to that token.

@Rineee Rineee force-pushed the ks-2022-01-store-token-in-session branch from bf557b5 to cb763fe Compare January 7, 2022 10:18
@Rineee Rineee changed the title WIP Ks 2022 01 store token in session Ks 2022 01 store token in session Jan 7, 2022
@Rineee
Copy link
Contributor Author

Rineee commented Jan 7, 2022

Looks good! So, now the token is only shown when it matches the module? And when I go to another budgeting, the token is not shown, but overwritten when I add a new one? I will try that out!

Now it should be like that, yes! See updated PR description :)

@Rineee
Copy link
Contributor Author

Rineee commented Jan 7, 2022

@fuzzylogic2000 Oh no, I think the problem is, that I was only handling the API View, but not the normal list view with the form.. so I'll look into it!

@Rineee I found out more: it happens when there is a token in the session and you try to add a proposal in another module not belonging to that token.

@fuzzylogic2000 The error should be fixed by commit 4!

@Rineee Rineee requested a review from fuzzylogic2000 January 7, 2022 10:28
Copy link
Contributor

@fuzzylogic2000 fuzzylogic2000 left a comment

Choose a reason for hiding this comment

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

Supercool!

@fuzzylogic2000 fuzzylogic2000 merged commit a162d02 into main Jan 7, 2022
@fuzzylogic2000 fuzzylogic2000 deleted the ks-2022-01-store-token-in-session branch January 7, 2022 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants