MOBILE-4498 comments: Use advanced features to check if comments are on

main
Pau Ferrer Ocaña 2024-02-28 16:17:57 +01:00
parent 65ed0d2b1c
commit 6a52b02eeb
11 changed files with 81 additions and 27 deletions

View File

@ -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<boolean> {
return await CoreComments.areCommentsEnabled();
}
/**
* Returns the data needed to render the block.
*

View File

@ -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();

View File

@ -33,7 +33,7 @@ export class AddonModAssignSubmissionCommentsComponent extends AddonModAssignSub
constructor() {
super();
this.commentsEnabled = !CoreComments.areCommentsDisabledInSite();
this.commentsEnabled = CoreComments.areCommentsEnabledInSite();
}
/**

View File

@ -157,7 +157,7 @@ export class AddonModDataEntryPage implements OnInit, OnDestroy {
return;
}
this.commentsEnabled = !CoreComments.areCommentsDisabledInSite();
this.commentsEnabled = CoreComments.areCommentsEnabledInSite();
await this.fetchEntryData();
}

View File

@ -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<unknown>[] = [];

View File

@ -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

View File

@ -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<string>('entrySlug');

View File

@ -155,7 +155,7 @@ export class AddonModGlossaryPrefetchHandlerService extends CoreCourseActivityPr
options,
).then((entries) => {
const promises: Promise<unknown>[] = [];
const commentsEnabled = !CoreComments.areCommentsDisabledInSite();
const commentsEnabled = CoreComments.areCommentsEnabledInSite();
entries.forEach((entry) => {
// Don't fetch individual entries, it's too many WS calls.

View File

@ -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<boolean>();
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<void> {
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;
}

View File

@ -1,4 +1,4 @@
<ng-container *ngIf="!disabled">
<ng-container *ngIf="enabled">
<core-loading *ngIf="!showItem" [hideUntil]="commentsLoaded" [fullscreen]="false">
<button *ngIf="!countError" (click)="openComments($event)" class="as-link">
{{ 'core.comments.commentscount' | translate : {'$a': commentsCount} }}

View File

@ -181,15 +181,14 @@ export class CoreCommentsProvider {
}
/**
* Check if Calendar is disabled in a certain site.
* Check if comments are disabled in a certain site.
*
* @param site Site. If not defined, use current site.
* @returns Whether it's disabled.
* @deprecated since 4.4. Use areCommentsEnabledInSite instead.
*/
areCommentsDisabledInSite(site?: CoreSite): boolean {
site = site || CoreSites.getCurrentSite();
return !!site?.isFeatureDisabled('NoDelegate_CoreComments');
return !this.areCommentsEnabledInSite(site);
}
/**
@ -197,11 +196,38 @@ export class CoreCommentsProvider {
*
* @param siteId Site Id. If not defined, use current site.
* @returns Promise resolved with true if disabled, rejected or resolved with false otherwise.
* @deprecated since 4.4. Use areCommentsEnabled instead.
*/
async areCommentsDisabled(siteId?: string): Promise<boolean> {
return !this.areCommentsEnabled(siteId);
}
/**
* Check if comments are enabled in a certain site.
*
* @param site Site. If not defined, use current site.
* @returns Whether it's enabled.
*/
areCommentsEnabledInSite(site?: CoreSite): boolean {
site = site || CoreSites.getCurrentSite();
if (!site) {
return false;
}
return site.canUseAdvancedFeature('usecomments') && !site.isFeatureDisabled('NoDelegate_CoreComments');
}
/**
* Check if comments are enabled in a certain site.
*
* @param siteId Site Id. If not defined, use current site.
* @returns Promise resolved with true if enabled, rejected or resolved with false otherwise.
*/
async areCommentsEnabled(siteId?: string): Promise<boolean> {
const site = await CoreSites.getSite(siteId);
return this.areCommentsDisabledInSite(site);
return this.areCommentsEnabledInSite(site);
}
/**
@ -323,7 +349,7 @@ export class CoreCommentsProvider {
const site = await CoreSites.getSite(siteId);
// First check if it's disabled.
if (this.areCommentsDisabledInSite(site)) {
if (!this.areCommentsEnabledInSite(site)) {
return false;
}