Skip to content

Commit 4dcb84c

Browse files
renzonrenzon
authored andcommitted
Implemented user redirection to memberkit
close #3844
1 parent 065ff3a commit 4dcb84c

File tree

11 files changed

+101
-344
lines changed

11 files changed

+101
-344
lines changed

conftest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,6 @@ def not_advanced_role(logged_user, request):
7070
return logged_user
7171

7272

73-
@pytest.fixture
74-
def client_with_not_advanced_roles(client, not_advanced_role):
75-
client.force_login(not_advanced_role)
76-
return client
77-
78-
7973
@pytest.fixture(params=_level_one_roles)
8074
@pytest.mark.django_db
8175
def level_one_role(logged_user, request):

pythonpro/memberkit/facade.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ class InactiveUserException(Exception):
7272
pass
7373

7474

75+
def has_memberkit_account(user):
76+
return Subscription.objects.filter(
77+
subscriber=user, status=Subscription.Status.ACTIVE
78+
).exclude(activated_at__isnull=True).exists()
79+
80+
81+
def has_any_subscription(user):
82+
return Subscription.objects.filter(subscriber=user).exists()
83+
84+
7585
def create_login_url(user):
7686
subscription = Subscription.objects.filter(
7787
subscriber=user, status=Subscription.Status.ACTIVE

pythonpro/modules/facade.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ def get_topic_with_contents(slug):
111111
'chapter__section__module').get()
112112

113113

114+
def get_topic_memberkit_url(slug):
115+
"""
116+
Search for a topic respective to slug with it's module, section and chapter
117+
:param slug: topic's slug
118+
:return: Topic
119+
"""
120+
return _Topic.objects.only('memberkit_url').get(slug=slug).memberkit_url
121+
122+
114123
def get_topic_with_contents_by_id(id: int) -> _Topic:
115124
"""
116125
Search for a topic respective to slug with it's module, section and chapter
@@ -180,19 +189,9 @@ def add_modules_purchase_link(modules):
180189
:param modules - a list of modules
181190
:return modules - a list of modules with a purchase link
182191
"""
183-
purchase_links = {
184-
'python-birds': reverse('core:lead_landing'),
185-
'pytools': reverse('checkout:webdev_landing_page'),
186-
'django': reverse('checkout:webdev_landing_page'),
187-
'entrevistas-tecnicas': reverse('checkout:webdev_landing_page'),
188-
'objetos-pythonicos': reverse('checkout:bootcamp_lp'),
189-
'python-para-pythonistas': reverse('checkout:bootcamp_lp'),
190-
'python-patterns': reverse('checkout:bootcamp_lp'),
191-
192-
}
193-
192+
link = reverse('checkout:bootcamp_lp')
194193
for module in modules:
195-
module.purchase_link = purchase_links[module.slug]
194+
module.purchase_link = link
196195

197196
return modules
198197

pythonpro/modules/modules_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def index(request):
1818
modules = add_modules_purchase_link(modules)
1919

2020
for module in modules:
21-
module.has_access = True if has_object_permission('access_content', request.user, module) else False
21+
module.has_access = has_object_permission('access_content', request.user, module)
2222

2323
return render(request, 'modules/module_index.html', context={'modules': modules})
2424

pythonpro/modules/permissions.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,9 @@
1-
from rolepermissions.checkers import has_permission
21
from rolepermissions.permissions import register_object_checker
32

4-
from pythonpro.core.roles import (
5-
Member,
6-
watch_client_modules,
7-
watch_lead_modules,
8-
watch_webdev_modules, watch_bootcamp_modules, watch_pythonista_modules
9-
)
103
from pythonpro.modules.models import Content
114

