MOBILE-4059 core: Check supportavailability config

Config setting introduced in MDL-74643
main
Noel De Martin 2022-11-07 16:10:50 +01:00
parent fc55a31872
commit c9120bce7b
6 changed files with 66 additions and 6 deletions

View File

@ -2749,10 +2749,21 @@ export type CoreSiteConfigResponse = {
warnings?: CoreWSExternalWarning[];
};
/**
* Possible values for 'supportavailability' config.
*/
export const enum CoreSiteConfigSupportAvailability {
Disabled = 0,
Authenticated = 1,
Anyone = 2,
}
/**
* Site config indexed by name.
*/
export type CoreSiteConfig = {[name: string]: string};
export type CoreSiteConfig = Record<string, string> & {
supportavailability?: string; // String representation of CoreSiteConfigSupportAvailability.
};
/**
* Result of WS tool_mobile_get_public_config.
@ -2784,6 +2795,7 @@ export type CoreSitePublicConfigResponse = {
agedigitalconsentverification?: boolean; // Whether age digital consent verification is enabled.
supportname?: string; // Site support contact name (only if age verification is enabled).
supportemail?: string; // Site support contact email (only if age verification is enabled).
supportavailability?: CoreSiteConfigSupportAvailability;
supportpage?: string; // Site support contact url.
autolang?: number; // Whether to detect default language from browser setting.
lang?: string; // Default language for the site.

View File

@ -0,0 +1,19 @@
@auth @core_auth @app @javascript @lms_from4.0 @lms_upto4.0
Feature: Test basic usage of login in app
I need basic login functionality to work
Background:
Given the following "users" exist:
| username | firstname | lastname |
| student1 | david | student |
Scenario: Forgot password
When I enter the app
And I press "Forgotten your username or password?" in the app
And I set the field "Enter either username or email address" to "student1"
And I press "Search" in the app
Then I should find "Success" in the app
When I press "OK" in the app
And I press "Forgotten your username or password?" in the app
Then I should find "Contact support" in the app

View File

@ -135,8 +135,10 @@ Feature: Test basic usage of login in app
When I press "Reconnect" in the app
Then I should find "Acceptance test site" in the app
@lms_from4.0
@lms_from4.1
Scenario: Forgot password
Given the following config values are set as admin:
| supportavailability | 2 |
When I enter the app
And I press "Forgotten your username or password?" in the app
And I set the field "Enter either username or email address" to "student1"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { CoreSite } from '@classes/site';
import { CoreSite, CoreSiteConfigSupportAvailability } from '@classes/site';
import { CoreSites } from '@services/sites';
import { CoreUserSupportConfig } from './support-config';
@ -42,8 +42,28 @@ export class CoreUserAuthenticatedSupportConfig extends CoreUserSupportConfig {
* @inheritdoc
*/
canContactSupport(): boolean {
return this.site.isVersionGreaterEqualThan('4.0')
&& !this.site.isFeatureDisabled('NoDelegate_CoreUserSupport');
if (this.site.isFeatureDisabled('NoDelegate_CoreUserSupport')) {
return false;
}
if (this.site.isVersionGreaterEqualThan('4.1')) {
if (!this.site.config || !('supportavailability' in this.site.config)) {
return false;
}
const supportAvailability = Number(this.site.config.supportavailability);
return supportAvailability === CoreSiteConfigSupportAvailability.Authenticated
|| supportAvailability === CoreSiteConfigSupportAvailability.Anyone;
}
if (this.site.isVersionGreaterEqualThan('4.0')) {
// This feature was always available in 4.0.
return true;
}
// This feature wasn't available before 4.0.
return false;
}
/**

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
import { CoreSitePublicConfigResponse } from '@classes/site';
import { CoreSiteConfigSupportAvailability, CoreSitePublicConfigResponse } from '@classes/site';
import { CoreUserNullSupportConfig } from '@features/user/classes/support/null-support-config';
import { CoreSites } from '@services/sites';
import { CoreUtils } from '@services/utils/utils';
@ -51,6 +51,12 @@ export class CoreUserGuestSupportConfig extends CoreUserSupportConfig {
* @inheritdoc
*/
canContactSupport(): boolean {
// This config was introduced in 4.1, if it's missing we can assume the site is 4.0 or lower.
if ('supportavailability' in this.config) {
return this.config.supportavailability === CoreSiteConfigSupportAvailability.Anyone;
}
// This config is only available to guests since 4.0, if it's missing we can assume guests can't contact support.
return 'supportpage' in this.config;
}

View File

@ -5,6 +5,7 @@ Feature: Site support
Given the following "users" exist:
| username | firstname | lastname |
| student1 | Student | Student |
And I am logged in as "student1"
Scenario: Uses default support page
Given I entered the app as "student1"