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

Implement restricted pages and documents #319

Closed
wants to merge 2 commits into from

Conversation

fgrsnau
Copy link
Member

@fgrsnau fgrsnau commented Nov 28, 2016

Instead of only publishing a few minutes, we want to make all minutes available to our members. This merge request should prepare Sipa for this change by

  • introducing a restricted documents area where the authentication of the user is checked
  • introducing a new meta field that flags the FlatPage as restricted

Up to now I did the following:

  • Run the tests and see them pass
  • Rebase your branch on top of develop
  • Include tests for features you introduced / bugs you fixed

@fgrsnau fgrsnau changed the title Private minutes Implement restricted pages and documents Nov 28, 2016
All documents in the sub-directory “restricted/” will require the user
to be authenticated.
The commit introduces a new meta field “restricted”. If this field is
set to true, the user has to be authenticated for viewing this page.
@lukasjuhrich
Copy link
Collaborator

lukasjuhrich commented Nov 29, 2016

Since you asked in private on how to compose unittests, it goes along the lines of this:

from ..base import SampleFrontendTestBase


class RestrictedDocumentsUnauthorizedTestCase(SampleFrontendTestBase):
    def setUp(self):
        super().setUp()
        # here you can set up things and add attributes to taste


    def create_app(self, **kw):
        # here you can create a temporary directory with e.g. a global
        # file and one in a folder `restricted/`.
        conf = kw.pop('additional_config')
        conf = {
            **conf,
            # here you can update the apps config, i.e. add the document base
            'CONFIG_VAR': 'testing'
        }
        kw['additional_config'] = conf
        super().create_app(**kw, additional_config=conf)

    def login(self, username, password):
        """login `username` with `password`.

        This method doesn't actually belong in this test case, but I
        noticed that no test base provides either a login mechanism.

        The `sample` backend has a user with {'uid': 'test',
        'password': 'test'}.
        """
        pass

    def test_unauthorized_404(self):
        resp = self.client.get('/documents/restricted/foo')
        self.assert403(resp)  # or assertRedirects, depending on what is done

For an example of a login mechanism, see test_basic.py (which is actually unused, kek).
See also the reference of flask_testing to have an overview of the custom assert methods.

@lukasjuhrich
Copy link
Collaborator

Since I don't have permission to push to your branch, I rebased and developed further on origin/restricted-documents.

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.

2 participants