12-
_LEAD_MODULES = {'python-birds'}
13-
_CLIENT_MODULES = {'python-birds', 'pytools'}
14-
_WEBDEV_MODULES = {'python-birds', 'pytools', 'django', 'entrevistas-tecnicas'}
15-
_BOOTCAMPER_MODULES = {
16-
'python-birds',
17-
'pytools',
18-
'django',
19-
'entrevistas-tecnicas',
20-
'objetos-pythonicos',
21-
'python-para-pythonistas',
22-
'python-patterns'
23-
}
24-
_PYTHONISTA_MODULES = {'python-birds', 'objetos-pythonicos', 'python-para-pythonistas', 'python-patterns'}
25-
265

276
@register_object_checker()
287
def access_content(role, user, content: Content) -> bool:
29-
if role == Member:
30-
return True
318
module_slug = content.module_slug()
32-
if module_slug in _BOOTCAMPER_MODULES and has_permission(user, watch_bootcamp_modules):
33-
return True
34-
if module_slug in _WEBDEV_MODULES and has_permission(user, watch_webdev_modules):
35-
return True
36-
if module_slug in _PYTHONISTA_MODULES and has_permission(user, watch_pythonista_modules):
37-
return True
38-
if module_slug in _CLIENT_MODULES and has_permission(user, watch_client_modules):
39-
return True
40-
if module_slug in _LEAD_MODULES and has_permission(user, watch_lead_modules):
41-
return True
42-
43-
return False
9+
return module_slug == 'python-birds'

pythonpro/modules/tests/test_module_index_view.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ def modules(transactional_db):
1818
def resp(client, django_user_model, modules):
1919
user = baker.make(django_user_model)
2020
client.force_login(user)
21-
return _resp_not_logged(client, modules)
21+
return _resp_not_logged(client)
2222

2323

2424
@pytest.fixture
2525
def resp_not_logged(client, modules):
26-
return _resp_not_logged(client, modules)
26+
return _resp_not_logged(client)
2727

2828

29-
def _resp_not_logged(client, modules):
29+
def _resp_not_logged(client):
3030
return client.get(reverse('modules:index'))
3131

3232

@@ -47,7 +47,10 @@ def test_module_index_link_not_logged(resp_not_logged):
4747
def test_module_link_not_logged(modules, resp_not_logged):
4848
""" Assert module links are not present when user is not logged """
4949
for module in modules:
50-
dj_assert_not_contains(resp_not_logged, f'href="{module.get_absolute_url()}"')
50+
if module.slug == 'python-birds':
51+
dj_assert_contains(resp_not_logged, f'href="{module.get_absolute_url()}"')
52+
else:
53+
dj_assert_not_contains(resp_not_logged, f'href="{module.get_absolute_url()}"')
5154

5255

5356
def test_module_index_link_logged(resp):

pythonpro/modules/tests/test_module_index_view_roles_access.py

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from django.core.management import call_command
33
from django.urls import reverse
44

5-
from pythonpro.django_assertions import dj_assert_contains, dj_assert_not_contains
5+
from pythonpro.django_assertions import dj_assert_contains
66
from pythonpro.modules import facade
77

88

