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

Commit

Permalink
[MM-20460] Migrate 'components/permissions_gates/channel_permission_g…
Browse files Browse the repository at this point in the history
…ate' module and associated tests to TypeScript (#6601)

* Migrate channel_permission_gate to TypeScript

* Rename test file to TypeScript

Co-authored-by: Mattermod <[email protected]>
  • Loading branch information
didithilmy and mattermod committed Oct 6, 2020
1 parent 99d650f commit 425cc09
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ exports[`components/permissions_gates ChannelPermissionGate should match snapsho
channelId="invalid_id"
dispatch={[Function]}
hasPermission={false}
invert={false}
permissions={
Array [
"test_channel_permission",
Expand Down Expand Up @@ -64,7 +63,6 @@ exports[`components/permissions_gates ChannelPermissionGate should match snapsho
channelId="channel_id"
dispatch={[Function]}
hasPermission={false}
invert={false}
permissions={
Array [
"invalid_permission",
Expand Down Expand Up @@ -144,7 +142,6 @@ exports[`components/permissions_gates ChannelPermissionGate should match snapsho
channelId="channel_id"
dispatch={[Function]}
hasPermission={true}
invert={false}
permissions={
Array [
"test_channel_permission",
Expand Down Expand Up @@ -225,7 +222,6 @@ exports[`components/permissions_gates ChannelPermissionGate should match snapsho
channelId="channel_id"
dispatch={[Function]}
hasPermission={true}
invert={false}
permissions={
Array [
"test_system_permission",
Expand Down Expand Up @@ -267,7 +263,6 @@ exports[`components/permissions_gates ChannelPermissionGate should match snapsho
channelId="channel_id"
dispatch={[Function]}
hasPermission={true}
invert={false}
permissions={
Array [
"test_team_permission",
Expand Down Expand Up @@ -309,7 +304,6 @@ exports[`components/permissions_gates ChannelPermissionGate should match snapsho
channelId="channel_id"
dispatch={[Function]}
hasPermission={true}
invert={false}
permissions={
Array [
"test_channel_permission",
Expand Down Expand Up @@ -351,7 +345,6 @@ exports[`components/permissions_gates ChannelPermissionGate should match snapsho
channelId="channel_id"
dispatch={[Function]}
hasPermission={false}
invert={false}
permissions={
Array [
"invalid_permission",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React from 'react';

type Props = {

/**
* Channel to check the permission
*/
channelId?: string;

/**
* Team to check the permission
*/
teamId?: string;

/**
* Permissions enough to pass the gate (binary OR)
*/
permissions: string[];

/**
* Has permission
*/
hasPermission: boolean;

/**
* Invert the permission (used for else)
*/
invert?: boolean;

/**
* Content protected by the permissions gate
*/
children: React.ReactNode;
}

export default class ChannelPermissionGate extends React.PureComponent<Props> {
render() {
const {hasPermission, children, invert = false} = this.props;

if (hasPermission && !invert) {
return children;
}
if (!hasPermission && invert) {
return children;
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
import {connect} from 'react-redux';

import {haveIChannelPermission} from 'mattermost-redux/selectors/entities/roles';
import {GlobalState} from 'mattermost-redux/types/store';

import ChannelPermissionGate from './channel_permission_gate.jsx';
import ChannelPermissionGate from './channel_permission_gate';

function mapStateToProps(state, ownProps) {
type Props = {
channelId?: string;
teamId?: string;
permissions: string[];
}

function mapStateToProps(state: GlobalState, ownProps: Props) {
if (!ownProps.channelId || ownProps.teamId === null || typeof ownProps.teamId === 'undefined') {
return {hasPermission: false};
}
Expand Down

0 comments on commit 425cc09

Please sign in to comment.