Management: Respect changeInfo and inviteUsers permissions (#1006)
This commit is contained in:
parent
2d36553b8f
commit
7324bf85e5
@ -4,7 +4,9 @@ import { withGlobal } from '../../lib/teact/teactn';
|
||||
import { ApiChat } from '../../api/types';
|
||||
|
||||
import { selectChat } from '../../modules/selectors';
|
||||
import { getChatDescription, getChatLink } from '../../modules/helpers';
|
||||
import {
|
||||
getChatDescription, getChatLink, getHasAdminRight, isChatChannel, isUserRightBanned,
|
||||
} from '../../modules/helpers';
|
||||
import renderText from '../common/helpers/renderText';
|
||||
import useLang from '../../hooks/useLang';
|
||||
|
||||
@ -16,9 +18,10 @@ type OwnProps = {
|
||||
|
||||
type StateProps = {
|
||||
chat?: ApiChat;
|
||||
canInviteUsers?: boolean;
|
||||
};
|
||||
|
||||
const ChatExtra: FC<OwnProps & StateProps> = ({ chat }) => {
|
||||
const ChatExtra: FC<OwnProps & StateProps> = ({ chat, canInviteUsers }) => {
|
||||
const lang = useLang();
|
||||
|
||||
if (!chat || chat.isRestricted) {
|
||||
@ -40,7 +43,7 @@ const ChatExtra: FC<OwnProps & StateProps> = ({ chat }) => {
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{!!link.length && (
|
||||
{canInviteUsers && !!link.length && (
|
||||
<div className="item">
|
||||
<i className="icon-mention" />
|
||||
<div>
|
||||
@ -57,6 +60,12 @@ export default memo(withGlobal<OwnProps>(
|
||||
(global, { chatId }): StateProps => {
|
||||
const chat = selectChat(global, chatId);
|
||||
|
||||
return { chat };
|
||||
|
||||
const canInviteUsers = chat && (
|
||||
(!isChatChannel(chat) && !isUserRightBanned(chat, 'inviteUsers'))
|
||||
|| getHasAdminRight(chat, 'inviteUsers')
|
||||
);
|
||||
|
||||
return { chat, canInviteUsers };
|
||||
},
|
||||
)(ChatExtra));
|
||||
|
||||
@ -9,7 +9,7 @@ import { ManagementScreens, ManagementProgress } from '../../../types';
|
||||
import { ApiChat, ApiMediaFormat } from '../../../api/types';
|
||||
|
||||
import { pick } from '../../../util/iteratees';
|
||||
import { getChatAvatarHash } from '../../../modules/helpers';
|
||||
import { getChatAvatarHash, getHasAdminRight } from '../../../modules/helpers';
|
||||
import useMedia from '../../../hooks/useMedia';
|
||||
import useLang from '../../../hooks/useLang';
|
||||
import { selectChat } from '../../../modules/selectors';
|
||||
@ -34,6 +34,7 @@ type StateProps = {
|
||||
chat: ApiChat;
|
||||
progress?: ManagementProgress;
|
||||
isSignaturesShown: boolean;
|
||||
canChangeInfo?: boolean;
|
||||
};
|
||||
|
||||
type DispatchProps = Pick<GlobalActions, (
|
||||
@ -47,6 +48,7 @@ const ManageChannel: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
chat,
|
||||
progress,
|
||||
isSignaturesShown,
|
||||
canChangeInfo,
|
||||
onScreenSelect,
|
||||
updateChat,
|
||||
toggleSignatures,
|
||||
@ -156,6 +158,7 @@ const ManageChannel: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
<AvatarEditable
|
||||
currentAvatarBlobUrl={currentAvatarBlobUrl}
|
||||
onChange={handleSetPhoto}
|
||||
disabled={!canChangeInfo}
|
||||
/>
|
||||
<InputText
|
||||
id="channel-title"
|
||||
@ -163,6 +166,7 @@ const ManageChannel: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
onChange={handleTitleChange}
|
||||
value={title}
|
||||
error={error === CHANNEL_TITLE_EMPTY ? error : undefined}
|
||||
disabled={!canChangeInfo}
|
||||
/>
|
||||
<InputText
|
||||
id="channel-about"
|
||||
@ -170,6 +174,7 @@ const ManageChannel: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
label={lang('DescriptionPlaceholder')}
|
||||
onChange={handleAboutChange}
|
||||
value={about}
|
||||
disabled={!canChangeInfo}
|
||||
/>
|
||||
{chat.isCreator && (
|
||||
<ListItem icon="lock" ripple onClick={handleClickEditType}>
|
||||
@ -179,7 +184,7 @@ const ManageChannel: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
</div>
|
||||
</ListItem>
|
||||
)}
|
||||
<ListItem icon="message" ripple onClick={handleClickDiscussion}>
|
||||
<ListItem icon="message" ripple onClick={handleClickDiscussion} disabled={!canChangeInfo}>
|
||||
<div className="multiline-item">
|
||||
<span className="title">{lang('Discussion')}</span>
|
||||
<span className="subtitle">{hasLinkedChat ? lang('DiscussionUnlink') : lang('Add')}</span>
|
||||
@ -243,7 +248,12 @@ export default memo(withGlobal<OwnProps>(
|
||||
const { progress } = global.management;
|
||||
const isSignaturesShown = Boolean(chat && chat.isSignaturesShown);
|
||||
|
||||
return { chat, progress, isSignaturesShown };
|
||||
return {
|
||||
chat,
|
||||
progress,
|
||||
isSignaturesShown,
|
||||
canChangeInfo: getHasAdminRight(chat, 'changeInfo'),
|
||||
};
|
||||
},
|
||||
(setGlobal, actions): DispatchProps => pick(actions, [
|
||||
'toggleSignatures', 'updateChat', 'closeManagement', 'leaveChannel', 'deleteChannel', 'openChat',
|
||||
|
||||
@ -8,7 +8,7 @@ import { ManagementScreens, ManagementProgress } from '../../../types';
|
||||
import { ApiChat, ApiChatBannedRights, ApiMediaFormat } from '../../../api/types';
|
||||
import { GlobalActions } from '../../../global/types';
|
||||
|
||||
import { getChatAvatarHash, isChatBasicGroup } from '../../../modules/helpers';
|
||||
import { getChatAvatarHash, getHasAdminRight, isChatBasicGroup } from '../../../modules/helpers';
|
||||
import useMedia from '../../../hooks/useMedia';
|
||||
import useLang from '../../../hooks/useLang';
|
||||
import useFlag from '../../../hooks/useFlag';
|
||||
@ -37,6 +37,8 @@ type StateProps = {
|
||||
progress?: ManagementProgress;
|
||||
isBasicGroup: boolean;
|
||||
hasLinkedChannel: boolean;
|
||||
canChangeInfo?: boolean;
|
||||
canBanUsers?: boolean;
|
||||
};
|
||||
|
||||
type DispatchProps = Pick<GlobalActions, (
|
||||
@ -56,6 +58,8 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
progress,
|
||||
isBasicGroup,
|
||||
hasLinkedChannel,
|
||||
canChangeInfo,
|
||||
canBanUsers,
|
||||
onScreenSelect,
|
||||
togglePreHistoryHidden,
|
||||
updateChat,
|
||||
@ -205,6 +209,7 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
<AvatarEditable
|
||||
currentAvatarBlobUrl={currentAvatarBlobUrl}
|
||||
onChange={handleSetPhoto}
|
||||
disabled={!canChangeInfo}
|
||||
/>
|
||||
<InputText
|
||||
id="group-title"
|
||||
@ -212,6 +217,7 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
onChange={handleTitleChange}
|
||||
value={title}
|
||||
error={error === GROUP_TITLE_EMPTY ? error : undefined}
|
||||
disabled={!canChangeInfo}
|
||||
/>
|
||||
<InputText
|
||||
id="group-about"
|
||||
@ -219,6 +225,7 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
label={lang('DescriptionPlaceholder')}
|
||||
onChange={handleAboutChange}
|
||||
value={about}
|
||||
disabled={!canChangeInfo}
|
||||
/>
|
||||
{chat.isCreator && (
|
||||
<ListItem icon="lock" ripple onClick={handleClickEditType}>
|
||||
@ -236,7 +243,7 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
</div>
|
||||
</ListItem>
|
||||
)}
|
||||
<ListItem icon="permissions" ripple onClick={handleClickPermissions}>
|
||||
<ListItem icon="permissions" ripple onClick={handleClickPermissions} disabled={!canBanUsers}>
|
||||
<div className="multiline-item">
|
||||
<span className="title">{lang('ChannelPermissions')}</span>
|
||||
<span className="subtitle">{enabledPermissionsCount}/{TOTAL_PERMISSIONS_COUNT}</span>
|
||||
@ -263,6 +270,7 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
|
||||
checked={!chat.fullInfo.isPreHistoryHidden}
|
||||
label={lang('ChatHistory')}
|
||||
onChange={handleTogglePreHistory}
|
||||
disabled={!canBanUsers}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@ -313,6 +321,8 @@ export default memo(withGlobal<OwnProps>(
|
||||
progress,
|
||||
isBasicGroup: isChatBasicGroup(chat),
|
||||
hasLinkedChannel,
|
||||
canChangeInfo: getHasAdminRight(chat, 'changeInfo'),
|
||||
canBanUsers: getHasAdminRight(chat, 'banUsers'),
|
||||
};
|
||||
},
|
||||
(setGlobal, actions): DispatchProps => pick(actions, [
|
||||
|
||||
@ -71,6 +71,14 @@
|
||||
|
||||
&.disabled {
|
||||
pointer-events: none;
|
||||
|
||||
i {
|
||||
display: none;
|
||||
}
|
||||
|
||||
&::after {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user