Skip to content

Commit c588e46

Browse files
authored
Merge pull request #4696 from crazyserver/MOBILE-4983
Mobile 4983 is admin / is manager
2 parents 28b8a5b + bbcad59 commit c588e46

File tree

4 files changed

+85
-21
lines changed

4 files changed

+85
-21
lines changed

src/core/classes/sites/authenticated-site.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,25 @@ export class CoreAuthenticatedSite extends CoreUnauthenticatedSite {
232232

233233
/**
234234
* Check if current user is Admin.
235-
* Works properly since v3.8. See more in: {@link https://moodle.atlassian.net/browse/MDL-65550}
235+
* Works properly since Moodle 3.8. See more in: {@link https://moodle.atlassian.net/browse/MDL-65550}
236236
*
237237
* @returns Whether the user is Admin.
238238
*/
239239
isAdmin(): boolean {
240-
return this.getInfo()?.userissiteadmin ?? false;
240+
const info = this.getInfo();
241+
242+
return (info?.userissiteadmin || info?.usercanchangeconfig) ?? false;
243+
}
244+
245+
/**
246+
* Check if current user is Manager.
247+
* Works properly since Moodle 5.2. See more in: {@link https://moodle.atlassian.net/browse/MDL-87034}
248+
*
249+
* @returns Whether the user is Manager. Will return false if cannot be determined.
250+
* @since 5.2
251+
*/
252+
isManager(): boolean {
253+
return this.getInfo()?.usercanviewconfig ?? false;
241254
}
242255

243256
/**

src/core/classes/sites/unauthenticated-site.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export class CoreUnauthenticatedSite {
253253
* Get the public config of this site.
254254
*
255255
* @param options Options.
256+
* @param options.readingStrategy Reading strategy to use.
256257
* @returns Promise resolved with public config. Rejected with an object if error, see CoreWS.callAjax.
257258
*/
258259
async getPublicConfig(options: { readingStrategy?: CoreSitesReadingStrategy } = {}): Promise<CoreSitePublicConfigResponse> {
@@ -571,7 +572,9 @@ export class CoreUnauthenticatedSite {
571572
}
572573

573574
/**
574-
* Result of WS core_webservice_get_site_info.
575+
* Data returned by core_webservice_get_site_info WS.
576+
*
577+
* WS Description: Return some site info / user info / list web service functions
575578
*/
576579
export type CoreSiteInfoResponse = {
577580
sitename: string; // Site name.
@@ -583,6 +586,11 @@ export type CoreSiteInfoResponse = {
583586
userid: number; // User id.
584587
siteurl: string; // Site url.
585588
userpictureurl: string; // The user profile picture.
589+
// Warning: this url is the public URL that only works when forcelogin is set to NO and guestaccess is set to YES.
590+
// In order to retrieve user profile pictures independently of the Moodle config, replace "pluginfile.php" by
591+
// "webservice/pluginfile.php?token=WSTOKEN&file="
592+
// Of course the user can only see profile picture depending
593+
// on his/her permissions. Moreover it is recommended to use HTTPS too.
586594
functions: {
587595
name: string; // Function name.
588596
version: string; // The version number of the component to which the function belongs.
@@ -600,16 +608,20 @@ export type CoreSiteInfoResponse = {
600608
userquota?: number; // User quota (bytes). 0 means user can ignore the quota.
601609
usermaxuploadfilesize?: number; // User max upload file size (bytes). -1 means the user can ignore the upload file size.
602610
userhomepage?: CoreSiteInfoUserHomepage; // The default home page for the user.
603-
userhomepageurl?: string; // @since 4.5. The URL of the custom user home page when using HOMEPAGE_URL.
611+
userhomepageurl?: string; // @since 4.5. The URL of default home page when userhomepage is 4 (HOMEPAGE_URL).
604612
userprivateaccesskey?: string; // Private user access key for fetching files.
605613
siteid?: number; // Site course ID.
606614
sitecalendartype?: string; // Calendar type set in the site.
607615
usercalendartype?: string; // Calendar typed used by the user.
608616
userissiteadmin?: boolean; // Whether the user is a site admin or not.
609617
theme?: string; // Current theme for the user.
610618
limitconcurrentlogins?: number; // @since 4.0. Number of concurrent sessions allowed.
611-
usersessionscount?: number; // @since 4.0. Number of active sessions for current user. Only if limitconcurrentlogins is used.
619+
usersessionscount?: number; // @since 4.0. Number of active sessions for current user.
620+
// Only returned when limitconcurrentlogins is used.
612621
policyagreed?: number; // @since 4.4. Whether user accepted all the policies.
622+
usercanchangeconfig?: boolean; // @since 5.2. Whether the user can change the site configuration.
623+
usercanviewconfig?: boolean; // @since 5.2. Whether the user can view the site administration tree.
624+
sitesecret?: string; // @since 5.2. The site secret, only returned to users with moodle/site:config capability (usually admins).
613625
};
614626

615627
/**

src/core/features/settings/pages/dev/dev.html

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,34 @@ <h1>{{ 'core.settings.developeroptions' | translate }}</h1>
9797

9898
@if (siteId) {
9999

100+
<ion-item class="ion-text-wrap">
101+
<ion-label>
102+
<p class="item-heading">Is admin</p>
103+
<p>
104+
@if (isAdmin) {
105+
{{ 'core.yes' | translate }}
106+
} @else {
107+
{{ 'core.no' | translate }}
108+
}
109+
</p>
110+
</ion-label>
111+
</ion-item>
112+
113+
@if (isManager !== undefined) {
114+
<ion-item class="ion-text-wrap">
115+
<ion-label>
116+
<p class="item-heading">Is manager</p>
117+
<p>
118+
@if (isManager) {
119+
{{ 'core.yes' | translate }}
120+
} @else {
121+
{{ 'core.no' | translate }}
122+
}
123+
</p>
124+
</ion-label>
125+
</ion-item>
126+
}
127+
100128
<ion-item class="ion-text-wrap">
101129
<ion-label>
102130
<p class="item-heading">WebService token</p>
@@ -151,16 +179,17 @@ <h1>{{ 'core.settings.developeroptions' | translate }}</h1>
151179
<h2>Disabled features</h2>
152180
</ion-label>
153181
</ion-item-divider>
154-
@if (disabledFeatures.length === 0) {
182+
@for (feature of disabledFeatures; track feature) {
183+
<ion-item class="ion-text-wrap">
184+
<ion-label>
185+
<p class="item-heading">{{ feature }}</p>
186+
</ion-label>
187+
</ion-item>
188+
} @empty {
155189
<ion-item>
156190
<ion-label>There are no features disabled.</ion-label>
157191
</ion-item>
158192
}
159-
<ion-item class="ion-text-wrap" *ngFor="let feature of disabledFeatures">
160-
<ion-label>
161-
<p class="item-heading">{{ feature }}</p>
162-
</ion-label>
163-
</ion-item>
164193

165194
<ion-item-divider>
166195
<ion-label>
@@ -191,17 +220,19 @@ <h2>WebService overrides</h2>
191220
<h2>Site plugins</h2>
192221
</ion-label>
193222
</ion-item-divider>
194-
@if (sitePlugins.length === 0) {
223+
224+
@for (plugin of sitePlugins; track plugin) {
225+
<ion-item class="ion-text-wrap">
226+
<ion-label>
227+
<p class="item-heading">{{ plugin.addon }} ({{plugin.component}})</p>
228+
<p>{{plugin.version}}</p>
229+
</ion-label>
230+
</ion-item>
231+
} @empty {
195232
<ion-item>
196233
<ion-label>There are no site plugins installed</ion-label>
197234
</ion-item>
198235
}
199-
<ion-item class="ion-text-wrap" *ngFor="let plugin of sitePlugins">
200-
<ion-label>
201-
<p class="item-heading">{{ plugin.addon }} ({{plugin.component}})</p>
202-
<p>{{plugin.version}}</p>
203-
</ion-label>
204-
</ion-item>
205236

206237
}
207238
</ion-list>

src/core/features/settings/pages/dev/dev.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { CoreText } from '@singletons/text';
3434
import { CoreAlerts } from '@services/overlays/alerts';
3535
import { CoreLoadings } from '@services/overlays/loadings';
3636
import { CoreSharedModule } from '@/core/shared.module';
37+
import { CoreSitePlugins } from '@features/siteplugins/services/siteplugins';
3738

3839
/**
3940
* Page that displays the developer options.
@@ -61,6 +62,8 @@ export default class CoreSettingsDevPage implements OnInit {
6162
stagingSitesCount = 0;
6263
enableStagingSites?: boolean;
6364
previousEnableStagingSites?: boolean;
65+
isAdmin = false;
66+
isManager?: boolean;
6467

6568
disabledFeatures: string[] = [];
6669

@@ -115,23 +118,28 @@ export default class CoreSettingsDevPage implements OnInit {
115118
this.autoLoginTimeBetweenRequests = await currentSite.getAutoLoginMinTimeBetweenRequests();
116119
this.lastAutoLoginTime = currentSite.getLastAutoLoginTime();
117120

121+
this.isAdmin = currentSite.isAdmin();
122+
// Check isManager only if LMS version is >= 5.2 because the function works properly since that version.
123+
if (currentSite.isVersionGreaterEqualThan('5.2')) {
124+
this.isManager = currentSite.isManager();
125+
}
126+
118127
document.head.querySelectorAll('style').forEach((style) => {
119128
if (this.siteId && style.id.endsWith(this.siteId)) {
120129
if (style.innerHTML.length > 0) {
121130
this.remoteStylesCount++;
122131
}
123-
this.remoteStyles = this.remoteStyles || style.getAttribute('media') != 'disabled';
132+
this.remoteStyles = this.remoteStyles || style.getAttribute('media') !== 'disabled';
124133
}
125134

126135
if (style.id.startsWith('siteplugin-')) {
127136
if (style.innerHTML.length > 0) {
128137
this.pluginStylesCount++;
129138
}
130-
this.pluginStyles = this.pluginStyles || style.getAttribute('media') != 'disabled';
139+
this.pluginStyles = this.pluginStyles || style.getAttribute('media') !== 'disabled';
131140
}
132141
});
133142

134-
const { CoreSitePlugins } = await import('@features/siteplugins/services/siteplugins');
135143
this.sitePlugins = CoreSitePlugins.getCurrentSitePluginList().map((plugin) => ({
136144
addon: plugin.addon,
137145
component: plugin.component,

0 commit comments

Comments
 (0)