Skip to content

Commit 6584918

Browse files
authored
Merge pull request #4512 from alfonso-salces/MOBILE-4798
MOBILE-4798 edit-entry: Show or hide publish state select
2 parents 0bae9dc + 0d1a275 commit 6584918

File tree

4 files changed

+65
-6
lines changed

4 files changed

+65
-6
lines changed

src/addons/blog/constants.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,14 @@ export const ADDON_BLOG_ENTRY_UPDATED = 'blog_entry_updated';
1717
export const ADDON_BLOG_AUTO_SYNCED = 'addon_blog_autom_synced';
1818
export const ADDON_BLOG_MANUAL_SYNCED = 'addon_blog_manual_synced';
1919
export const ADDON_BLOG_SYNC_ID = 'blog';
20+
21+
/**
22+
* Restriction level of user blog visualization.
23+
*/
24+
export const enum CoreSiteBlogLevel {
25+
BLOG_USER_LEVEL = 1,
26+
BLOG_GROUP_LEVEL = 2,
27+
BLOG_COURSE_LEVEL = 3,
28+
BLOG_SITE_LEVEL = 4,
29+
BLOG_GLOBAL_LEVEL = 5,
30+
}

src/addons/blog/pages/edit-entry/edit-entry.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ <h1>{{ entry ? entry.subject : 'addon.blog.addnewentry' | translate }}</h1>
3030
<ion-select-option class="core-select-option-title" [value]="publishState.draft">
3131
{{ 'addon.blog.publishtonoone' | translate }}
3232
</ion-select-option>
33-
<ion-select-option class="core-select-option-title" [value]="publishState.site">
34-
{{ 'addon.blog.publishtosite' | translate }}
35-
</ion-select-option>
33+
@if (!isUserLevel()) {
34+
<ion-select-option class="core-select-option-title" [value]="publishState.site">
35+
{{ 'addon.blog.publishtosite' | translate }}
36+
</ion-select-option>
37+
}
38+
39+
@if (isGlobalLevel()) {
40+
<ion-select-option class="core-select-option-title" [value]="publishState.public">
41+
{{ 'addon.blog.publishtoworld' | translate }}
42+
</ion-select-option>
43+
}
3644
</core-combobox>
3745
</ion-item>
3846

src/addons/blog/pages/edit-entry/edit-entry.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414
import { ContextLevel } from '@/core/constants';
1515
import { CoreSharedModule } from '@/core/shared.module';
16-
import { ADDON_BLOG_ENTRY_UPDATED, ADDON_BLOG_SYNC_ID } from '@addons/blog/constants';
16+
import { ADDON_BLOG_ENTRY_UPDATED, ADDON_BLOG_SYNC_ID, CoreSiteBlogLevel } from '@addons/blog/constants';
1717
import {
1818
AddonBlog,
1919
AddonBlogAddEntryOption,
@@ -23,7 +23,7 @@ import {
2323
AddonBlogPublishState,
2424
} from '@addons/blog/services/blog';
2525
import { AddonBlogOffline } from '@addons/blog/services/blog-offline';
26-
import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
26+
import { Component, computed, ElementRef, OnDestroy, OnInit, signal, ViewChild } from '@angular/core';
2727
import { AddonBlogSync } from '@addons/blog/services/blog-sync';
2828
import { FormControl, FormGroup, Validators } from '@angular/forms';
2929
import { CoreError } from '@classes/errors/error';
@@ -90,6 +90,9 @@ export default class AddonBlogEditEntryPage implements CanLeave, OnInit, OnDestr
9090
siteHomeId?: number;
9191
forceLeave = false;
9292
isOfflineEntry = false;
93+
readonly blogLevel = signal(CoreSiteBlogLevel.BLOG_SITE_LEVEL);
94+
readonly isUserLevel = computed(() => this.blogLevel() === CoreSiteBlogLevel.BLOG_USER_LEVEL);
95+
readonly isGlobalLevel = computed(() => this.blogLevel() === CoreSiteBlogLevel.BLOG_GLOBAL_LEVEL);
9396

9497
/**
9598
* Gives if the form is not pristine. (only for existing entries)
@@ -132,6 +135,13 @@ export default class AddonBlogEditEntryPage implements CanLeave, OnInit, OnDestr
132135
return CoreNavigator.back();
133136
}
134137

138+
const blogLevel = Number(await site.getConfig('bloglevel'));
139+
this.blogLevel.set(isNaN(blogLevel) ? CoreSiteBlogLevel.BLOG_SITE_LEVEL : blogLevel);
140+
141+
if (this.isUserLevel()) {
142+
this.form.controls.publishState.setValue(AddonBlogPublishState.draft);
143+
}
144+
135145
const entryId = CoreNavigator.getRouteParam('id');
136146
const lastModified = CoreNavigator.getRouteNumberParam('lastModified');
137147
const filters: AddonBlogFilter | undefined = CoreNavigator.getRouteParam('filters');
@@ -212,7 +222,7 @@ export default class AddonBlogEditEntryPage implements CanLeave, OnInit, OnDestr
212222
this.entry.summary,
213223
this.entry.summaryfiles,
214224
),
215-
publishState: this.entry.publishstate ?? AddonBlogPublishState.site,
225+
publishState: this.entry?.publishstate ?? AddonBlogPublishState.draft,
216226
associateWithCourse: this.form.controls.associateWithCourse.value,
217227
associateWithModule: this.form.controls.associateWithModule.value,
218228
});

src/addons/blog/tests/behat/edit-entry.feature

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,33 @@ Feature: Edit blog entries
6767
And I should find "Entry with attachments" in the app
6868
And I should find "stub6.txt" in the app
6969
And I should find "stub7.txt" in the app
70+
71+
Scenario: Changing blog visibility to Users can only see their own blog
72+
Given the following config values are set as admin:
73+
| bloglevel | 1 |
74+
And I entered the app as "testuser"
75+
When I press the user menu button in the app
76+
And I press "Blog entries" in the app
77+
And I press "Add a new entry" in the app
78+
And I press "Publish to" in the app
79+
Then I should not find "Anyone on this site" in the app
80+
81+
Scenario: Changing blog visibility to All site users can see all blog entries
82+
Given the following config values are set as admin:
83+
| bloglevel | 4 |
84+
And I entered the app as "testuser"
85+
When I press the user menu button in the app
86+
And I press "Blog entries" in the app
87+
And I press "Add a new entry" in the app
88+
And I press "Publish to" in the app
89+
Then I should find "Anyone on this site" in the app
90+
91+
Scenario: Changing blog visibility to The world can read entries set to be world-accessible
92+
Given the following config values are set as admin:
93+
| bloglevel | 5 |
94+
And I entered the app as "testuser"
95+
When I press the user menu button in the app
96+
And I press "Blog entries" in the app
97+
And I press "Add a new entry" in the app
98+
And I press "Publish to" in the app
99+
Then I should find "Anyone in the world" in the app

0 commit comments

Comments
 (0)