-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from keybase/zapu/implicit-admin-bug
Fix a bug where kssh and keybaseca would try to fetch KV store data from teams user is not an explicit member of.
- Loading branch information
Showing
4 changed files
with
48 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package shared | ||
|
||
import ( | ||
"github.com/keybase/go-keybase-chat-bot/kbchat" | ||
"github.com/keybase/go-keybase-chat-bot/kbchat/types/keybase1" | ||
) | ||
|
||
// CanRoleReadTeam checks if given role can access team data. User has to be an | ||
// actual team member (not implicit admin) to be able to access data, and | ||
// cannot be a RESTRICTED BOT. | ||
func CanRoleReadTeam(role keybase1.TeamRole) bool { | ||
switch role { | ||
case keybase1.TeamRole_READER, | ||
keybase1.TeamRole_WRITER, | ||
keybase1.TeamRole_ADMIN, | ||
keybase1.TeamRole_OWNER, | ||
keybase1.TeamRole_BOT: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// GetAllTeams makes an API call and returns list of team names readable for | ||
// current user. | ||
func GetAllTeams(api *kbchat.API) (teams []string, err error) { | ||
memberships, err := api.ListUserMemberships(api.GetUsername()) | ||
if err != nil { | ||
return teams, err | ||
} | ||
for _, m := range memberships { | ||
if CanRoleReadTeam(m.Role) { | ||
teams = append(teams, m.FqName) | ||
} | ||
} | ||
return teams, nil | ||
} |