Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rights Engine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Polaris
Rights Engine
Commits
64240536
Commit
64240536
authored
2 years ago
by
Max Lou
Browse files
Options
Downloads
Patches
Plain Diff
Fix: random statement generator and LRS forwarding
parent
c487237d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
backend/xapi/views.py
+12
-7
12 additions, 7 deletions
backend/xapi/views.py
tools/xapi-statement-generator/generator.py
+1
-2
1 addition, 2 deletions
tools/xapi-statement-generator/generator.py
with
13 additions
and
9 deletions
backend/xapi/views.py
+
12
−
7
View file @
64240536
...
...
@@ -17,10 +17,10 @@ TOKEN = settings.LRS.get('TOKEN')
def
store_in_lrs
(
x_api_statement
):
header
=
{
"
Authorization
"
:
f
"
Basic
{
TOKEN
}
"
,
"
X-Experience-API-Version
"
:
"
1.0.3
"
}
response
=
requests
.
post
(
URL
,
json
=
x_api_statement
,
response
=
requests
.
post
(
f
'
{
URL
}
/data/xAPI/statements
'
,
json
=
x_api_statement
,
headers
=
header
)
print
(
response
.
content
)
return
response
.
ok
class
CreateStatement
(
APIView
):
...
...
@@ -33,7 +33,8 @@ class CreateStatement(APIView):
except
ObjectDoesNotExist
:
return
JsonResponse
({
"
message
"
:
"
No consent provider available.
"
},
safe
=
False
,
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
for
provider
in
latest_consent
.
definition
:
essential_verbs
.
extend
([
verb
[
"
id
"
]
for
verb
in
provider
[
"
essentialVerbs
"
]])
essential_verbs
.
extend
([
verb
[
"
id
"
]
for
verb
in
provider
[
"
essentialVerbs
"
]])
# validate statement
if
(
not
"
actor
"
in
request
.
data
)
or
(
not
"
mbox
"
in
request
.
data
[
"
actor
"
])
or
(
not
request
.
data
[
"
actor
"
][
"
mbox
"
].
startswith
(
"
mailto:
"
)):
...
...
@@ -62,7 +63,8 @@ class CreateStatement(APIView):
return
JsonResponse
({
"
message
"
:
'
discarded. User has paused data collection
'
},
status
=
status
.
HTTP_200_OK
)
# has the user given consent to this verb?
user_consent
=
UserConsents
.
objects
.
filter
(
user
=
user
,
verb
=
verb
,
consented
=
True
).
first
()
user_consent
=
UserConsents
.
objects
.
filter
(
user
=
user
,
verb
=
verb
,
consented
=
True
).
first
()
if
not
user_consent
:
return
JsonResponse
({
"
message
"
:
'
error. User has not given consent to this verb
'
},
status
=
status
.
HTTP_403_FORBIDDEN
)
...
...
@@ -70,7 +72,7 @@ class CreateStatement(APIView):
# has the user given consent to the object at hand?
object_consent
=
False
verb_objects
=
json
.
loads
(
user_consent
.
object
)
if
not
verb_objects
:
# no objects defined, "consent" by default
if
not
verb_objects
:
# no objects defined, "consent" by default
object_consent
=
True
else
:
for
obj
in
verb_objects
:
...
...
@@ -80,5 +82,8 @@ class CreateStatement(APIView):
if
not
object_consent
:
return
JsonResponse
({
"
message
"
:
'
error. User has not given consent to this object
'
},
status
=
status
.
HTTP_403_FORBIDDEN
)
store_in_lrs
(
request
.
data
)
return
JsonResponse
({
"
message
"
:
'
processed
'
},
status
=
status
.
HTTP_200_OK
)
response_ok
=
store_in_lrs
(
request
.
data
)
if
response_ok
:
return
JsonResponse
({
"
message
"
:
'
processed
'
},
status
=
status
.
HTTP_200_OK
)
else
:
return
JsonResponse
({
"
message
"
:
'
LRS request failed
'
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
This diff is collapsed.
Click to expand it.
tools/xapi-statement-generator/generator.py
+
1
−
2
View file @
64240536
...
...
@@ -91,12 +91,11 @@ def get_rand_statement():
def
start_random_generation
(
args
):
random_statement
=
get_rand_statement
()
url
=
args
.
target
[
0
]
print
(
'
Running...
'
)
while
True
:
send_x_api_statement
(
url
,
rand
om
_statement
)
send_x_api_statement
(
url
,
get_
rand_statement
()
)
time
.
sleep
(
1
)
...
...
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