Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add customisation to make certain UI components invisible to students
Browse files Browse the repository at this point in the history
Requires #6922
  • Loading branch information
turt2live authored and Kerry Archibald committed Dec 16, 2021
1 parent eea8b3a commit 06e66b1
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright 2021 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Dev note: this customisation point is heavily inspired by UIFeature flags, though
// with an intention of being used for more complex switching on whether or not a feature
// should be shown.

// Populate this class with the details of your customisations when copying it.

import { UIComponent } from "../settings/UIFeature";
import SdkConfig from "../../SdkConfig";
import { MatrixClientPeg } from "../../MatrixClientPeg";

/**
* Determines whether or not the active MatrixClient user should be able to use
* the given UI component. If shown, the user might still not be able to use the
* component depending on their contextual permissions. For example, invite options
* might be shown to the user but they won't have permission to invite users to
* the current room: the button will appear disabled.
* @param {UIComponent} component The component to check visibility for.
* @returns {boolean} True (default) if the user is able to see the component, false
* otherwise.
*/
function shouldShowComponent(component: UIComponent): boolean {
const studentInvisibleComponents = [
UIComponent.InviteUsers,
UIComponent.CreateRooms,
];
if (!studentInvisibleComponents.includes(component)) return true;

const userPrefix = SdkConfig.get()['studentNamePrefix'];
const isStudent = userPrefix && MatrixClientPeg.get().getUserId().startsWith(userPrefix);
return !isStudent;
}

// This interface summarises all available customisation points and also marks
// them all as optional. This allows customisers to only define and export the
// customisations they need while still maintaining type safety.
export interface IComponentVisibilityCustomisations {
shouldShowComponent?: typeof shouldShowComponent;
}

export const ComponentVisibilityCustomisations: IComponentVisibilityCustomisations = {
shouldShowComponent: shouldShowComponent,
};

0 comments on commit 06e66b1

Please sign in to comment.