forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
82 lines (74 loc) · 2.56 KB
/
get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package teams
import (
"encoding/json"
"golang.org/x/net/context"
"github.com/keybase/client/go/libkb"
"github.com/keybase/client/go/protocol/keybase1"
)
type rawTeam struct {
ID keybase1.TeamID `json:"id"`
Name keybase1.TeamName `json:"name"`
Status libkb.AppStatus `json:"status"`
Chain []json.RawMessage `json:"chain"`
Box *TeamBox `json:"box"`
Prevs map[keybase1.PerTeamKeyGeneration]prevKeySealedEncoded `json:"prevs"`
ReaderKeyMasks []keybase1.ReaderKeyMask `json:"reader_key_masks"`
// Whether the user is only being allowed to view the chain
// because they are a member of a descendent team.
SubteamReader bool `json:"subteam_reader"`
}
func (r *rawTeam) GetAppStatus() *libkb.AppStatus {
return &r.Status
}
func (r *rawTeam) parseLinks(ctx context.Context) ([]SCChainLink, error) {
var links []SCChainLink
for _, raw := range r.Chain {
link, err := ParseTeamChainLink(string(raw))
if err != nil {
return nil, err
}
links = append(links, link)
}
return links, nil
}
// needAdmin must be set when interacting with links that have a possibility of being stubbed.
func GetForTeamManagementByStringName(ctx context.Context, g *libkb.GlobalContext, name string, needAdmin bool) (*Team, error) {
team, err := Load(ctx, g, keybase1.LoadTeamArg{
Name: name,
ForceRepoll: true,
NeedAdmin: needAdmin,
})
return team, fixupTeamGetError(ctx, g, err, name)
}
// Get a team with no stubbed links if we are an admin. Use this instead of NeedAdmin when you don't
// know whether you are an admin. This always causes roundtrips. Doesn't work for implicit admins.
func GetMaybeAdminByStringName(ctx context.Context, g *libkb.GlobalContext, name string) (*Team, error) {
// Find out our up-to-date role.
team, err := Load(ctx, g, keybase1.LoadTeamArg{
Name: name,
ForceRepoll: true,
})
if err != nil {
return nil, err
}
me, err := loadUserVersionByUID(ctx, g, g.Env.GetUID())
if err != nil {
return nil, err
}
role, err := team.MemberRole(ctx, me)
if err != nil {
return nil, err
}
if role.IsAdminOrAbove() {
// Will hit the cache _unless_ we had a cached non-admin team
// and are now an admin.
team, err = Load(ctx, g, keybase1.LoadTeamArg{
Name: name,
NeedAdmin: true,
})
if err != nil {
return nil, err
}
}
return team, nil
}