Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
598f6707
Commit
598f6707
authored
2 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Change how user data is get and subscribed
parent
55b74280
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/static/js/App.js
+12
-25
12 additions, 25 deletions
app/static/js/App.js
app/users/events.py
+44
-6
44 additions, 6 deletions
app/users/events.py
app/users/routes.py
+2
-8
2 additions, 8 deletions
app/users/routes.py
with
58 additions
and
39 deletions
app/static/js/App.js
+
12
−
25
View file @
598f6707
...
...
@@ -8,33 +8,20 @@ class App {
this
.
socket
.
on
(
'
PATCH
'
,
(
patch
)
=>
{
this
.
onPatch
(
patch
);});
}
getUser
(
userId
)
{
getUser
(
userId
,
backrefs
=
false
,
relationships
=
false
)
{
if
(
userId
in
this
.
data
.
promises
.
getUser
)
{
return
this
.
data
.
promises
.
getUser
[
userId
];
}
this
.
data
.
promises
.
getUser
[
userId
]
=
new
Promise
((
resolve
,
reject
)
=>
{
fetch
(
`/users/
${
userId
}
?backrefs=true&relationships=true`
,
{
headers
:
{
Accept
:
'
application/json
'
}})
.
then
(
(
response
)
=>
{
if
(
response
.
status
===
403
)
{
this
.
flash
(
'
Forbidden
'
,
'
error
'
);
reject
(
response
);}
return
response
.
json
();
},
(
response
)
=>
{
this
.
flash
(
'
Something went wrong
'
,
'
error
'
);
reject
(
response
);
}
)
.
then
(
(
user
)
=>
{
this
.
data
.
users
[
userId
]
=
user
;
resolve
(
this
.
data
.
users
[
userId
]);
},
(
error
)
=>
{
console
.
error
(
error
,
'
error
'
);
reject
(
error
);
}
);
this
.
socket
.
emit
(
'
GET /users/<user_id>
'
,
userId
,
backrefs
,
relationships
,
(
response
)
=>
{
if
(
response
.
status
!==
200
)
{
reject
(
response
);
return
;
}
this
.
data
.
users
[
userId
]
=
response
.
body
;
resolve
(
this
.
data
.
users
[
userId
]);
});
});
return
this
.
data
.
promises
.
getUser
[
userId
];
...
...
@@ -47,11 +34,11 @@ class App {
this
.
data
.
promises
.
subscribeUser
[
userId
]
=
new
Promise
((
resolve
,
reject
)
=>
{
this
.
socket
.
emit
(
'
SUBSCRIBE /users/<user_id>
'
,
userId
,
(
response
)
=>
{
if
(
response
.
code
===
200
)
{
resolve
(
response
);
}
else
{
if
(
response
.
status
!==
200
)
{
reject
(
response
);
return
;
}
resolve
(
response
);
});
});
...
...
This diff is collapsed.
Click to expand it.
app/users/events.py
+
44
−
6
View file @
598f6707
...
...
@@ -5,17 +5,55 @@ from app.decorators import socketio_login_required
from
app.models
import
User
@socketio.on
(
'
GET /users/<user_id>
'
)
@socketio_login_required
def
get_user
(
user_hashid
,
backrefs
=
False
,
relationships
=
False
):
user_id
=
hashids
.
decode
(
user_hashid
)
user
=
User
.
query
.
get
(
user_id
)
if
user
is
None
:
return
{
'
status
'
:
404
,
'
statusText
'
:
'
Not found
'
}
if
not
(
user
==
current_user
or
current_user
.
is_administrator
):
return
{
'
status
'
:
403
,
'
statusText
'
:
'
Forbidden
'
}
return
{
'
body
'
:
user
.
to_json_serializeable
(
backrefs
=
backrefs
,
relationships
=
relationships
),
'
status
'
:
200
,
'
statusText
'
:
'
OK
'
,
}
# @socketio.on('GET /users/<user_id>')
# @socketio_login_required
# def get_user(user_hashid):
# user_id = hashids.decode(user_hashid)
# user = User.query.get(user_id)
# if user is None:
# return {'options': {'status': 404, 'statusText': 'Not found'}}
# if not (user == current_user or current_user.is_administrator):
# return {'options': {'status': 403, 'statusText': 'Forbidden'}}
# return {
# 'body': user.to_json_serializable2(),
# 'options': {
# 'status': 200,
# 'statusText': 'OK',
# 'headers': {'Content-Type: application/json'}
# }
# }
@socketio.on
(
'
SUBSCRIBE /users/<user_id>
'
)
@socketio_login_required
def
subscribe_user
(
user_hashid
):
user_id
=
hashids
.
decode
(
user_hashid
)
user
=
User
.
query
.
get
(
user_id
)
if
user
is
None
:
return
{
'
code
'
:
404
,
'
msg
'
:
'
Not found
'
}
return
{
'
status
'
:
404
,
'
statusText
'
:
'
Not found
'
}
if
not
(
user
==
current_user
or
current_user
.
is_administrator
):
return
{
'
code
'
:
403
,
'
msg
'
:
'
Forbidden
'
}
return
{
'
status
'
:
403
,
'
statusText
'
:
'
Forbidden
'
}
join_room
(
f
'
/users/
{
user
.
hashid
}
'
)
return
{
'
code
'
:
200
,
'
msg
'
:
'
OK
'
}
return
{
'
status
'
:
200
,
'
statusText
'
:
'
OK
'
}
@socketio.on
(
'
UNSUBSCRIBE /users/<user_id>
'
)
...
...
@@ -24,8 +62,8 @@ def unsubscribe_user(user_hashid):
user_id
=
hashids
.
decode
(
user_hashid
)
user
=
User
.
query
.
get
(
user_id
)
if
user
is
None
:
return
{
'
code
'
:
404
,
'
msg
'
:
'
Not found
'
}
return
{
'
status
'
:
404
,
'
statusText
'
:
'
Not found
'
}
if
not
(
user
==
current_user
or
current_user
.
is_administrator
):
return
{
'
code
'
:
403
,
'
msg
'
:
'
Forbidden
'
}
return
{
'
status
'
:
403
,
'
statusText
'
:
'
Forbidden
'
}
leave_room
(
f
'
/users/
{
user
.
hashid
}
'
)
return
{
'
code
'
:
200
,
'
msg
'
:
'
OK
'
}
return
{
'
status
'
:
200
,
'
statusText
'
:
'
OK
'
}
This diff is collapsed.
Click to expand it.
app/users/routes.py
+
2
−
8
View file @
598f6707
from
flask
import
abort
,
current_app
,
request
from
flask
import
abort
,
current_app
from
flask_login
import
current_user
,
login_required
from
threading
import
Thread
from
app
import
db
...
...
@@ -9,13 +9,7 @@ from . import bp
@bp.route
(
'
/<hashid:user_id>
'
)
@login_required
def
user
(
user_id
):
user
=
User
.
query
.
get_or_404
(
user_id
)
if
not
(
user
==
current_user
or
current_user
.
is_administrator
()):
abort
(
403
)
backrefs
=
request
.
args
.
get
(
'
backrefs
'
,
'
false
'
).
lower
()
==
'
true
'
relationships
=
(
request
.
args
.
get
(
'
relationships
'
,
'
false
'
).
lower
()
==
'
true
'
)
return
user
.
to_json_serializeable
(
backrefs
=
backrefs
,
relationships
=
relationships
),
200
abort
(
503
)
@bp.route
(
'
/<hashid:user_id>
'
,
methods
=
[
'
DELETE
'
])
...
...
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