Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed settings pages #1952

Merged
merged 29 commits into from
Jun 18, 2020
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
99af536
Updated backend endpoints to move most of the logic to the frontend
jayoshih Jun 12, 2020
c20e6ad
Removed legacy settings templates
jayoshih Jun 12, 2020
a14c8e8
Moved multiselect component to shared folder
jayoshih Jun 12, 2020
f0f6d0c
Set up actions for form submissions
jayoshih Jun 12, 2020
4223129
Finished main account tab layout
jayoshih Jun 12, 2020
82c0a75
Updated password change form
jayoshih Jun 12, 2020
f532737
Updated change name form
jayoshih Jun 12, 2020
80d3982
Updated appbar and side navigation
jayoshih Jun 12, 2020
df1ef37
Added test for empty strings
jayoshih Jun 12, 2020
ee561f9
Updated delete account form
jayoshih Jun 12, 2020
cd59eb8
Updated Using Studio page
jayoshih Jun 12, 2020
ab55c87
Updated report issue form
jayoshih Jun 12, 2020
448e955
Updated Storage page
jayoshih Jun 12, 2020
fcf27c2
Updated storage form
jayoshih Jun 12, 2020
292f01e
Cleaned up name change form and account deletion form
jayoshih Jun 12, 2020
58c04cb
Finished tests and renamed views folder
jayoshih Jun 12, 2020
c777bc4
Moved constants that used to be in RegistrationForm to pytest
jayoshih Jun 13, 2020
f78b84b
Fixed pytests
jayoshih Jun 13, 2020
36c5f5d
Updated method allowed on export_user_data
jayoshih Jun 15, 2020
98edcdf
Don't make channel required on issue report form
jayoshih Jun 15, 2020
bb20d79
Fixed full name form
jayoshih Jun 15, 2020
0c36f90
Merge branch 'vue-refactor' of https://github.com/learningequality/st…
jayoshih Jun 15, 2020
c8b1815
Make clean more forgiving
jayoshih Jun 16, 2020
093779c
Updated ricecooker doc link
jayoshih Jun 16, 2020
4462245
Updated other instances of Alert component
jayoshih Jun 16, 2020
e73ed68
Fixed failing test
jayoshih Jun 16, 2020
d9989fa
Optimized user deletion
jayoshih Jun 17, 2020
5dfe294
Properly set form fields for reactivity
jayoshih Jun 17, 2020
805ae69
Fixed editor count query
jayoshih Jun 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Updated backend endpoints to move most of the logic to the frontend
jayoshih committed Jun 12, 2020

Verified

This commit was signed with the committer’s verified signature.
fwyzard Andrea Bocci
commit 99af536d1996aab282e35ab3187061290f002b1c
385 changes: 88 additions & 297 deletions contentcuration/contentcuration/forms.py

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion contentcuration/contentcuration/models.py
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@
from mptt.models import raise_if_unsaved
from mptt.models import TreeForeignKey
from pg_utils import DistinctSum
from rest_framework.authtoken.models import Token

from contentcuration.db.models.manager import CustomContentNodeTreeManager
from contentcuration.statistics import record_channel_stats
@@ -131,6 +132,17 @@ def __unicode__(self):
def delete(self):
# Remove any invitations associated to this account
self.sent_to.all().delete()

# Delete channels associated with this user (if user is the only editor)
for c in self.editable_channels.all():
if c.editors.count() == 1:
c.delete()

# Delete channel collections associated with this user (if user is the only editor)
for cs in self.channel_sets.all():
if cs.editors.count() == 1:
cs.delete()

super(User, self).delete()

def can_edit(self, channel_id):
@@ -325,9 +337,15 @@ def get_full_name(self):
return full_name.strip()

def get_short_name(self):
"Returns the short name for the user."
"""
Returns the short name for the user.
"""
return self.first_name

def get_token(self):
token, _ = Token.objects.get_or_create(user=self)
return token.key

def save(self, *args, **kwargs):
super(User, self).save(*args, **kwargs)
changed = False
49 changes: 27 additions & 22 deletions contentcuration/contentcuration/serializers.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
from django.core.exceptions import ValidationError as DjangoValidationError
from django.core.files.storage import default_storage
from django.db import transaction
from django.db.models import Count
from django.db.models import IntegerField
from django.db.models import Manager
from django.db.models import QuerySet
@@ -22,7 +23,6 @@
from rest_framework.settings import api_settings
from rest_framework.utils import model_meta
from rest_framework_bulk import BulkSerializerMixin
from rest_framework.authtoken.models import Token

from contentcuration.celery import app
from contentcuration.models import AssessmentItem
@@ -841,28 +841,8 @@ class Meta:
class UserChannelListSerializer(serializers.ModelSerializer):
bookmarks = serializers.SerializerMethodField('retrieve_bookmarks')
available_space = serializers.SerializerMethodField()
channels_as_sole_editor = serializers.SerializerMethodField()
api_token = serializers.SerializerMethodField()
space_used_by_kind = serializers.SerializerMethodField()
clipboard_root_id = serializers.CharField(source='clipboard_tree_id')

