Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
re2o
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nounous
re2o
Commits
0c7e944b
Commit
0c7e944b
authored
Apr 20, 2018
by
Maël Kervella
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add permission for API view
parent
6478a0ae
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
2 deletions
+29
-2
api/initial_perm.py
api/initial_perm.py
+17
-0
api/settings.py
api/settings.py
+6
-0
api/urls.py
api/urls.py
+1
-0
re2o/urls.py
re2o/urls.py
+5
-2
No files found.
api/initial_perm.py
0 → 100644
View file @
0c7e944b
from
django.contrib.contenttypes.models
import
ContentType
from
django.contrib.auth.models
import
Permission
from
django.conf
import
settings
api_content_type
,
created
=
ContentType
.
objects
.
get_or_create
(
app_label
=
settings
.
API_CONTENT_TYPE_APP_LABEL
,
model
=
settings
.
API_CONTENT_TYPE_MODEL
)
if
created
:
api_content_type
.
save
()
api_permission
,
created
=
Permission
.
objects
.
get_or_create
(
name
=
settings
.
API_PERMISSION_NAME
,
content_type
=
api_content_type
,
codename
=
settings
.
API_PERMISSION_CODENAME
)
if
created
:
api_permission
.
save
()
api/settings.py
View file @
0c7e944b
...
...
@@ -35,3 +35,9 @@ REST_FRAMEWORK = {
'api.permissions.DefaultACLPermission'
,
)
}
# API permission settings
API_CONTENT_TYPE_APP_LABEL
=
'api'
API_CONTENT_TYPE_MODEL
=
'api'
API_PERMISSION_NAME
=
'Can use the API'
API_PERMISSION_CODENAME
=
'use_api'
api/urls.py
View file @
0c7e944b
...
...
@@ -28,6 +28,7 @@ from django.conf.urls import url, include
from
rest_framework.routers
import
DefaultRouter
from
.
import
views
from
.
import
initial_perm
router
=
DefaultRouter
()
router
.
register
(
r
'users'
,
views
.
UserViewSet
)
...
...
re2o/urls.py
View file @
0c7e944b
...
...
@@ -42,6 +42,7 @@ Including another URLconf
"""
from
__future__
import
unicode_literals
from
django.conf
import
settings
from
django.conf.urls
import
include
,
url
from
django.contrib
import
admin
from
django.contrib.auth
import
views
as
auth_views
...
...
@@ -70,6 +71,8 @@ urlpatterns = [
r
'^preferences/'
,
include
(
'preferences.urls'
,
namespace
=
'preferences'
)
),
url
(
r
'^api/'
,
include
(
'api.urls'
,
namespace
=
'api'
)),
]
if
'api'
in
settings
.
INSTALLED_APPS
:
urlpatterns
+=
[
url
(
r
'^api/'
,
include
(
'api.urls'
,
namespace
=
'api'
)),
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment