From 6a52b02eeb307eb675c1d24edd4e213b7ad0cb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pau=20Ferrer=20Oca=C3=B1a?= Date: Wed, 28 Feb 2024 16:17:57 +0100 Subject: [PATCH] MOBILE-4498 comments: Use advanced features to check if comments are on --- .../block/comments/services/block-handler.ts | 8 ++++ src/addons/blog/pages/entries/entries.ts | 2 +- .../submission/comments/component/comments.ts | 2 +- src/addons/mod/data/pages/entry/entry.ts | 2 +- .../mod/data/services/handlers/prefetch.ts | 2 +- .../mod/data/tests/behat/entries.feature | 28 ++++++++++++-- src/addons/mod/glossary/pages/entry/entry.ts | 2 +- .../glossary/services/handlers/prefetch.ts | 2 +- .../comments/components/comments/comments.ts | 20 +++++----- .../components/comments/core-comments.html | 2 +- .../features/comments/services/comments.ts | 38 ++++++++++++++++--- 11 files changed, 81 insertions(+), 27 deletions(-) diff --git a/src/addons/block/comments/services/block-handler.ts b/src/addons/block/comments/services/block-handler.ts index 7ca6c2ef1..8a77ac7a4 100644 --- a/src/addons/block/comments/services/block-handler.ts +++ b/src/addons/block/comments/services/block-handler.ts @@ -18,6 +18,7 @@ import { CoreBlockOnlyTitleComponent } from '@features/block/components/only-tit import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler'; import { CoreCourseBlock } from '@features/course/services/course'; import { makeSingleton } from '@singletons'; +import { CoreComments } from '@features/comments/services/comments'; /** * Block handler. @@ -28,6 +29,13 @@ export class AddonBlockCommentsHandlerService extends CoreBlockBaseHandler { name = 'AddonBlockComments'; blockName = 'comments'; + /** + * @inheritdoc + */ + async isEnabled(): Promise { + return await CoreComments.areCommentsEnabled(); + } + /** * Returns the data needed to render the block. * diff --git a/src/addons/blog/pages/entries/entries.ts b/src/addons/blog/pages/entries/entries.ts index a570d0786..3441163a0 100644 --- a/src/addons/blog/pages/entries/entries.ts +++ b/src/addons/blog/pages/entries/entries.ts @@ -139,7 +139,7 @@ export class AddonBlogEntriesPage implements OnInit { this.contextInstanceId = 0; } - this.commentsEnabled = !CoreComments.areCommentsDisabledInSite(); + this.commentsEnabled = CoreComments.areCommentsEnabledInSite(); this.tagsEnabled = CoreTag.areTagsAvailableInSite(); const deepLinkManager = new CoreMainMenuDeepLinkManager(); diff --git a/src/addons/mod/assign/submission/comments/component/comments.ts b/src/addons/mod/assign/submission/comments/component/comments.ts index 1488aa159..46cfe5861 100644 --- a/src/addons/mod/assign/submission/comments/component/comments.ts +++ b/src/addons/mod/assign/submission/comments/component/comments.ts @@ -33,7 +33,7 @@ export class AddonModAssignSubmissionCommentsComponent extends AddonModAssignSub constructor() { super(); - this.commentsEnabled = !CoreComments.areCommentsDisabledInSite(); + this.commentsEnabled = CoreComments.areCommentsEnabledInSite(); } /** diff --git a/src/addons/mod/data/pages/entry/entry.ts b/src/addons/mod/data/pages/entry/entry.ts index c8bd10562..1c46e26ef 100644 --- a/src/addons/mod/data/pages/entry/entry.ts +++ b/src/addons/mod/data/pages/entry/entry.ts @@ -157,7 +157,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy { return; } - this.commentsEnabled = !CoreComments.areCommentsDisabledInSite(); + this.commentsEnabled = CoreComments.areCommentsEnabledInSite(); await this.fetchEntryData(); } diff --git a/src/addons/mod/data/services/handlers/prefetch.ts b/src/addons/mod/data/services/handlers/prefetch.ts index 49a2027a8..c8a33a75c 100644 --- a/src/addons/mod/data/services/handlers/prefetch.ts +++ b/src/addons/mod/data/services/handlers/prefetch.ts @@ -230,7 +230,7 @@ export class AddonModDataPrefetchHandlerService extends CoreCourseActivityPrefet // Prefetch the database data. const database = info.database; - const commentsEnabled = !CoreComments.areCommentsDisabledInSite(); + const commentsEnabled = CoreComments.areCommentsEnabledInSite(); const promises: Promise[] = []; diff --git a/src/addons/mod/data/tests/behat/entries.feature b/src/addons/mod/data/tests/behat/entries.feature index dff57b440..e1f6f993f 100644 --- a/src/addons/mod/data/tests/behat/entries.feature +++ b/src/addons/mod/data/tests/behat/entries.feature @@ -19,8 +19,8 @@ Feature: Users can manage entries in database activities | student1 | C1 | student | | student2 | C1 | student | And the following "activities" exist: - | activity | name | intro | course | idnumber | - | data | Web links | Useful links | C1 | data1 | + | activity | name | intro | course | idnumber | comments | + | data | Web links | Useful links | C1 | data1 | 0 | And the following "mod_data > fields" exist: | database | type | name | description | | data1 | text | URL | URL link | @@ -38,7 +38,13 @@ Feature: Users can manage entries in database activities And I should find "Moodle community site" in the app Scenario: Browse entry - Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app + Given the following "activities" exist: + | activity | name | intro | course | idnumber | comments | + | data | Data with comments | - | C1 | data2 | 1 | + And the following "mod_data > fields" exist: + | database | type | name | description | + | data2 | text | Description | Description | + And I entered the data activity "Web links" on course "Course 1" as "student1" in the app # TODO Create and use a generator for database entries. When I press "Add entries" in the app @@ -54,6 +60,7 @@ Feature: Users can manage entries in database activities And I press "Save" near "Web links" in the app And I press "Show more" near "Moodle community site" in the app Then I should find "Moodle community site" in the app + And I should not find "Comments" in the app And I should be able to press "Previous" in the app But I should not be able to press "Next" in the app @@ -70,6 +77,21 @@ Feature: Users can manage entries in database activities And I should find "Moodle community site" in the app And I should find "Moodle Cloud" in the app + Given I entered the data activity "Data with comments" on course "Course 1" as "student1" in the app + When I press "Add entries" in the app + And I set the following fields to these values in the app: + | Description | Moodle community site | + And I press "Save" near "Data with comments" in the app + And I press "Show more" near "Moodle community site" in the app + Then I should find "Moodle community site" in the app + And I should find "Comments" in the app + + Given the following config values are set as admin: + | usecomments | 0 | + And I entered the data activity "Data with comments" on course "Course 1" as "student1" in the app + When I press "Show more" near "Moodle community site" in the app + Then I should not find "Comments" in the app + Scenario: Students can not edit or delete other user's entries from list and single view in the app Given I entered the data activity "Web links" on course "Course 1" as "student1" in the app And I press "Add entries" in the app diff --git a/src/addons/mod/glossary/pages/entry/entry.ts b/src/addons/mod/glossary/pages/entry/entry.ts index 3160c1818..f4b946f77 100644 --- a/src/addons/mod/glossary/pages/entry/entry.ts +++ b/src/addons/mod/glossary/pages/entry/entry.ts @@ -99,7 +99,7 @@ export class AddonModGlossaryEntryPage implements OnInit, OnDestroy { try { this.courseId = CoreNavigator.getRequiredRouteNumberParam('courseId'); this.tagsEnabled = CoreTag.areTagsAvailableInSite(); - this.commentsEnabled = !CoreComments.areCommentsDisabledInSite(); + this.commentsEnabled = CoreComments.areCommentsEnabledInSite(); this.cmId = CoreNavigator.getRequiredRouteNumberParam('cmId'); const entrySlug = CoreNavigator.getRequiredRouteParam('entrySlug'); diff --git a/src/addons/mod/glossary/services/handlers/prefetch.ts b/src/addons/mod/glossary/services/handlers/prefetch.ts index f9566bd0e..08690f68c 100644 --- a/src/addons/mod/glossary/services/handlers/prefetch.ts +++ b/src/addons/mod/glossary/services/handlers/prefetch.ts @@ -155,7 +155,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr options, ).then((entries) => { const promises: Promise[] = []; - const commentsEnabled = !CoreComments.areCommentsDisabledInSite(); + const commentsEnabled = CoreComments.areCommentsEnabledInSite(); entries.forEach((entry) => { // Don't fetch individual entries, it's too many WS calls. diff --git a/src/core/features/comments/components/comments/comments.ts b/src/core/features/comments/components/comments/comments.ts index 26fed4370..31b1f85f9 100644 --- a/src/core/features/comments/components/comments/comments.ts +++ b/src/core/features/comments/components/comments/comments.ts @@ -45,7 +45,7 @@ export class CoreCommentsCommentsComponent implements OnInit, OnChanges, OnDestr commentsLoaded = false; commentsCount = ''; countError = false; - disabled = false; + enabled = false; protected updateSiteObserver?: CoreEventObserver; protected refreshCommentsObserver?: CoreEventObserver; @@ -55,15 +55,15 @@ export class CoreCommentsCommentsComponent implements OnInit, OnChanges, OnDestr this.onLoading = new EventEmitter(); - this.disabled = CoreComments.areCommentsDisabledInSite(); + this.enabled = CoreComments.areCommentsEnabledInSite(); // Update visibility if current site info is updated. this.updateSiteObserver = CoreEvents.on(CoreEvents.SITE_UPDATED, () => { - const wasDisabled = this.disabled; + const wasEnabled = this.enabled; - this.disabled = CoreComments.areCommentsDisabledInSite(); + this.enabled = CoreComments.areCommentsEnabledInSite(); - if (wasDisabled && !this.disabled) { + if (!wasEnabled && this.enabled) { this.fetchData(); } }, CoreSites.getCurrentSiteId()); @@ -123,7 +123,7 @@ export class CoreCommentsCommentsComponent implements OnInit, OnChanges, OnDestr * Fetch comments data. */ async fetchData(): Promise { - if (this.disabled) { + if (!this.enabled) { return; } @@ -173,12 +173,10 @@ export class CoreCommentsCommentsComponent implements OnInit, OnChanges, OnDestr * Opens the comments page. */ openComments(e?: Event): void { - if (e) { - e.preventDefault(); - e.stopPropagation(); - } + e?.preventDefault(); + e?.stopPropagation(); - if (this.disabled || this.countError) { + if (!this.enabled || this.countError) { return; } diff --git a/src/core/features/comments/components/comments/core-comments.html b/src/core/features/comments/components/comments/core-comments.html index 0eb566d94..a09077f48 100644 --- a/src/core/features/comments/components/comments/core-comments.html +++ b/src/core/features/comments/components/comments/core-comments.html @@ -1,4 +1,4 @@ - +