@@ -56,104 +56,3 @@ def test_module_lead_user_can_access(modules_dct, resp_lead_user):
5656
""" Assert that user with a lead role can access the right content """
5757
python_birds = modules_dct['python-birds']
5858
dj_assert_contains(resp_lead_user, f'href="{python_birds.get_absolute_url()}"')
59-
60-
61-
@pytest.mark.parametrize('slug', [
62-
'objetos-pythonicos',
63-
'pytools',
64-
'python-para-pythonistas',
65-
'django',
66-
'python-patterns',
67-
'entrevistas-tecnicas',
68-
])
69-
def test_module_lead_user_can_not_access(modules_dct, resp_lead_user, slug):
70-
""" Assert that user with a lead role can not access some contents """
71-
dj_assert_not_contains(resp_lead_user, modules_dct[slug].get_absolute_url())
72-
73-
74-
@pytest.mark.parametrize('slug', ['python-birds', 'pytools'])
75-
def test_module_client_user_can_access(modules_dct, resp_client_user, slug):
76-
""" Assert that user with a client role can access the right content """
77-
dj_assert_contains(resp_client_user, modules_dct[slug].get_absolute_url())
78-
79-
80-
@pytest.mark.parametrize('slug', [
81-
'django',
82-
'objetos-pythonicos',
83-
'python-para-pythonistas',
84-
'python-patterns',
85-
'entrevistas-tecnicas',
86-
])
87-
def test_module_client_user_can_not_access(modules_dct, resp_client_user, slug):
88-
""" Assert that user with a client role can not access some contents """
89-
dj_assert_not_contains(resp_client_user, modules_dct[slug].get_absolute_url())
90-
91-
92-
@pytest.mark.parametrize('slug', [
93-
'python-birds',
94-
'pytools',
95-
'django',
96-
'entrevistas-tecnicas',
97-
])
98-
def test_module_webdev_user_can_access(modules_dct, resp_webdev_user, slug):
99-
""" Assert that user with a webdev role can access the right content """
100-
dj_assert_contains(resp_webdev_user, modules_dct[slug].get_absolute_url())
101-
102-
103-
@pytest.mark.parametrize('slug', [
104-
'objetos-pythonicos',
105-
'python-para-pythonistas',
106-
'python-patterns',
107-
])
108-
def test_module_webdev_user_can_not_access(modules_dct, resp_webdev_user, slug):
109-
""" Assert that user with a webdev role can not access some contents """
110-
dj_assert_not_contains(resp_webdev_user, modules_dct[slug].get_absolute_url())
111-
112-
113-
@pytest.mark.parametrize('slug', [
114-
'python-birds',
115-
'pytools',
116-
'django',
117-
'entrevistas-tecnicas',
118-
'objetos-pythonicos',
119-
'python-para-pythonistas',
120-
'python-patterns',
121-
])
122-
def test_module_bootcamper_user_can_access(modules_dct, resp_bootcamper_user, slug):
123-
""" Assert that user with a bootcamper role can access the right content """
124-
dj_assert_contains(resp_bootcamper_user, modules_dct[slug].get_absolute_url())
125-
126-
127-
@pytest.mark.parametrize('slug', [
128-
'python-birds',
129-
'objetos-pythonicos',
130-
'python-para-pythonistas',
131-
'python-patterns',
132-
])
133-
def test_module_pythonista_user_can_access(modules_dct, resp_pythonista_user, slug):
134-
""" Assert that user with a pythonista role can access the right content """
135-
dj_assert_contains(resp_pythonista_user, modules_dct[slug].get_absolute_url())
136-
137-
138-
@pytest.mark.parametrize('slug', [
139-
'pytools',
140-
'django',
141-
'entrevistas-tecnicas',
142-
])
143-
def test_module_pythonista_user_can_not_access(modules_dct, resp_pythonista_user, slug):
144-
""" Assert that user with a pythonista role can not access some contents """
145-
dj_assert_not_contains(resp_pythonista_user, modules_dct[slug].get_absolute_url())
146-
147-
148-
@pytest.mark.parametrize('slug', [
149-
'pytools',
150-
'django',
151-
'entrevistas-tecnicas',
152-
'python-birds',
153-
'objetos-pythonicos',
154-
'python-para-pythonistas',
155-
'python-patterns',
156-
])
157-
def test_module_member_user_can_access(modules_dct, resp_member_user, slug):
158-
""" Assert that user with a member role can access all the content """
159-
dj_assert_contains(resp_member_user, modules_dct[slug].get_absolute_url())

pythonpro/modules/tests/test_next_content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@pytest.fixture
1010
def module(db):
11-
return baker.make(Module)
11+
return baker.make(Module, slug='python-birds')
1212

1313

1414
@pytest.fixture

pythonpro/modules/tests/test_previous_content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@pytest.fixture
1010
def module(db):
11-
return baker.make(Module)
11+
return baker.make(Module, slug='python-birds')
1212

1313

1414
@pytest.fixture

0 commit comments

Comments
 (0)