Groups: Disable some permissions for public groups (#2708)

This commit is contained in:
Alexander Zinchuk 2023-03-03 14:30:32 +01:00
parent 893fa8f557
commit b60d888d00
2 changed files with 42 additions and 17 deletions

View File

@ -9,6 +9,7 @@ import type { ApiChat, ApiChatBannedRights, ApiChatMember } from '../../../api/t
import stopEvent from '../../../util/stopEvent'; import stopEvent from '../../../util/stopEvent';
import buildClassName from '../../../util/buildClassName'; import buildClassName from '../../../util/buildClassName';
import { isChatPublic } from '../../../global/helpers';
import useLang from '../../../hooks/useLang'; import useLang from '../../../hooks/useLang';
import { selectChat } from '../../../global/selectors'; import { selectChat } from '../../../global/selectors';
import useHistoryBack from '../../../hooks/useHistoryBack'; import useHistoryBack from '../../../hooks/useHistoryBack';
@ -31,6 +32,7 @@ type OwnProps = {
type StateProps = { type StateProps = {
chat?: ApiChat; chat?: ApiChat;
currentUserId?: string; currentUserId?: string;
hasLinkedChat?: boolean;
}; };
const ITEM_HEIGHT = 24 + 32; const ITEM_HEIGHT = 24 + 32;
@ -81,16 +83,19 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
onChatMemberSelect, onChatMemberSelect,
chat, chat,
currentUserId, currentUserId,
hasLinkedChat,
onClose, onClose,
isActive, isActive,
}) => { }) => {
const { updateChatDefaultBannedRights } = getActions(); const { updateChatDefaultBannedRights, showNotification } = getActions();
const { const {
permissions, havePermissionChanged, isLoading, handlePermissionChange, setIsLoading, permissions, havePermissionChanged, isLoading, handlePermissionChange, setIsLoading,
} = useManagePermissions(chat?.defaultBannedRights); } = useManagePermissions(chat?.defaultBannedRights);
const lang = useLang(); const lang = useLang();
const { isForum } = chat || {}; const { isForum } = chat || {};
const isPublic = useMemo(() => chat && isChatPublic(chat), [chat]);
const shouldDisablePermissionForPublicGroup = hasLinkedChat || isPublic;
useHistoryBack({ useHistoryBack({
isActive, isActive,
@ -116,6 +121,10 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
setIsMediaDropdownOpen(!isMediaDropdownOpen); setIsMediaDropdownOpen(!isMediaDropdownOpen);
}, [isMediaDropdownOpen]); }, [isMediaDropdownOpen]);
const handleDisabledClick = useCallback(() => {
showNotification({ message: lang('lng_rights_permission_unavailable') });
}, [lang, showNotification]);
const handleSavePermissions = useCallback(() => { const handleSavePermissions = useCallback(() => {
if (!chat) { if (!chat) {
return; return;
@ -181,7 +190,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
<div className="section without-bottom-shadow"> <div className="section without-bottom-shadow">
<h3 className="section-heading" dir="auto">{lang('ChannelPermissionsHeader')}</h3> <h3 className="section-heading" dir="auto">{lang('ChannelPermissionsHeader')}</h3>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendPlain" name="sendPlain"
checked={!permissions.sendPlain} checked={!permissions.sendPlain}
@ -190,7 +199,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
onChange={handlePermissionChange} onChange={handlePermissionChange}
/> />
</div> </div>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendMedia" name="sendMedia"
checked={!permissions.sendMedia} checked={!permissions.sendMedia}
@ -208,7 +217,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
isMediaDropdownOpen && 'DropdownList--open', isMediaDropdownOpen && 'DropdownList--open',
)} )}
> >
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendPhotos" name="sendPhotos"
checked={!permissions.sendPhotos} checked={!permissions.sendPhotos}
@ -218,7 +227,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
/> />
</div> </div>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendVideos" name="sendVideos"
checked={!permissions.sendVideos} checked={!permissions.sendVideos}
@ -228,7 +237,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
/> />
</div> </div>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendStickers" name="sendStickers"
checked={!permissions.sendStickers && !permissions.sendGifs} checked={!permissions.sendStickers && !permissions.sendGifs}
@ -238,7 +247,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
/> />
</div> </div>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendAudios" name="sendAudios"
checked={!permissions.sendAudios} checked={!permissions.sendAudios}
@ -248,7 +257,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
/> />
</div> </div>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendDocs" name="sendDocs"
checked={!permissions.sendDocs} checked={!permissions.sendDocs}
@ -258,7 +267,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
/> />
</div> </div>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendVoices" name="sendVoices"
checked={!permissions.sendVoices} checked={!permissions.sendVoices}
@ -268,7 +277,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
/> />
</div> </div>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendRoundvideos" name="sendRoundvideos"
checked={!permissions.sendRoundvideos} checked={!permissions.sendRoundvideos}
@ -278,7 +287,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
/> />
</div> </div>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="embedLinks" name="embedLinks"
checked={!permissions.embedLinks} checked={!permissions.embedLinks}
@ -288,7 +297,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
/> />
</div> </div>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="sendPolls" name="sendPolls"
checked={!permissions.sendPolls} checked={!permissions.sendPolls}
@ -301,7 +310,7 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
</div> </div>
<div className={buildClassName('part', isMediaDropdownOpen && 'shifted')}> <div className={buildClassName('part', isMediaDropdownOpen && 'shifted')}>
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="inviteUsers" name="inviteUsers"
checked={!permissions.inviteUsers} checked={!permissions.inviteUsers}
@ -310,26 +319,34 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
onChange={handlePermissionChange} onChange={handlePermissionChange}
/> />
</div> </div>
<div className="ListItem no-selection"> <div
className="ListItem no-selection with-checkbox"
onClick={shouldDisablePermissionForPublicGroup ? handleDisabledClick : undefined}
>
<Checkbox <Checkbox
name="pinMessages" name="pinMessages"
checked={!permissions.pinMessages} checked={!permissions.pinMessages}
label={lang('UserRestrictionsPinMessages')} label={lang('UserRestrictionsPinMessages')}
disabled={shouldDisablePermissionForPublicGroup}
blocking blocking
onChange={handlePermissionChange} onChange={handlePermissionChange}
/> />
</div> </div>
<div className="ListItem no-selection"> <div
className="ListItem no-selection with-checkbox"
onClick={shouldDisablePermissionForPublicGroup ? handleDisabledClick : undefined}
>
<Checkbox <Checkbox
name="changeInfo" name="changeInfo"
checked={!permissions.changeInfo} checked={!permissions.changeInfo}
label={lang('UserRestrictionsChangeInfo')} label={lang('UserRestrictionsChangeInfo')}
blocking blocking
disabled={shouldDisablePermissionForPublicGroup}
onChange={handlePermissionChange} onChange={handlePermissionChange}
/> />
</div> </div>
{isForum && ( {isForum && (
<div className="ListItem no-selection"> <div className="ListItem no-selection with-checkbox">
<Checkbox <Checkbox
name="manageTopics" name="manageTopics"
checked={!permissions.manageTopics} checked={!permissions.manageTopics}
@ -410,7 +427,8 @@ const ManageGroupPermissions: FC<OwnProps & StateProps> = ({
export default memo(withGlobal<OwnProps>( export default memo(withGlobal<OwnProps>(
(global, { chatId }): StateProps => { (global, { chatId }): StateProps => {
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
const hasLinkedChat = Boolean(chat?.fullInfo?.linkedChatId);
return { chat, currentUserId: global.currentUserId }; return { chat, currentUserId: global.currentUserId, hasLinkedChat };
}, },
)(ManageGroupPermissions)); )(ManageGroupPermissions));

View File

@ -68,6 +68,13 @@
text-overflow: ellipsis; text-overflow: ellipsis;
} }
&.with-checkbox {
body.is-ios &::after,
body.is-android &::after {
bottom: -1rem;
}
}
&:not(.picker-list-item) .Checkbox { &:not(.picker-list-item) .Checkbox {
margin-top: 2rem; margin-top: 2rem;
margin-bottom: 2rem; margin-bottom: 2rem;