Skip to content

Commit

Permalink
Re-implement share file functionality.
Browse files Browse the repository at this point in the history
Remove unneeded appCapabilities from kolibri/utils.
  • Loading branch information
rtibbles committed Dec 19, 2024
1 parent 3a3a72b commit c1ec045
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,25 @@
class="download-button"
data-test="download-button"
/>
<KButton
v-if="canShareFile"
:text="learnString('shareFile')"
class="share-button"
@click="shareFile()"
/>
</section>

</template>


<script>
import { ContentLevels } from 'kolibri/constants';
import { ContentNodeKinds, ContentLevels } from 'kolibri/constants';
import camelCase from 'lodash/camelCase';
import client from 'kolibri/client';
import useUser from 'kolibri/composables/useUser';
import urls from 'kolibri/urls';
import pluginData from 'kolibri-plugin-data';
import LearnerNeeds from 'kolibri-constants/labels/Needs';
import DownloadButton from 'kolibri/components/DownloadButton';
import TimeDuration from 'kolibri-common/components/TimeDuration';
Expand All @@ -167,6 +176,10 @@
TimeDuration,
},
mixins: [commonCoreStrings, commonLearnStrings],
setup() {
const { isAppContext } = useUser();
return { isAppContext };
},
props: {
canDownloadExternally: {
type: Boolean,
Expand All @@ -187,6 +200,13 @@
};
},
computed: {
canShareFile() {
return (
this.isAppContext &&
this.content.kind !== ContentNodeKinds.EXERCISE &&
pluginData.canShareFile
);
},
forBeginners() {
return get(this.content, 'learner_needs', []).includes(LearnerNeeds.FOR_BEGINNERS);
},
Expand Down Expand Up @@ -260,6 +280,21 @@
return '-';
}
},
shareFile() {
const urlFunction = urls['kolibri:core:sharefile'];
return client({
url: urlFunction(),
method: 'POST',
data: {
content_node: this.content.id,
message: this.learnString('shareFileMessage', {
title: this.content.title,
topic: this.content.ancestors.slice(-1)[0].title,
copyrightHolder: this.content.license_owner,
}),
},
});
},
},
};
Expand Down Expand Up @@ -309,7 +344,8 @@
padding-top: 8px;
}
.download-button {
.download-button,
.share-button {
margin-top: 16px;
}
Expand Down
4 changes: 4 additions & 0 deletions kolibri/plugins/learn/assets/src/views/commonLearnStrings.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export const learnStrings = createTranslator('CommonLearnStrings', {
message: 'Share',
context: 'Option to share a specific file from a learning resource.',
},
shareFileMessage: {
message: '"{title}" (in "{topic}"), from {copyrightHolder}',
context: 'Message shared with the default file from a learning resource.',
},
locationsInChannel: {
message: 'Location in {channelname}',
context:
Expand Down
2 changes: 2 additions & 0 deletions kolibri/plugins/learn/kolibri_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from kolibri.core.auth.constants.user_kinds import ANONYMOUS
from kolibri.core.auth.constants.user_kinds import LEARNER
from kolibri.core.content.hooks import ContentNodeDisplayHook
from kolibri.core.content.hooks import ShareFileHook
from kolibri.core.device.hooks import CheckIsMeteredHook
from kolibri.core.device.utils import allow_learner_unassigned_resource_access
from kolibri.core.device.utils import get_device_setting
Expand Down Expand Up @@ -65,6 +66,7 @@ def plugin_data(self):
"allow_download_on_metered_connection"
),
"canCheckMeteredConnection": CheckIsMeteredHook.is_registered,
"canShareFile": ShareFileHook.is_registered,
"allowGuestAccess": get_device_setting("allow_guest_access"),
"allowLearnerDownloads": get_device_setting(
"allow_learner_download_resources"
Expand Down
2 changes: 1 addition & 1 deletion packages/kolibri-tools/lib/moduleMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module.exports = {
},
'kolibri.themeConfig': 'kolibri/styles/themeConfig',
'kolibri.urls': 'kolibri/urls',
'kolibri.utils.appCapabilities': 'kolibri/utils/appCapabilities',
'kolibri.utils.appCapabilities': null, // Redistributed into more specific code where used.
'kolibri.utils.browserInfo': 'kolibri/utils/browserInfo',
'kolibri.utils.bytesForHumans': 'kolibri/uiText/bytesForHumans',
'kolibri.utils.CatchErrors': 'kolibri/utils/CatchErrors',
Expand Down
1 change: 0 additions & 1 deletion packages/kolibri/internal/apiSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export default {
'kolibri/uiText/notificationStrings': require('kolibri/uiText/notificationStrings'),
'kolibri/urls': require('kolibri/urls'),
'kolibri/utils/CatchErrors': require('kolibri/utils/CatchErrors'),
'kolibri/utils/appCapabilities': require('kolibri/utils/appCapabilities'),
'kolibri/utils/baseClient': require('kolibri/utils/baseClient'),
'kolibri/utils/browserInfo': require('kolibri/utils/browserInfo'),
'kolibri/utils/i18n': require('kolibri/utils/i18n'),
Expand Down
1 change: 0 additions & 1 deletion packages/kolibri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"./uiText/notificationStrings": "./uiText/notificationStrings",
"./urls": "./urls",
"./utils/CatchErrors": "./utils/CatchErrors",
"./utils/appCapabilities": "./utils/appCapabilities",
"./utils/baseClient": "./utils/baseClient",
"./utils/browserInfo": "./utils/browserInfo",
"./utils/i18n": "./utils/i18n",
Expand Down
36 changes: 0 additions & 36 deletions packages/kolibri/utils/appCapabilities.js

This file was deleted.

0 comments on commit c1ec045

Please sign in to comment.