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

views: access control #18

Merged
merged 3 commits into from
Jan 18, 2016
Merged

Conversation

nharraud
Copy link
Member

@nharraud nharraud commented Dec 3, 2015

Signed-off-by: Nicolas Harraudeau [email protected]

@nharraud nharraud changed the title global: views: access control views: access control Dec 3, 2015
@nharraud nharraud added this to the v1.0.0 milestone Dec 3, 2015
self._update_permission_factory = None
self._delete_permission_factory = None

@property
Copy link
Member

Choose a reason for hiding this comment

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

IMHO it can be werkzeug.utils:cached_property

@jirikuncar jirikuncar assigned nharraud and unassigned lnielsen Dec 3, 2015
$ curl -XPOST http://localhost:5000/login -d 'email=admin%40invenio-software.org&password=123456' -c mycookie
$ curl -XGET http://localhost:5000/records/1 -b mycookie

Login as [email protected] (password 123456), hwo has not
Copy link
Member

Choose a reason for hiding this comment

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

hwo -> who

@nharraud
Copy link
Member Author

nharraud commented Dec 3, 2015

@lnielsen @jirikuncar One thing you can see in the code but which I forgot to mention is that the tests and example use the UI login as we don't have oauth yet. As the search-ui will be also use cookie authentication to access this REST API this seemed a valid usage even if not the most common.

@jirikuncar
Copy link
Member

@nharraud both OAuthClient and OAuth2Server should be ready on GitHub (not PyPI yet).

@nharraud
Copy link
Member Author

nharraud commented Dec 4, 2015

@jirikuncar Sorry I meant Application Token. There is no need for an OAuth authentication here. Using an application token added directly to the database would remove the dependency on UI login.
Do we have any module for that right now?

@nharraud nharraud force-pushed the access_control branch 4 times, most recently from 93d39c6 to b60b025 Compare December 9, 2015 09:16
@nharraud
Copy link
Member Author

Coverage decreased because I added the delete permission factory methods even though there is no delete method implemented yet.

@nharraud nharraud assigned jirikuncar and unassigned nharraud Dec 14, 2015
@jirikuncar jirikuncar assigned nharraud and unassigned jirikuncar Dec 16, 2015
@nharraud
Copy link
Member Author

nharraud commented Jan 7, 2016

@jirikuncar can we release a new version of invenio-rest? This depends on the last commits.

@nharraud nharraud force-pushed the access_control branch 2 times, most recently from b16c6d2 to 8c70ec8 Compare January 11, 2016 13:53
@nharraud nharraud assigned jirikuncar and unassigned nharraud Jan 11, 2016
@nharraud
Copy link
Member Author

@jirikuncar I removed the example with permissions, removed default permission factories and copied permissions.py from invenio_records for the tests. Ready for merge.

try:
record.delete()
# mark all PIDs as DELETED
all_pids = PersistentIdentifier.query \
Copy link
Member

Choose a reason for hiding this comment

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

IMHO you can use only one call of .filter() (or db.and_(cond1, cond2)).

all_pids = PersistentIdentifier.query.filter(
    PersistentIdentifier.object_type == pid.object_type,
    PersistentIdentifier.object_uuid == pid.object_uuid
).all()

@nharraud nharraud force-pushed the access_control branch 2 times, most recently from 1c38793 to 4bd5968 Compare January 12, 2016 16:19
"""Load default read permission factory."""
if self._read_permission_factory is None:
imp = self.app.config[
"RECORDS_REST_DEFAULT_READ_PERMISSION_FACTORY"
Copy link
Member

Choose a reason for hiding this comment

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

It is not critical, but can you use single quotes (') for strings for consistency with rest of the code. They are randomly mixed (") through the code also in other files. Thanks

Copy link
Member Author

Choose a reason for hiding this comment

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

@jirikuncar Yes you are right. Can I fix that in the next pull request (search integration) so that I don't spend too much time rebasing?

Copy link
Member

Choose a reason for hiding this comment

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

IMHO it's not so much pain to run search&replace. You won't have many conflicts when you rebase other branches.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok. Is there a guideline for quotes in Invenio? I think we should also fix the cookie cutter as it is putting " in some places.

Copy link
Member

Choose a reason for hiding this comment

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

Just use your judgement and be consistent. When in doubt, be consistent with the surrounding code.

@nharraud nharraud force-pushed the access_control branch 3 times, most recently from 89666b1 to 5efe984 Compare January 15, 2016 15:49
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this file as its usage is discouraged with py.test.

avoid “init.py” files in your test directories. This way your tests can run easily against an installed version of mypkg, independently from the installed package if it contains the tests or not.

source https://pytest.org/latest/goodpractises.html

@jirikuncar
Copy link
Member

  • Update copyright year in all files you have touched in this PR. Thanks

Nicolas Harraudeau added 3 commits January 18, 2016 09:43
* NEW Adds customizable access control to record views. Allow
  configuring different permissions per endpoint. (addresses inveniosoftware#14)

Signed-off-by: Nicolas Harraudeau <[email protected]>
* NEW Adds DELETE support to the records REST API.

Signed-off-by: Nicolas Harraudeau <[email protected]>
Signed-off-by: Nicolas Harraudeau <[email protected]>
@nharraud
Copy link
Member Author

@jirikuncar Done. Only the .gitignore has not been updated as I didn't see copyrights in other projects either.

@jirikuncar jirikuncar merged commit 0160301 into inveniosoftware:master Jan 18, 2016
@nharraud nharraud deleted the access_control branch February 2, 2017 13:53
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.

3 participants