Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
  • Loading branch information
giovannicimolin committed Sep 8, 2020
1 parent f427d5b commit 3a8aec4
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 21 deletions.
3 changes: 2 additions & 1 deletion lti_consumer/lti_1p3/ags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
LTI Advantage Assignments and Grades service implementation
"""


class LtiAgs:
"""
LTI Advantage Consumer
Expand Down Expand Up @@ -72,4 +73,4 @@ def get_lti_ags_launch_claim(self):
if self.lineitem_url:
ags_claim.update({"lineitem": self.lineitem_url})

return ags_claim
return ags_claim
7 changes: 6 additions & 1 deletion lti_consumer/lti_1p3/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@
"scope",
])

LTI_1P3_ACCESS_TOKEN_SCOPES = []

LTI_1P3_ACCESS_TOKEN_SCOPES = [
# LTI-AGS Scopes
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
]


class LTI_1P3_CONTEXT_TYPE(Enum): # pylint: disable=invalid-name
Expand Down
4 changes: 4 additions & 0 deletions lti_consumer/lti_1p3/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class TokenSignatureExpired(Lti1p3Exception):
pass


class UnauthorizedToken(Lti1p3Exception):
pass


class NoSuitableKeys(Lti1p3Exception):
pass

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ def authenticate(self, request):
raise exceptions.AuthenticationFailed(msg)

# Verify token validity
import pdb; pdb.set_trace()

# This doesn't validate specific permissions, just checks if the token
# is valid or not.
try:
lti_consumer.check_token(auth[1])
# Attach token to request to be used to check permissions later
request.lti_auth_token = auth[1]
except:
msg = _('LTI configuration not found.')
raise exceptions.AuthenticationFailed(msg)

# Passing parameters back to the view through the request.
# Not exactly optimal.
Expand All @@ -50,4 +57,4 @@ def authenticate(self, request):

# Return (None, None) since this isn't tied to any authentication
# backend on Django, and it's just used for LTI endpoints.
return (None, None)
return (None, None)
File renamed without changes.
29 changes: 29 additions & 0 deletions lti_consumer/lti_1p3/extensions/rest_framework/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from rest_framework import permissions

from lti_consumer.lti_1p3 import exceptions


class LtiAgsPermissions(permissions.BasePermission):
def has_permission(self, request, view):
if view.action in ['list', 'retrieve']:
try:
request.lti_consumer.check_token(
request.lti_auth_token,
[
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem.readonly',
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem',
],
)
return True
except exceptions.UnauthorizedToken:
return False
elif view.action in ['create', 'update', 'partial_update', 'delete']:
try:
request.lti_consumer.check_token(
request.lti_auth_token,
'https://purl.imsglobal.org/spec/lti-ags/scope/lineitem'
)
return True
except exceptions.UnauthorizedToken:
return False
return False
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ class LineItemsRenderer(renderers.JSONRenderer):

class LineItemRenderer(renderers.JSONRenderer):
media_type = 'application/vnd.ims.lis.v2.lineitem+json'
format = 'json'
format = 'json'
1 change: 0 additions & 1 deletion lti_consumer/lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ def _get_lti_consumer(self):

return get_lti_consumer(block=self)


