Only show admin tools to privileged users
This commit is contained in:
parent
9dd77af5ef
commit
3e64333ada
1 changed files with 49 additions and 47 deletions
|
@ -17,50 +17,62 @@ limitations under the License.
|
||||||
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { MatrixClient } from 'matrix-js-sdk';
|
||||||
import dis from '../../../dispatcher';
|
import dis from '../../../dispatcher';
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import { GroupMemberType } from '../../../groups';
|
import { GroupMemberType } from '../../../groups';
|
||||||
import { groupMemberFromApiObject } from '../../../groups';
|
import GroupStoreCache from '../../../stores/GroupStoreCache';
|
||||||
import withMatrixClient from '../../../wrappers/withMatrixClient';
|
|
||||||
import AccessibleButton from '../elements/AccessibleButton';
|
import AccessibleButton from '../elements/AccessibleButton';
|
||||||
import GeminiScrollbar from 'react-gemini-scrollbar';
|
import GeminiScrollbar from 'react-gemini-scrollbar';
|
||||||
|
|
||||||
|
module.exports = React.createClass({
|
||||||
module.exports = withMatrixClient(React.createClass({
|
|
||||||
displayName: 'GroupMemberInfo',
|
displayName: 'GroupMemberInfo',
|
||||||
|
|
||||||
|
contextTypes: {
|
||||||
|
matrixClient: PropTypes.instanceOf(MatrixClient),
|
||||||
|
},
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
matrixClient: PropTypes.object.isRequired,
|
|
||||||
groupId: PropTypes.string,
|
groupId: PropTypes.string,
|
||||||
groupMember: GroupMemberType,
|
groupMember: GroupMemberType,
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
fetching: false,
|
|
||||||
removingUser: false,
|
removingUser: false,
|
||||||
groupMembers: null,
|
isUserPrivilegedInGroup: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
this._fetchMembers();
|
this._initGroupStore(this.props.groupId);
|
||||||
},
|
},
|
||||||
|
|
||||||
_fetchMembers: function() {
|
componentWillReceiveProps(newProps) {
|
||||||
this.setState({fetching: true});
|
if (newProps.groupId !== this.props.groupId) {
|
||||||
this.props.matrixClient.getGroupUsers(this.props.groupId).then((result) => {
|
this._unregisterGroupStore();
|
||||||
this.setState({
|
this._initGroupStore(newProps.groupId);
|
||||||
groupMembers: result.chunk.map((apiMember) => {
|
}
|
||||||
return groupMemberFromApiObject(apiMember);
|
},
|
||||||
}),
|
|
||||||
fetching: false,
|
_initGroupStore(groupId) {
|
||||||
});
|
this._groupStore = GroupStoreCache.getGroupStore(
|
||||||
}).catch((e) => {
|
this.context.matrixClient, this.props.groupId,
|
||||||
this.setState({fetching: false});
|
);
|
||||||
console.error("Failed to get group groupMember list: ", e);
|
this._groupStore.registerListener(this.onGroupStoreUpdated);
|
||||||
|
},
|
||||||
|
|
||||||
|
_unregisterGroupStore() {
|
||||||
|
if (this._groupStore) {
|
||||||
|
this._groupStore.unregisterListener(this.onGroupStoreUpdated);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onGroupStoreUpdated: function() {
|
||||||
|
this.setState({
|
||||||
|
isUserPrivilegedInGroup: this._groupStore.isUserPrivileged(),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -74,7 +86,7 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
if (!proceed) return;
|
if (!proceed) return;
|
||||||
|
|
||||||
this.setState({removingUser: true});
|
this.setState({removingUser: true});
|
||||||
this.props.matrixClient.removeUserFromGroup(
|
this.context.matrixClient.removeUserFromGroup(
|
||||||
this.props.groupId, this.props.groupMember.userId,
|
this.props.groupId, this.props.groupMember.userId,
|
||||||
).then(() => {
|
).then(() => {
|
||||||
// return to the user list
|
// return to the user list
|
||||||
|
@ -111,21 +123,14 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
if (this.state.fetching || this.state.removingUser) {
|
if (this.state.removingUser) {
|
||||||
const Spinner = sdk.getComponent("elements.Spinner");
|
const Spinner = sdk.getComponent("elements.Spinner");
|
||||||
return <Spinner />;
|
return <Spinner />;
|
||||||
}
|
}
|
||||||
if (!this.state.groupMembers) return null;
|
|
||||||
|
|
||||||
const targetIsInGroup = this.state.groupMembers.some((m) => {
|
let adminTools;
|
||||||
return m.userId === this.props.groupMember.userId;
|
if (this.state.isUserPrivilegedInGroup) {
|
||||||
});
|
const kickButton = (
|
||||||
|
|
||||||
let kickButton;
|
|
||||||
let adminButton;
|
|
||||||
|
|
||||||
if (targetIsInGroup) {
|
|
||||||
kickButton = (
|
|
||||||
<AccessibleButton className="mx_MemberInfo_field"
|
<AccessibleButton className="mx_MemberInfo_field"
|
||||||
onClick={this._onKick}>
|
onClick={this._onKick}>
|
||||||
{ _t('Remove from community') }
|
{ _t('Remove from community') }
|
||||||
|
@ -137,22 +142,19 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
giveModButton = <AccessibleButton className="mx_MemberInfo_field" onClick={this.onModToggle}>
|
giveModButton = <AccessibleButton className="mx_MemberInfo_field" onClick={this.onModToggle}>
|
||||||
{giveOpLabel}
|
{giveOpLabel}
|
||||||
</AccessibleButton>;*/
|
</AccessibleButton>;*/
|
||||||
|
|
||||||
|
if (kickButton) {
|
||||||
|
adminTools =
|
||||||
|
<div className="mx_MemberInfo_adminTools">
|
||||||
|
<h3>{ _t("Admin Tools") }</h3>
|
||||||
|
<div className="mx_MemberInfo_buttons">
|
||||||
|
{ kickButton }
|
||||||
|
</div>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let adminTools;
|
const avatarUrl = this.context.matrixClient.mxcUrlToHttp(
|
||||||
if (kickButton || adminButton) {
|
|
||||||
adminTools =
|
|
||||||
<div className="mx_MemberInfo_adminTools">
|
|
||||||
<h3>{ _t("Admin Tools") }</h3>
|
|
||||||
|
|
||||||
<div className="mx_MemberInfo_buttons">
|
|
||||||
{ kickButton }
|
|
||||||
{ adminButton }
|
|
||||||
</div>
|
|
||||||
</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const avatarUrl = this.props.matrixClient.mxcUrlToHttp(
|
|
||||||
this.props.groupMember.avatarUrl,
|
this.props.groupMember.avatarUrl,
|
||||||
36, 36, 'crop',
|
36, 36, 'crop',
|
||||||
);
|
);
|
||||||
|
@ -192,4 +194,4 @@ module.exports = withMatrixClient(React.createClass({
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
}));
|
});
|
||||||
|
|
Loading…
Reference in a new issue