Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hide manage bot functionality for non-admins #21886

Merged
merged 8 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go/protocol/keybase1/teams.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions go/teams/service_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,7 @@ func CanUserPerform(ctx context.Context, g *libkb.GlobalContext, teamname string
ret.ChangeOpenTeam = isAdmin || isImplicitAdmin
ret.ChangeTarsDisabled = isAdmin || isImplicitAdmin
ret.EditTeamDescription = isAdmin || isImplicitAdmin
ret.ManageBots = isAdmin || isImplicitAdmin
ret.SetMemberShowcase, err = canMemberShowcase()
if err != nil {
return ret, err
Expand Down
1 change: 1 addition & 0 deletions protocol/avdl/keybase1/teams.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,7 @@ protocol teams {
boolean deleteOtherMessages;
boolean deleteTeam;
boolean pinMessage;
boolean manageBots;
}

record ProfileTeamLoadRes {
Expand Down
4 changes: 4 additions & 0 deletions protocol/json/keybase1/teams.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 40 additions & 29 deletions shared/chat/conversation/bot/install.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as Chat2Gen from '../../../actions/chat2-gen'
import * as WaitingGen from '../../../actions/waiting-gen'
import * as Types from '../../../constants/types/chat2'
import * as TeamTypes from '../../../constants/types/teams'
import * as TeamConstants from '../../../constants/teams'
import * as Constants from '../../../constants/chat2'
import * as RPCTypes from '../../../constants/types/rpc-gen'

Expand Down Expand Up @@ -56,11 +57,16 @@ const InstallBotPopup = (props: Props) => {
const [installWithCommands, setInstallWithCommands] = React.useState(true)
const [installWithMentions, setInstallWithMentions] = React.useState(true)
const [installWithRestrict, setInstallWithRestrict] = React.useState(true)
const {commands, featured, inTeam, inTeamUnrestricted, settings} = Container.useSelector(
const {commands, featured, inTeam, inTeamUnrestricted, readOnly, settings} = Container.useSelector(
(state: Container.TypedState) => {
let inTeam: boolean | undefined
let teamRole: TeamTypes.TeamRoleType | null | undefined
let readOnly = false
if (conversationIDKey) {
const meta = state.chat2.metaMap.get(conversationIDKey)
if (meta && meta.teamname) {
readOnly = !TeamConstants.getCanPerform(state, meta.teamname).manageBots
}
teamRole = state.chat2.botTeamRoleInConvMap.get(conversationIDKey)?.get(botUsername)
if (teamRole !== undefined) {
inTeam = !!teamRole
Expand All @@ -71,6 +77,7 @@ const InstallBotPopup = (props: Props) => {
featured: state.chat2.featuredBotsMap.get(botUsername),
inTeam,
inTeamUnrestricted: inTeam && teamRole === 'bot',
readOnly,
settings: conversationIDKey
? state.chat2.botSettings.get(conversationIDKey)?.get(botUsername) ?? undefined
: undefined,
Expand Down Expand Up @@ -150,7 +157,7 @@ const InstallBotPopup = (props: Props) => {
}
}, [conversationIDKey, inTeam])

const restrictPicker = !inTeam && (
const restrictPicker = !inTeam && !readOnly && (
<Kb.Box2 direction="vertical" fullWidth={true} gap="tiny">
<Kb.Text type="BodyBigExtrabold">Install as:</Kb.Text>
<Kb.Box2 direction="vertical" fullWidth={true} gap="tiny">
Expand Down Expand Up @@ -348,37 +355,41 @@ const InstallBotPopup = (props: Props) => {
header={{
leftButton: (
<Kb.Text type="BodyBigLink" onClick={onClose}>
{installScreen ? 'Back' : inTeam ? 'Close' : 'Cancel'}
{installScreen ? 'Back' : inTeam || readOnly ? 'Close' : 'Cancel'}
</Kb.Text>
),
title: '',
}}
footer={{
content: enabled && (
<Kb.Box2 direction="vertical" gap="tiny" fullWidth={true}>
<Kb.ButtonBar direction="column">
{editButton}
{saveButton}
{reviewButton}
{installButton}
{removeButton}
</Kb.ButtonBar>
{!!error && (
<Kb.Text type="Body" style={{color: Styles.globalColors.redDark}}>
{'Something went wrong! Please try again, or send '}
<Kb.Text
type="Body"
style={{color: Styles.globalColors.redDark}}
underline={true}
onClick={onFeedback}
>
{'feedback'}
</Kb.Text>
</Kb.Text>
)}
</Kb.Box2>
),
}}
footer={
enabled && !readOnly
? {
content: (
<Kb.Box2 direction="vertical" gap="tiny" fullWidth={true}>
<Kb.ButtonBar direction="column">
{editButton}
{saveButton}
{reviewButton}
{installButton}
{removeButton}
</Kb.ButtonBar>
{!!error && (
<Kb.Text type="Body" style={{color: Styles.globalColors.redDark}}>
{'Something went wrong! Please try again, or send '}
<Kb.Text
type="Body"
style={{color: Styles.globalColors.redDark}}
underline={true}
onClick={onFeedback}
>
{'feedback'}
</Kb.Text>
</Kb.Text>
)}
</Kb.Box2>
),
}
: undefined
}
>
<Kb.Box2 direction="vertical" style={styles.outerContainer} fullWidth={true}>
{enabled ? content : <Kb.ProgressIndicator />}
Expand Down
5 changes: 5 additions & 0 deletions shared/chat/conversation/info-panel/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,18 @@ const ConnectedInfoPanel = Container.connect(
let canSetMinWriterRole = false
let canSetRetention = false
let canDeleteHistory = false
let canManageBots = false
if (meta.teamname) {
const yourOperations = TeamConstants.getCanPerformByID(state, meta.teamID)
admin = yourOperations.manageMembers
canEditChannel = yourOperations.editTeamDescription
canSetMinWriterRole = yourOperations.setMinWriterRole
canSetRetention = yourOperations.setRetentionPolicy
canDeleteHistory = yourOperations.deleteChatHistory && !meta.cannotWrite
canManageBots = yourOperations.manageBots
} else {
canDeleteHistory = true
canManageBots = true
}
const isPreview = meta.membershipType === 'youArePreviewing'
const selectedTab = ownProps.selectedTab || (meta.teamname ? 'members' : 'attachments')
Expand All @@ -88,6 +91,7 @@ const ConnectedInfoPanel = Container.connect(
attachmentsLoading,
canDeleteHistory,
canEditChannel,
canManageBots,
canSetMinWriterRole,
canSetRetention,
channelname: meta.channelname,
Expand Down Expand Up @@ -269,6 +273,7 @@ const ConnectedInfoPanel = Container.connect(
attachmentsLoading: stateProps.attachmentsLoading,
canDeleteHistory: stateProps.canDeleteHistory,
canEditChannel: stateProps.canEditChannel,
canManageBots: stateProps.canManageBots,
canSetMinWriterRole: stateProps.canSetMinWriterRole,
canSetRetention: stateProps.canSetRetention,
channelname: stateProps.channelname,
Expand Down
5 changes: 4 additions & 1 deletion shared/chat/conversation/info-panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export type InfoPanelProps = {
onJoinChannel: () => void

// Used for bots
canManageBots: boolean
loadedAllBots: boolean
onSearchFeaturedBots: (username: string) => void
onLoadMoreBots: () => void
Expand Down Expand Up @@ -428,7 +429,9 @@ class _InfoPanel extends React.PureComponent<InfoPanelProps> {
}
}

tabsSection.data.push(addBotButton)
if (this.props.canManageBots) {
tabsSection.data.push(addBotButton)
}
if (this.props.installedBots.length > 0) {
tabsSection.data.push(inThisChannelHeader)
}
Expand Down
1 change: 1 addition & 0 deletions shared/constants/teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ const deriveCanPerform = (roleAndDetails?: Types.TeamRoleAndDetails): Types.Team
editTeamDescription: isAdminOrAbove || implicitAdmin,
joinTeam: role === 'none' && implicitAdmin,
listFirst: implicitAdmin,
manageBots: isAdminOrAbove || implicitAdmin,
manageMembers: isAdminOrAbove || implicitAdmin,
manageSubteams: isAdminOrAbove || implicitAdmin,
pinMessage: isWriterOrAbove,
Expand Down
2 changes: 1 addition & 1 deletion shared/constants/types/rpc-gen.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion shared/teams/team/rows/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ const makeRows = (
// loading
rows.push({key: 'loading', type: 'loading'})
}
rows.push({key: 'bot:install-more', type: 'bot-add'})
if (yourOperations.manageBots) {
rows.push({key: 'bot:install-more', type: 'bot-add'})
}
if (bots.length === 0) {
rows.push({key: 'bot:none', type: 'bot-none'})
}
Expand Down