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

split user plugin #8443

Merged
merged 8 commits into from
Oct 12, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion kolibri/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
"kolibri.plugins.pdf_viewer",
"kolibri.plugins.setup_wizard",
"kolibri.plugins.slideshow_viewer",
"kolibri.plugins.user",
"kolibri.plugins.user_auth",
"kolibri.plugins.user_profile",
]
2 changes: 2 additions & 0 deletions kolibri/core/assets/src/core-app/apiSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import LearnOnlyDeviceNotice from '../views/LearnOnlyDeviceNotice';
import branding from '../utils/branding';
import sortLanguages from '../utils/sortLanguages';
import * as sync from '../views/sync/syncComponentSet';
import PageRoot from '../views/PageRoot';

// webpack optimization
import CoreInfoIcon from '../views/CoreInfoIcon';
Expand Down Expand Up @@ -193,6 +194,7 @@ export default {
PageStatus,
LearnOnlyDeviceNotice,
SuggestedTime,
PageRoot,
},
componentSets: {
sync,
Expand Down
10 changes: 5 additions & 5 deletions kolibri/core/assets/src/views/AuthMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@
return this.details || this.$tr(this.authorizedRole);
},
linkText() {
if (!this.userPluginUrl) {
if (!this.userAuthPluginUrl) {
return this.$tr('goBackToHomeAction');
} else {
return this.$tr('signInToKolibriAction');
}
},
userPluginUrl() {
return urls['kolibri:kolibri.plugins.user:user'];
userAuthPluginUrl() {
return urls['kolibri:kolibri.plugins.user_auth:user_auth'];
},
signInLink() {
// Creates a link to the Sign In Page that also has a query parameter that
// will redirect back to this page after user logs in with correct credentials.
if (!this.userPluginUrl) {
if (!this.userAuthPluginUrl) {
// If User plugin is not active, go to the root of whatever plugin you're in.
// In practice, this will only happen on select Learn pages.
return '/';
Expand All @@ -93,7 +93,7 @@
} else {
next = window.encodeURIComponent(window.location.href);
}
return `${this.userPluginUrl()}#/signin?next=${next}`;
return `${this.userAuthPluginUrl()}#/signin?next=${next}`;
}
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be put into the core API? It seems like boiler plate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it is in the core API!

https://github.com/learningequality/kolibri/pull/8443/files#diff-a2dd73b039d1c55598114bb71dc7ce6bd5fffd2e7ed8e921b218c49c53e99cc7

It's a step in the direction of this: #5719

Once 0.15 is cut, I'll apply the pattern to user_auth also


<!-- populated by client-side router -->
<router-view />

</template>
Expand All @@ -8,7 +9,7 @@
<script>

export default {
name: 'CoachIndex',
name: 'PageRoot',
};

</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>

<div>
<KButtonGroup style="margin-top: 8px;">
<KButtonGroup style="margin-top: 8px; position: relative; left: -16px;">
<KIconButton
icon="language"
aria-hidden="true"
Expand All @@ -23,7 +23,7 @@
/>

<KButton
v-if="numSelectableLanguages > numVisibleLanguages + 1"
v-if="numSelectableLanguages > numVisibleLanguageBtns + 1"
:text="$tr('showMoreLanguagesSelector')"
:primary="false"
appearance="flat-button"
Expand Down Expand Up @@ -68,15 +68,15 @@
selectedLanguage() {
return availableLanguages[currentLanguage];
},
numVisibleLanguages() {
numVisibleLanguageBtns() {
// At windowBreakpoint = 0, only the "More languages" button will show
return this.windowBreakpoint;
return Math.min(4, this.windowBreakpoint);
},
numSelectableLanguages() {
return this.selectableLanguages.length;
},
buttonLanguages() {
if (this.selectableLanguages.length <= this.numVisibleLanguages + 1) {
if (this.selectableLanguages.length <= this.numVisibleLanguageBtns + 1) {
return this.selectableLanguages.slice().sort(compareLanguages);
}
return this.selectableLanguages
Expand All @@ -93,7 +93,7 @@
}
return compareLanguages(a, b);
})
.slice(0, this.numVisibleLanguages);
.slice(0, this.numVisibleLanguageBtns);
},
},
$trs: {
Expand Down
10 changes: 5 additions & 5 deletions kolibri/core/assets/test/views/auth-message.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ describe('auth message component', () => {
describe('tests for sign-in page link when user plugin exists', () => {
beforeAll(() => {
const userUrl = jest.fn();
urls['kolibri:kolibri.plugins.user:user'] = userUrl;
userUrl.mockReturnValue('http://localhost:8000/en/user/');
urls['kolibri:kolibri.plugins.user_auth:user_auth'] = userUrl;
userUrl.mockReturnValue('http://localhost:8000/en/auth/');
});

afterAll(() => {
delete urls['kolibri:kolibri.plugins.user:user'];
delete urls['kolibri:kolibri.plugins.user_auth:user_auth'];
});

it('shows correct link text if there is a user plugin', () => {
const wrapper = makeWrapper();
const link = wrapper.find('kexternallink-stub');
expect(link.attributes()).toMatchObject({
href:
'http://localhost:8000/en/user/#/signin?next=http%3A%2F%2Flocalhost%3A8000%2F%23%2Ftest_url',
'http://localhost:8000/en/auth/#/signin?next=http%3A%2F%2Flocalhost%3A8000%2F%23%2Ftest_url',
text: 'Sign in to Kolibri',
});
});
Expand All @@ -111,7 +111,7 @@ describe('auth message component', () => {
const link = wrapper.find('kexternallink-stub');
expect(link.attributes()).toMatchObject({
href:
'http://localhost:8000/en/user/#/signin?next=http%3A%2F%2Flocalhost%3A8000%2F%23%2Fsome_other_url',
'http://localhost:8000/en/auth/#/signin?next=http%3A%2F%2Flocalhost%3A8000%2F%23%2Fsome_other_url',
text: 'Sign in to Kolibri',
});
});
Expand Down
2 changes: 1 addition & 1 deletion kolibri/core/test/test_key_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _assert_location_reverse_url(self, url_name):
self.assertEqual(response.get("location"), reverse(url_name))

def test_anonymous_user_is_redirected_to_user_plugin(self):
self._assert_location_reverse_url("kolibri:kolibri.plugins.user:user")
self._assert_location_reverse_url("kolibri:kolibri.plugins.user_auth:user_auth")

def test_superuser_is_redirected_to_device_plugin(self):
self.client.login(username=self.superuser.username, password=DUMMY_PASSWORD)
Expand Down
4 changes: 2 additions & 2 deletions kolibri/plugins/coach/assets/src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setChannelInfo } from 'kolibri.coreVue.vuex.actions';
import router from 'kolibri.coreVue.router';
import RootVue from './views/CoachIndex';
import PageRoot from 'kolibri.coreVue.components.PageRoot';
import routes from './routes';
import pluginModule from './modules/pluginModule';
import KolibriApp from 'kolibri_app';
Expand All @@ -13,7 +13,7 @@ class CoachToolsModule extends KolibriApp {
return routes;
}
get RootVue() {
return RootVue;
return PageRoot;
}
get pluginModule() {
return pluginModule;
Expand Down
4 changes: 2 additions & 2 deletions kolibri/plugins/demo_server/kolibri_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from kolibri.core.webpack import hooks as webpack_hooks
from kolibri.plugins import KolibriPluginBase
from kolibri.plugins.hooks import register_hook
from kolibri.plugins.user import hooks
from kolibri.plugins.user_auth import hooks


class DemoServer(KolibriPluginBase):
Expand All @@ -18,5 +18,5 @@ class DemoServerAsset(webpack_hooks.WebpackBundleHook):


@register_hook
class DemoServerInclusionHook(hooks.UserSyncHook):
class DemoServerInclusionHook(hooks.UserAuthSyncHook):
bundle_class = DemoServerAsset
10 changes: 5 additions & 5 deletions kolibri/plugins/learn/assets/src/views/LearnIndex.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

<UpdateYourProfileModal
v-if="profileNeedsUpdate"
:disabled="demographicInfo === null || !userPluginUrl"
:disabled="demographicInfo === null || !userProfilePluginUrl"
@cancel="handleCancelUpdateYourProfileModal"
@submit="handleSubmitUpdateYourProfileModal"
/>
Expand Down Expand Up @@ -317,8 +317,8 @@
(this.demographicInfo.gender === '' || this.demographicInfo.birth_year === '')
);
},
userPluginUrl() {
return urls['kolibri:kolibri.plugins.user:user'];
userProfilePluginUrl() {
return urls['kolibri:kolibri.plugins.user_profile:user_profile'];
},
learnBackPageRoute() {
// extract the key pieces of routing from immersive page props, but since we don't need
Expand Down Expand Up @@ -383,8 +383,8 @@
this.demographicInfo = null;
},
handleSubmitUpdateYourProfileModal() {
if (this.userPluginUrl) {
const url = `${this.userPluginUrl()}#/profile/edit?next_page=learn`;
if (this.userProfilePluginUrl) {
const url = `${this.userProfilePluginUrl()}#/profile/edit?next_page=learn`;
const redirect = () => {
window.location.href = url;
};
Expand Down
4 changes: 4 additions & 0 deletions kolibri/plugins/setup_wizard/kolibri_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class SetupWizardPlugin(KolibriPluginBase):
untranslated_view_urls = "api_urls"
translated_view_urls = "urls"

@property
def url_slug(self):
return "setup"


@register_hook
class SetupWizardAsset(webpack_hooks.WebpackBundleHook):
Expand Down