Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GraceDB Server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Coughlin
GraceDB Server
Commits
c6851936
Commit
c6851936
authored
6 years ago
by
Tanner Prestegard
Committed by
GraceDB
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Add a user information API endpoint
parent
7fed56da
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gracedb/api/v1/main/serializers.py
+32
-0
32 additions, 0 deletions
gracedb/api/v1/main/serializers.py
gracedb/api/v1/main/views.py
+27
-0
27 additions, 0 deletions
gracedb/api/v1/main/views.py
gracedb/api/v1/urls.py
+4
-1
4 additions, 1 deletion
gracedb/api/v1/urls.py
with
63 additions
and
1 deletion
gracedb/api/v1/main/serializers.py
0 → 100644
+
32
−
0
View file @
c6851936
from
__future__
import
absolute_import
import
logging
from
django.conf
import
settings
from
django.contrib.auth
import
get_user_model
from
rest_framework
import
fields
,
serializers
# Set up user model
UserModel
=
get_user_model
()
# Set up logger
logger
=
logging
.
getLogger
(
__name__
)
class
UserSerializer
(
serializers
.
ModelSerializer
):
is_internal_user
=
fields
.
SerializerMethodField
(
read_only
=
True
)
#permissions = fields.SerializerMethodField(read_only=True)
class
Meta
:
model
=
UserModel
# Add permissions later. It will just be confusing now because
# they are not implemented properly for the events app.
fields
=
(
'
username
'
,
'
first_name
'
,
'
last_name
'
,
'
email
'
,
'
is_internal_user
'
,)
def
get_is_internal_user
(
self
,
obj
):
# Is the user in the LVC?
return
obj
.
groups
.
filter
(
name
=
settings
.
LVC_GROUP
).
exists
()
#def get_permissions(self, obj):
# return sorted(obj.get_all_permissions())
This diff is collapsed.
Click to expand it.
gracedb/api/v1/main/views.py
+
27
−
0
View file @
c6851936
...
...
@@ -4,6 +4,7 @@ from __future__ import absolute_import
import
logging
from
django.conf
import
settings
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth.models
import
Group
as
AuthGroup
from
django.http
import
HttpResponse
,
HttpResponseForbidden
...
...
@@ -13,15 +14,20 @@ from rest_framework.response import Response
from
rest_framework.reverse
import
reverse
as
drf_reverse
from
rest_framework.settings
import
api_settings
from
rest_framework.views
import
APIView
from
rest_framework.generics
import
RetrieveAPIView
from
api.utils
import
api_reverse
from
events.models
import
Group
,
Pipeline
,
Search
,
Tag
,
Label
,
EMGroup
,
\
VOEvent
,
EMBBEventLog
,
EMSPECTRUM
,
SignoffBase
from
events.view_logic
import
get_performance_info
from
superevents.models
import
Superevent
from
.serializers
import
UserSerializer
from
..mixins
import
InheritDefaultPermissionsMixin
from
..superevents.url_templates
import
construct_url_templates
# Set up user model
UserModel
=
get_user_model
()
# Set up logger
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -123,6 +129,7 @@ class GracedbRoot(APIView):
"
events
"
:
api_reverse
(
"
events:event-list
"
,
request
=
request
),
"
self
"
:
api_reverse
(
"
root
"
,
request
=
request
),
"
performance
"
:
api_reverse
(
"
performance-info
"
,
request
=
request
),
"
user-info
"
:
api_reverse
(
"
user-info
"
,
request
=
request
),
},
"
templates
"
:
templates
,
"
groups
"
:
[
group
.
name
for
group
in
Group
.
objects
.
all
()],
...
...
@@ -172,3 +179,23 @@ class PerformanceInfo(InheritDefaultPermissionsMixin, APIView):
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
return
Response
(
performance_info
,
status
=
status
.
HTTP_200_OK
)
class
UserInfoView
(
RetrieveAPIView
):
serializer_class
=
UserSerializer
#def get_serializer_class(self):
# # Override so we can use custom behavior for unauthenticated users
# if self.request.user.is_anonymous():
# return AnonymousUserSerializer
# else:
# return self.serializer_class
def
retrieve
(
self
,
request
,
*
args
,
**
kwargs
):
if
request
.
user
.
is_anonymous
():
output
=
{
'
username
'
:
'
AnonymousUser
'
}
else
:
instance
=
request
.
user
serializer
=
self
.
get_serializer
(
instance
)
output
=
serializer
.
data
return
Response
(
output
)
This diff is collapsed.
Click to expand it.
gracedb/api/v1/urls.py
+
4
−
1
View file @
c6851936
...
...
@@ -2,7 +2,7 @@ from __future__ import absolute_import
from
django.conf.urls
import
url
,
include
from
.main.views
import
GracedbRoot
,
PerformanceInfo
,
TagList
from
.main.views
import
GracedbRoot
,
PerformanceInfo
,
TagList
,
UserInfoView
urlpatterns
=
[
...
...
@@ -10,6 +10,9 @@ urlpatterns = [
# API root
url
(
r
'
^$
'
,
GracedbRoot
.
as_view
(),
name
=
"
root
"
),
# User information
url
(
r
'
^user-info/
'
,
UserInfoView
.
as_view
(),
name
=
'
user-info
'
),
# Tags
url
(
r
'
^tag/
'
,
TagList
.
as_view
(),
name
=
'
tag-list
'
),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment