Skip to content

Commit

Permalink
Check role in showTeamByName deep link (keybase#22821)
Browse files Browse the repository at this point in the history
  • Loading branch information
zapu authored Mar 3, 2020
1 parent f57f4e2 commit a0b7443
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
5 changes: 1 addition & 4 deletions shared/actions/deeplinks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ import logger from '../logger'
const handleTeamPageLink = (teamname: string, action: 'add_or_invite' | 'manage_settings' | undefined) => {
const initialTab = action === 'manage_settings' ? 'settings' : undefined
const addMembers = action === 'add_or_invite' ? true : undefined
return [
RouteTreeGen.createSwitchTab({tab: Tabs.teamsTab}),
TeamsGen.createShowTeamByName({addMembers, initialTab, teamname}),
]
return [TeamsGen.createShowTeamByName({addMembers, initialTab, teamname})]
}

const handleShowUserProfileLink = (username: string) => {
Expand Down
25 changes: 23 additions & 2 deletions shared/actions/teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as ChatTypes from '../constants/types/chat2'
import * as RPCChatTypes from '../constants/types/rpc-chat-gen'
import * as RPCTypes from '../constants/types/rpc-gen'
import * as Saga from '../util/saga'
import * as Tabs from '../constants/tabs'
import * as RouteTreeGen from './route-tree-gen'
import * as NotificationsGen from './notifications-gen'
import * as ConfigGen from './config-gen'
Expand Down Expand Up @@ -1325,11 +1326,31 @@ async function showTeamByName(action: TeamsGen.ShowTeamByNamePayload, logger: Sa
let teamID: string
try {
teamID = await RPCTypes.teamsGetTeamIDRpcPromise({teamName: teamname})
} catch (e) {
logger.info(`showTeamByName: team "${teamname}" cannot be loaded: ${e.toString()}`)
} catch (err) {
logger.info(`team="${teamname}" cannot be loaded:`, err)
return null
}

if (addMembers) {
// Check if we have the right role to be adding members, otherwise don't
// show the team builder.
try {
// Get (hopefully fresh) role map. The app might have just started so it's
// not enough to just look in the react store.
const map = await RPCTypes.teamsGetTeamRoleMapRpcPromise()
const role = map.teams[teamID]?.role || map.teams[teamID]?.implicitRole
if (role !== RPCTypes.TeamRole.admin && role !== RPCTypes.TeamRole.owner) {
logger.info(`ignoring team="${teamname}" with addMember, user is not an admin but role=${role}`)
return null
}
} catch (err) {
logger.info(`team="${teamname}" failed to check if user is an admin:`, err)
return null
}
}

return [
RouteTreeGen.createSwitchTab({tab: Tabs.teamsTab}),
RouteTreeGen.createNavigateAppend({
path: [{props: {initialTab, teamID}, selected: 'team'}],
}),
Expand Down

0 comments on commit a0b7443

Please sign in to comment.