Skip to content

Commit bbcad59

Browse files
committed
MOBILE-4983 chore: Improve admin detection and detect manager role
1 parent 495f897 commit bbcad59

File tree

3 files changed

+70
-18
lines changed

3 files changed

+70
-18
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/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)