Skip to content

Commit

Permalink
install unrestricted bots (#21880)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaxim committed Jan 2, 2020
1 parent 2b9f5f5 commit c322104
Show file tree
Hide file tree
Showing 17 changed files with 323 additions and 77 deletions.
14 changes: 14 additions & 0 deletions go/chat/server.go
Expand Up @@ -3003,6 +3003,20 @@ func (h *Server) GetBotMemberSettings(ctx context.Context, arg chat1.GetBotMembe
return teams.GetBotSettingsByID(ctx, h.G().ExternalG(), teamID, arg.Username)
}

func (h *Server) GetTeamRoleInConversation(ctx context.Context, arg chat1.GetTeamRoleInConversationArg) (res keybase1.TeamRole, err error) {
ctx = globals.ChatCtx(ctx, h.G(), keybase1.TLFIdentifyBehavior_CHAT_GUI, nil, nil)
defer h.Trace(ctx, func() error { return err }, "GetTeamRoleInConversation")()
uid, err := utils.AssertLoggedInUID(ctx, h.G())
if err != nil {
return res, err
}
teamID, _, err := h.teamIDFromConvID(ctx, uid, arg.ConvID)
if err != nil {
return res, err
}
return teams.MemberRoleFromID(ctx, h.G().ExternalG(), teamID, arg.Username)
}

func (h *Server) TeamIDFromTLFName(ctx context.Context, arg chat1.TeamIDFromTLFNameArg) (res keybase1.TeamID, err error) {
var identBreaks []keybase1.TLFIdentifyFailure
ctx = globals.ChatCtx(ctx, h.G(), keybase1.TLFIdentifyBehavior_CHAT_GUI, &identBreaks, h.identNotifier)
Expand Down
26 changes: 26 additions & 0 deletions go/protocol/chat1/local.go

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

18 changes: 18 additions & 0 deletions go/teams/service_helper.go
Expand Up @@ -953,6 +953,24 @@ func MemberRole(ctx context.Context, g *libkb.GlobalContext, teamname, username
return role, err
}

func MemberRoleFromID(ctx context.Context, g *libkb.GlobalContext, teamID keybase1.TeamID, username string) (role keybase1.TeamRole, err error) {
uv, err := loadUserVersionByUsername(ctx, g, username, false /* useTracking */)
if err != nil {
return keybase1.TeamRole_NONE, err
}

err = RetryIfPossible(ctx, g, func(ctx context.Context, _ int) error {
t, err := GetForTeamManagementByTeamID(ctx, g, teamID, false)
if err != nil {
return err
}
// return value assign to escape closure
role, err = t.MemberRole(ctx, uv)
return err
})
return role, err
}

func RemoveMemberByID(ctx context.Context, g *libkb.GlobalContext, teamID keybase1.TeamID, username string) error {
teamGetter := func() (*Team, error) {
return GetForTeamManagementByTeamID(ctx, g, teamID, false)
Expand Down
1 change: 1 addition & 0 deletions protocol/avdl/chat1/local.avdl
Expand Up @@ -1245,6 +1245,7 @@ protocol local {
void removeBotMember(ConversationID convID, string username);
void setBotMemberSettings(ConversationID convID, string username, keybase1.TeamBotSettings botSettings);
keybase1.TeamBotSettings getBotMemberSettings(ConversationID convID, string username);
keybase1.TeamRole getTeamRoleInConversation(ConversationID convID, string username);

keybase1.TeamID teamIDFromTLFName(string tlfName, ConversationMembersType membersType, boolean tlfPublic);

Expand Down
1 change: 1 addition & 0 deletions protocol/bin/enabled-calls.json
Expand Up @@ -22,6 +22,7 @@
"chat.1.local.getStaticConfig": {"promise": true},
"chat.1.local.getTLFConversationsLocal": {"promise": true},
"chat.1.local.getTeamRetentionLocal": {"promise": true},
"chat.1.local.getTeamRoleInConversation": {"promise": true},
"chat.1.local.getThreadLocal": {"promise": true},
"chat.1.local.getThreadNonblock": {"engineSaga": true},
"chat.1.local.getUnfurlSettings": {"promise": true},
Expand Down
13 changes: 13 additions & 0 deletions protocol/json/chat1/local.json

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

35 changes: 35 additions & 0 deletions shared/actions/chat2-gen.tsx

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

32 changes: 27 additions & 5 deletions shared/actions/chat2/index.tsx
Expand Up @@ -3401,6 +3401,25 @@ const loadNextBotPage = (state: Container.TypedState, action: Chat2Gen.LoadNextB
page: state.chat2.featuredBotsPage + 1,
})

const refreshBotRoleInConv = async (action: Chat2Gen.RefreshBotRoleInConvPayload) => {
let role: RPCTypes.TeamRole | undefined
try {
role = await RPCChatTypes.localGetTeamRoleInConversationRpcPromise({
convID: Types.keyToConversationID(action.payload.conversationIDKey),
username: action.payload.username,
})
} catch (err) {
logger.info(`refreshBotRoleInConv: failed to refresh bot team role: ${err.message}`)
return
}
const trole = TeamsConstants.teamRoleByEnum[role]
return Chat2Gen.createSetBotRoleInConv({
conversationIDKey: action.payload.conversationIDKey,
role: !trole || trole === 'none' ? null : trole,
username: action.payload.username,
})
}

const refreshBotPublicCommands = async (
_: Container.TypedState,
action: Chat2Gen.RefreshBotPublicCommandsPayload
Expand Down Expand Up @@ -3441,12 +3460,14 @@ const addBotMember = async (state: Container.TypedState, action: Chat2Gen.AddBot
try {
await RPCChatTypes.localAddBotMemberRpcPromise(
{
botSettings: {
cmds: allowCommands,
mentions: allowMentions,
},
botSettings: action.payload.restricted
? {
cmds: allowCommands,
mentions: allowMentions,
}
: null,
convID: Types.keyToConversationID(conversationIDKey),
role: RPCTypes.TeamRole.restrictedbot,
role: action.payload.restricted ? RPCTypes.TeamRole.restrictedbot : RPCTypes.TeamRole.bot,
username,
},
Constants.waitingKeyBotAdd
Expand Down Expand Up @@ -3605,6 +3626,7 @@ function* chat2Saga() {
yield* Saga.chainAction2(Chat2Gen.removeBotMember, removeBotMember)
yield* Saga.chainAction2(Chat2Gen.refreshBotSettings, refreshBotSettings)
yield* Saga.chainAction2(Chat2Gen.findGeneralConvIDFromTeamID, findGeneralConvIDFromTeamID)
yield* Saga.chainAction(Chat2Gen.refreshBotRoleInConv, refreshBotRoleInConv)

// On login lets load the untrusted inbox. This helps make some flows easier
yield* Saga.chainAction2(ConfigGen.bootstrapStatusLoaded, startupInboxLoad)
Expand Down
14 changes: 13 additions & 1 deletion shared/actions/json/chat2.json
Expand Up @@ -837,7 +837,8 @@
"conversationIDKey": "Types.ConversationIDKey",
"allowCommands": "boolean",
"allowMentions": "boolean",
"username": "string"
"username": "string",
"restricted": "boolean"
},
"refreshBotSettings": {
"_description": "refresh bot settings",
Expand Down Expand Up @@ -880,6 +881,17 @@
"_description": "Record teamID to general convID mapping",
"teamID": "TeamsTypes.TeamID",
"conversationIDKey": "Types.ConversationIDKey"
},
"refreshBotRoleInConv": {
"_description": "Refresh role in conversation",
"conversationIDKey": "Types.ConversationIDKey",
"username": "string"
},
"setBotRoleInConv": {
"_description": "Set bot role in conversation",
"conversationIDKey": "Types.ConversationIDKey",
"username": "string",
"role": "TeamsTypes.TeamRoleType | null"
}
}
}
4 changes: 2 additions & 2 deletions shared/actions/teams.tsx
Expand Up @@ -580,7 +580,7 @@ function* getDetails(_: TypedState, action: TeamsGen.GetDetailsPayload, logger:
})
)
} catch (e) {
logger.error(e)
logger.info(e)
} finally {
const loadingKey = action.payload.clearInviteLoadingKey
if (loadingKey) {
Expand Down Expand Up @@ -680,7 +680,7 @@ function* getTeamPublicity(_: TypedState, action: TeamsGen.GetTeamPublicityPaylo

yield Saga.put(TeamsGen.createSetTeamPublicitySettings({publicity: publicityMap, teamname}))
} catch (e) {
logger.error(e.message)
logger.info(e.message)
}
}

Expand Down
2 changes: 2 additions & 0 deletions shared/actions/typed-actions-gen.tsx

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

0 comments on commit c322104

Please sign in to comment.