def extract_real_user_data(self):
"""
Extract and return real user data from the runtime
Expand Down
18 changes: 18 additions & 0 deletions lti_consumer/migrations/0002_auto_20200717_1720.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.14 on 2020-07-17 17:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lti_consumer', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='lticonfiguration',
name='version',
field=models.CharField(choices=[('LTI_1P1', 'LTI 1.1'), ('LTI_1P3', 'LTI 1.3 (with LTI Advantage Support)')], default='LTI_1P1', max_length=10),
),
]
18 changes: 18 additions & 0 deletions lti_consumer/migrations/0003_auto_20200717_1722.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.14 on 2020-07-17 17:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lti_consumer', '0002_auto_20200717_1720'),
]

operations = [
migrations.AlterField(
model_name='lticonfiguration',
name='config_store',
field=models.CharField(choices=[('CONFIG_ON_XBLOCK', 'Configuration Stored on XBlock fields')], default='CONFIG_ON_XBLOCK', max_length=25),
),
]
28 changes: 28 additions & 0 deletions lti_consumer/migrations/0004_ltiagslineitem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.2.14 on 2020-07-17 17:44

from django.db import migrations, models
import django.db.models.deletion
import opaque_keys.edx.django.models


class Migration(migrations.Migration):

dependencies = [
('lti_consumer', '0003_auto_20200717_1722'),
]

operations = [
migrations.CreateModel(
name='LtiAgsLineItem',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('resource_id', models.CharField(blank=True, max_length=50)),
('resource_link_id', opaque_keys.edx.django.models.UsageKeyField(blank=True, db_index=True, max_length=255, null=True)),
('score_maximum', models.IntegerField()),
('tag', models.CharField(blank=True, max_length=50)),
('start_date_time', models.DateTimeField(blank=True)),
('end_date_time', models.DateTimeField(blank=True)),
('lti_configuration', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='lti_consumer.LtiConfiguration')),
],
),
]
24 changes: 24 additions & 0 deletions lti_consumer/migrations/0005_auto_20200717_1827.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 2.2.14 on 2020-07-17 18:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lti_consumer', '0004_ltiagslineitem'),
]

operations = [
migrations.AddField(
model_name='ltiagslineitem',
name='label',
field=models.CharField(default='', max_length=100),
preserve_default=False,
),
migrations.AlterField(
model_name='ltiagslineitem',
name='resource_id',
field=models.CharField(blank=True, max_length=100),
),
]
23 changes: 23 additions & 0 deletions lti_consumer/migrations/0006_auto_20200717_1828.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.14 on 2020-07-17 18:28

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lti_consumer', '0005_auto_20200717_1827'),
]

operations = [
migrations.AlterField(
model_name='ltiagslineitem',
name='end_date_time',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AlterField(
model_name='ltiagslineitem',
name='start_date_time',
field=models.DateTimeField(blank=True, null=True),
),
]
19 changes: 19 additions & 0 deletions lti_consumer/migrations/0007_auto_20200717_2011.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.14 on 2020-07-17 20:11

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('lti_consumer', '0006_auto_20200717_1828'),
]

operations = [
migrations.AlterField(
model_name='ltiagslineitem',
name='lti_configuration',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='lti_consumer.LtiConfiguration'),
),
]
4 changes: 2 additions & 2 deletions lti_consumer/plugin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
)


## TEST CODE
# TEST CODE
from rest_framework import routers

from lti_consumer.views.ags import LtiAgsLineItemViewset
from lti_consumer.views import LtiAgsLineItemViewset

router = routers.SimpleRouter(trailing_slash=False)
router.register(r'lti-ags', LtiAgsLineItemViewset, base_name='lti-ags-view')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ class Meta:
'resourceLinkId',
'startDateTime',
'endDateTime',
)
)
13 changes: 7 additions & 6 deletions lti_consumer/views/ags.py → lti_consumer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
from django_filters.rest_framework import DjangoFilterBackend

from lti_consumer.models import LtiAgsLineItem
from lti_consumer.serializers.ags import LtiAgsLineItemSerializer
from lti_consumer.serializers import LtiAgsLineItemSerializer

from lti_consumer.lti_1p3.extensions.rest_framework.permissions import LtiAgsPermissions
from lti_consumer.lti_1p3.extensions.rest_framework.authentication import Lti1p3ApiAuthentication
from lti_consumer.lti_1p3.extensions.rest_framework.renderers import LineItemsRenderer, LineItemRenderer
from lti_consumer.lti_1p3.extensions.rest_framework.parsers import LineItemParser

from .permissions import LtiAgsPermissions
from .authentication import Lti1p3ApiAuthentication
from .renderers import LineItemsRenderer, LineItemRenderer
from .parsers import LineItemParser

class LtiAgsLineItemViewset(viewsets.ModelViewSet):
"""
Expand Down Expand Up @@ -54,4 +55,4 @@ def get_queryset(self):

def perform_create(self, serializer):
lti_configuration = self.request.lti_configuration
serializer.save(lti_configuration=lti_configuration)
serializer.save(lti_configuration=lti_configuration)
5 changes: 0 additions & 5 deletions lti_consumer/views/permissions.py

This file was deleted.

0 comments on commit 3a8aec4

Please sign in to comment.