Add my-kv licenses and per-platform check for them
This commit is contained in:
parent
fec8022f0f
commit
ad34cf50cf
|
|
@ -18,9 +18,11 @@ Note the Client ID and the Client Secret of the newly created client
|
|||
|
||||
Go to the environment on heroku, and enter the following env variables:
|
||||
|
||||
- OAUTH_ACCESS_TOKEN_URL: https://sso.hep-verlag.ch/oauth/token
|
||||
- OAUTH_API_BASE_URL: https://cms.hep-verlag.ch
|
||||
- OAUTH_AUTHORIZE_URL: https://sso.hep-verlag.ch/oauth/authorize
|
||||
- OAUTH_CLIENT_ID: `<Client ID>`
|
||||
- OAUTH_CLIENT_SECRET: `<Client Secret>`
|
||||
- OAUTH_LOCAL_REDIRECT_URI: https://<App URL>/api/oauth/callback/
|
||||
```
|
||||
OAUTH_ACCESS_TOKEN_URL=https://sso.hep-verlag.ch/oauth/token
|
||||
OAUTH_API_BASE_URL=https://cms.hep-verlag.ch
|
||||
OAUTH_AUTHORIZE_URL=https://sso.hep-verlag.ch/oauth/authorize
|
||||
OAUTH_CLIENT_ID=<Client ID>
|
||||
OAUTH_CLIENT_SECRET=<Client Secret>
|
||||
OAUTH_LOCAL_REDIRECT_URI=https://<App URL>/api/oauth/callback/
|
||||
```
|
||||
|
|
|
|||
|
|
@ -33,3 +33,4 @@ export OAUTH_AUTHORIZE_URL=
|
|||
export OAUTH_API_BASE_URL=
|
||||
export OAUTH_LOCAL_REDIRECT_URI=
|
||||
export LOGOUT_REDIRECT_URL=
|
||||
export PLATFORM=myskillbox
|
||||
|
|
|
|||
|
|
@ -35,3 +35,4 @@ TASKBASE_TOKEN:
|
|||
TASKBASE_USER:
|
||||
USE_AWS: True
|
||||
WEB_CONCURRENCY: 4
|
||||
PLATFORM: myskillbox
|
||||
|
|
|
|||
|
|
@ -366,7 +366,6 @@ WAGTAIL_SITE_NAME = 'skillbox'
|
|||
GRAPHQL_QUERIES_DIR = os.path.join(BASE_DIR, '..', 'client', 'src', 'graphql', 'gql', 'queries')
|
||||
GRAPHQL_MUTATIONS_DIR = os.path.join(GRAPHQL_QUERIES_DIR, '../mutations')
|
||||
|
||||
|
||||
DEFAULT_FROM_EMAIL = 'myskillbox <noreply@myskillbox.ch>'
|
||||
|
||||
# Metanet Config
|
||||
|
|
@ -400,6 +399,8 @@ AUTHLIB_OAUTH_CLIENTS = {
|
|||
}
|
||||
}
|
||||
|
||||
PLATFORM = os.environ.get('PLATFORM', 'myskillbox')
|
||||
|
||||
OAUTH_LOCAL_REDIRECT_URI = os.environ.get("OAUTH_LOCAL_REDIRECT_URI")
|
||||
|
||||
TASKBASE_USER = os.environ.get("TASKBASE_USER")
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from datetime import timedelta
|
|||
|
||||
from oauth.models import OAuth2Token
|
||||
from oauth.oauth_client import oauth, fetch_token
|
||||
from users.licenses import MYSKILLBOX_LICENSES, is_myskillbox_product, TEACHER_KEY
|
||||
from users.licenses import get_license_dict, is_myskillbox_product, TEACHER_KEY
|
||||
from users.models import License
|
||||
|
||||
from core.logger import get_logger
|
||||
|
|
@ -14,6 +14,7 @@ logger = get_logger(__name__)
|
|||
|
||||
VALID_PRODUCT_STATES = ['waiting', 'paid', 'completed', 'shipped']
|
||||
|
||||
licenses = get_license_dict()
|
||||
|
||||
class HepClientException(Exception):
|
||||
pass
|
||||
|
|
@ -144,13 +145,14 @@ class HepClient:
|
|||
return products
|
||||
|
||||
def entry_to_product(self, entry, activation_date, status):
|
||||
if is_myskillbox_product(entry['isbn']) and activation_date:
|
||||
isbn = entry['isbn']
|
||||
if is_myskillbox_product(isbn) and activation_date:
|
||||
return {
|
||||
'raw': entry,
|
||||
'activated': activation_date,
|
||||
'status': status,
|
||||
'order_id': entry['id'],
|
||||
'license': MYSKILLBOX_LICENSES[entry['isbn']],
|
||||
'license': licenses[isbn],
|
||||
'isbn': entry['isbn']
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,17 +9,18 @@ from oauth.factories import Oauth2TokenFactory
|
|||
from oauth.hep_client import HepClient, HepClientUnauthorizedException, HepClientNoTokenException, HepClientException
|
||||
from oauth.models import OAuth2Token
|
||||
from oauth.tests.test_oauth2token import REFRESH_DATA
|
||||
from users.licenses import MYSKILLBOX_LICENSES
|
||||
from users.licenses import get_valid_isbns, get_license_dict
|
||||
from users.models import License
|
||||
from users.tests.mock_hep_data_factory import MockResponse
|
||||
|
||||
ISBNS = list(MYSKILLBOX_LICENSES.keys())
|
||||
ISBNS = get_valid_isbns()
|
||||
licenses = get_license_dict()
|
||||
|
||||
STUDENT_ISBN = ISBNS[0]
|
||||
STUDENT_LICENSE = MYSKILLBOX_LICENSES[STUDENT_ISBN]
|
||||
STUDENT_LICENSE = licenses[STUDENT_ISBN]
|
||||
|
||||
TEACHER_ISBN = ISBNS[-1]
|
||||
TEACHER_LICENSE = MYSKILLBOX_LICENSES[TEACHER_ISBN]
|
||||
TEACHER_LICENSE = licenses[TEACHER_ISBN]
|
||||
|
||||
|
||||
class HepClientTestCases(TestCase):
|
||||
|
|
|
|||
|
|
@ -1,35 +1,63 @@
|
|||
from django.conf import settings
|
||||
|
||||
TEACHER_KEY = 'teacher'
|
||||
STUDENT_KEY = 'student'
|
||||
MYSKILLBOX_PLATFORM = 'myskillbox'
|
||||
MYKV_PLATFORM = 'mykv'
|
||||
|
||||
MYSKILLBOX_LICENSES = {
|
||||
"978-3-0355-1397-4": {
|
||||
'edition': STUDENT_KEY,
|
||||
'duration': 4 * 365,
|
||||
'name': 'Student 4 years'
|
||||
'name': 'Student 4 years',
|
||||
'platform': MYSKILLBOX_PLATFORM
|
||||
},
|
||||
"978-3-0355-1860-3": {
|
||||
'edition': STUDENT_KEY,
|
||||
'duration': 365,
|
||||
'name': 'Student 1 year'
|
||||
'name': 'Student 1 year',
|
||||
'platform': MYSKILLBOX_PLATFORM
|
||||
},
|
||||
"978-3-0355-1862-7": {
|
||||
'edition': STUDENT_KEY,
|
||||
'duration': 30,
|
||||
'name': 'Student test 1 month'
|
||||
'name': 'Student test 1 month',
|
||||
'platform': MYSKILLBOX_PLATFORM
|
||||
},
|
||||
"978-3-0355-1861-0": {
|
||||
'edition': TEACHER_KEY,
|
||||
'duration': 30,
|
||||
'name': 'Teacher test 1 month'
|
||||
'name': 'Teacher test 1 month',
|
||||
'platform': MYSKILLBOX_PLATFORM
|
||||
},
|
||||
"978-3-0355-1823-8": {
|
||||
'edition': TEACHER_KEY,
|
||||
'duration': 365,
|
||||
'name': 'Teacher 1 year'
|
||||
'name': 'Teacher 1 year',
|
||||
'platform': MYSKILLBOX_PLATFORM
|
||||
},
|
||||
'978-3-0355-2189-4': {
|
||||
'edition': STUDENT_KEY,
|
||||
'duration': 30,
|
||||
'name': 'Student test 1 month',
|
||||
'platform': MYKV_PLATFORM
|
||||
},
|
||||
'978-3-0355-2188-7': {
|
||||
'edition': TEACHER_KEY,
|
||||
'duration': 30,
|
||||
'name': 'Student test 1 month',
|
||||
'platform': MYKV_PLATFORM
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def get_license_dict():
|
||||
return {
|
||||
k: v for k, v in MYSKILLBOX_LICENSES.items() if v.get('platform') == settings.PLATFORM
|
||||
}
|
||||
|
||||
def get_valid_isbns():
|
||||
return list(get_license_dict().keys())
|
||||
|
||||
def is_myskillbox_product(isbn):
|
||||
valid_isbns = list(MYSKILLBOX_LICENSES.keys())
|
||||
return isbn in valid_isbns
|
||||
return isbn in get_valid_isbns()
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@ from datetime import date, timedelta
|
|||
from django.utils.timezone import now
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from users.licenses import MYSKILLBOX_LICENSES
|
||||
from users.licenses import get_license_dict
|
||||
from users.models import License, NO_DATE
|
||||
|
||||
YEARLY_ISBNS = ["978-3-0355-1860-3", "978-3-0355-1823-8"]
|
||||
LONGER_DURATION = 455
|
||||
|
||||
licenses = get_license_dict()
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = """
|
||||
|
|
@ -27,7 +27,7 @@ class Command(BaseCommand):
|
|||
if isbn not in YEARLY_ISBNS:
|
||||
continue
|
||||
|
||||
standard_duration = MYSKILLBOX_LICENSES[isbn]['duration'] # use isbn from hep due to our bug
|
||||
standard_duration = licenses[isbn]['duration'] # use isbn from hep due to our bug
|
||||
start_date = license.get_hep_start_date()
|
||||
duration_in_days = (license.expire_date - start_date).days
|
||||
if duration_in_days == standard_duration:
|
||||
|
|
|
|||
|
|
@ -9,8 +9,9 @@ from django.utils.translation import ugettext_lazy as _
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import UserManager as DjangoUserManager
|
||||
|
||||
from users.licenses import MYSKILLBOX_LICENSES
|
||||
from users.licenses import get_license_dict
|
||||
|
||||
license_dict = get_license_dict()
|
||||
|
||||
class RoleManager(models.Manager):
|
||||
use_in_migrations = True
|
||||
|
|
@ -140,7 +141,7 @@ class LicenseManager(models.Manager):
|
|||
|
||||
def create_license_for_role(self, licensee, activation_date, raw, role, order_id, isbn):
|
||||
Role = apps.get_model('users', 'Role')
|
||||
expiry_date = activation_date + timedelta(MYSKILLBOX_LICENSES[isbn]['duration'])
|
||||
expiry_date = activation_date + timedelta(license_dict[isbn]['duration'])
|
||||
|
||||
if role == 'teacher':
|
||||
user_role = Role.objects.get_default_teacher_role()
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ from django.utils.timezone import is_aware, make_aware
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from core.mixins import GraphqlNodeMixin
|
||||
from users.licenses import MYSKILLBOX_LICENSES
|
||||
from users.licenses import get_license_dict
|
||||
from users.managers import LicenseManager, RoleManager, UserManager, UserRoleManager
|
||||
|
||||
DEFAULT_SCHOOL_ID = 1
|
||||
|
|
@ -23,6 +23,8 @@ NO_DATE = date(MINYEAR, 1, 1) # date to tag licenses without date
|
|||
NO_DATETIME = datetime.combine(NO_DATE, datetime.min.time())
|
||||
AWARE_NO_DATETIME = make_aware(NO_DATETIME)
|
||||
|
||||
licenses = get_license_dict()
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
LICENSE_NONE = 'no-license'
|
||||
|
|
@ -309,7 +311,7 @@ class License(models.Model):
|
|||
order_id = models.IntegerField(blank=False, null=False, default=-1)
|
||||
raw = models.TextField(default='')
|
||||
isbn = models.CharField(max_length=50, blank=False, null=False,
|
||||
default=list(MYSKILLBOX_LICENSES.keys())[0]) # student license
|
||||
default=list(licenses.keys())[0]) # student license
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
hep_created_at = models.DateTimeField(default=AWARE_NO_DATETIME)
|
||||
new_api_raw = models.TextField(default='')
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ from datetime import timedelta
|
|||
from django.utils.timezone import now
|
||||
|
||||
from core.factories import UserFactory
|
||||
from users.factories import SchoolClassFactory, LicenseFactory
|
||||
from users.licenses import MYSKILLBOX_LICENSES
|
||||
from users.models import Role, UserRole, DEFAULT_SCHOOL_ID
|
||||
from users.factories import SchoolClassFactory
|
||||
from users.models import Role, UserRole
|
||||
|
||||
|
||||
def create_student(**kwargs):
|
||||
|
|
|
|||
Loading…
Reference in New Issue