def get_space_used_by_kind(self, user):
return user.get_space_used_by_kind()

def get_api_token(self, user):
api_token, isNew = Token.objects.get_or_create(user=user)
return api_token.key

def get_channels_as_sole_editor(self, user):
# Returns id and name for channels where this user is the only editor.
# Used in account deletion process to avoid deleting a channel's
# sole editor.
return [
{ 'id': channel.id, 'name': channel.name }
for channel in Channel.objects.filter(id__in=user.editable_channels.all(), deleted=False)
if len(channel.editors.all()) == 1
]

def get_available_space(self, user):
return user.get_available_space()

@@ -871,7 +851,32 @@ def retrieve_bookmarks(self, user):

class Meta:
model = User
fields = ('email', 'first_name', 'last_name', 'id', 'is_active', 'bookmarks', 'is_admin', 'available_space', 'disk_space', 'channels_as_sole_editor', 'api_token', 'space_used_by_kind', 'clipboard_root_id')
fields = ('email', 'first_name', 'last_name', 'id', 'is_active', 'bookmarks', 'is_admin', 'available_space', 'disk_space', 'clipboard_root_id')


class UserSettingsSerializer(UserChannelListSerializer):
api_token = serializers.SerializerMethodField()
space_used_by_kind = serializers.SerializerMethodField()
channels = serializers.SerializerMethodField()

def get_api_token(self, user):
return user.get_token()

def get_space_used_by_kind(self, user):
return user.get_space_used_by_kind()

def get_channels(self, user):
# Returns id, name, and editor_count for channels where this user is an editor.
# editor_count is used in account deletion process to avoid deleting
# a channel's sole editor
return list(user.editable_channels.filter(deleted=False)
.annotate(editor_count=Count('editors__id'))
.values('id', 'name', 'editor_count'))

class Meta:
model = User
fields = ('email', 'first_name', 'last_name', 'id', 'is_active', 'is_admin', 'available_space',
'disk_space', 'channels', 'api_token', 'space_used_by_kind')


class AdminChannelListSerializer(ChannelFieldMixin, serializers.ModelSerializer):
4 changes: 2 additions & 2 deletions contentcuration/contentcuration/tasks.py
Original file line number Diff line number Diff line change
@@ -121,8 +121,8 @@ def generatechannelcsv_task(channel_id, domain, user_id):


@task(name='generateusercsv_task')
def generateusercsv_task(email):
user = User.objects.get(email=email)
def generateusercsv_task(user_id):
user = User.objects.get(pk=user_id)
csv_path = write_user_csv(user)
subject = render_to_string('export/user_csv_email_subject.txt', {})
message = render_to_string('export/user_csv_email.txt', {
16 changes: 5 additions & 11 deletions contentcuration/contentcuration/urls.py
Original file line number Diff line number Diff line change
@@ -264,18 +264,12 @@ def get_queryset(self):
# Add settings endpoints
urlpatterns += [
url(r'^settings/$', settings_views.settings, name='settings'),
#url(r'^settings/profile', settings_views.ProfileView.as_view(), name='profile_settings'),
#url(r'^settings/preferences', settings_views.PreferencesView.as_view(), name='preferences_settings'),
#url(r'^settings/account$', settings_views.account_settings, name='account_settings'),
url(r'^api/delete_user_account/(?P<user_email>[^/]+)/$', settings_views.delete_user_account, name='delete_user_account'),
url(r'^api/export_user_data/(?P<user_email>[^/]+)/$', settings_views.export_user_data, name='export_user_data'),
url(r'^api/change_password/(?P<user_email>[^/]+)/$', settings_views.change_password, name='change_password'),
url(r'^api/update_user_full_name/(?P<user_email>[^/]+)/$', settings_views.update_user_full_name, name='update_user_full_name'),
#url(r'^settings/account/deleted', settings_views.account_deleted, name='account_deleted'),
#url(r'^settings/tokens', settings_views.tokens_settings, name='tokens_settings'),
url(r'^settings/storage', settings_views.StorageSettingsView.as_view(), name='storage_settings'),
url(r'^api/delete_user_account/$', settings_views.DeleteAccountView.as_view(), name='delete_user_account'),
url(r'^api/export_user_data/$', settings_views.export_user_data, name='export_user_data'),
url(r'^api/change_password/$', settings_views.UserPasswordChangeView.as_view(), name='change_password'),
url(r'^api/update_user_full_name/$', settings_views.UsernameChangeView.as_view(), name='update_user_full_name'),
url(r'^settings/issues', settings_views.IssuesSettingsView.as_view(), name='issues_settings'),
url(r'^settings/policies', settings_views.policies_settings, name='policies_settings'),
url(r'^settings/request_storage', settings_views.StorageSettingsView.as_view(), name='request_storage'),
url(r'^policies/update', settings_views.PolicyAcceptView.as_view(), name='policy_update'),
]

416 changes: 103 additions & 313 deletions contentcuration/contentcuration/views/settings.py

Large diffs are not rendered by default.