Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@
},
},
created() {
this.fetchDeferredUserData();
this.fetchDeferredUserApiToken();
this.fetchDeferredUserStorageByKind();
},
methods: {
...mapActions('settings', ['fetchDeferredUserData']),
...mapActions('settings', ['fetchDeferredUserStorageByKind', 'fetchDeferredUserApiToken']),
updateTitleForPage() {
// Updates the tab title every time the top-level route changes
let title;
Expand Down
41 changes: 34 additions & 7 deletions contentcuration/contentcuration/frontend/settings/vuex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import client from 'shared/client';

const throttleTime = 30 * 1000;

const settingsDeferredUser = throttle(
const settingsDeferredUserApiToken = function() {
return client.get(window.Urls.deferred_user_api_token());
};

const settingsDeferredUserSpaceByKind = throttle(
function() {
return client.get(window.Urls.deferred_user_data());
return client.get(window.Urls.deferred_user_space_by_kind());
},
throttleTime,
{ trailing: false }
Expand Down Expand Up @@ -78,14 +82,37 @@ export default {
return client.post(window.Urls.delete_user_account(), { email });
},

// Fetch fields that take longer to calculate
fetchDeferredUserData(context) {
if (context.getters.storageUseByKind && context.state.currentUser.api_token) {
// Fetch the user API token
fetchDeferredUserApiToken(context) {
if (context.rootState.session.currentUser.api_token) {
return;
}

return settingsDeferredUserApiToken().then(response => {
context.commit(
'UPDATE_SESSION',
{
api_token: response.data.api_token,
},
{ root: true }
);
});
},

// Fetch the user storage details
fetchDeferredUserStorageByKind(context) {
if (context.rootGetters.storageUseByKind) {
return;
}

return settingsDeferredUser().then(response => {
context.commit('UPDATE_SESSION', response.data, { root: true });
return settingsDeferredUserSpaceByKind().then(response => {
context.commit(
'UPDATE_SESSION',
{
space_used_by_kind: response.data.space_used_by_kind,
},
{ root: true }
);
});
},
},
Expand Down
3 changes: 2 additions & 1 deletion contentcuration/contentcuration/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def get_redirect_url(self, *args, **kwargs):
re_path(r'^activate/(?P<activation_key>[-:\w]+)/$', registration_views.UserActivationView.as_view(), name='registration_activate'),
re_path(r'^api/send_invitation_email/$', registration_views.send_invitation_email, name='send_invitation_email'),
re_path(r'^new/accept_invitation/(?P<email>[^/]+)/', registration_views.new_user_redirect, name="accept_invitation_and_registration"),
re_path(r'^api/deferred_user_data/$', registration_views.deferred_user_data, name="deferred_user_data"),
re_path(r'^api/deferred_user_space_by_kind/$', registration_views.deferred_user_space_by_kind, name="deferred_user_space_by_kind"),
re_path(r'^api/deferred_user_api_token/$', registration_views.deferred_user_api_token, name="deferred_user_api_token"),
re_path(r'^settings/$', settings_views.settings, name='settings'),
re_path(r'^administration/', admin_views.administration, name='administration'),
re_path(r'^manifest.webmanifest$', pwa.ManifestView.as_view(), name="manifest"),
Expand Down
11 changes: 10 additions & 1 deletion contentcuration/contentcuration/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,19 @@ def send_invitation_email(request):
@api_view(["GET"])
@authentication_classes((SessionAuthentication,))
@permission_classes((IsAuthenticated,))
def deferred_user_data(request):
def deferred_user_space_by_kind(request):
return Response(
{
"space_used_by_kind": request.user.get_space_used_by_kind(),
}
)

@api_view(["GET"])
@authentication_classes((SessionAuthentication,))
@permission_classes((IsAuthenticated,))
def deferred_user_api_token(request):
return Response(
{
"api_token": request.user.get_token(),
}
)
Expand Down