Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: milo/appengine/settings/acl.go

Issue 2241853002: Milo: ACL support (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@lucicfg
Patch Set: Remove debugging Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | milo/appengine/settings/acl_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package settings
6
7 import (
8 "github.com/luci/luci-go/common/logging"
9 "github.com/luci/luci-go/server/auth"
10 "github.com/luci/luci-go/server/auth/identity"
11 "golang.org/x/net/context"
12 )
13
14 // Helper functions for ACL checking.
15
16 // IsAllowed checks to see if the user in the context is allowed to access
17 // the given project. If write is true, this checks Writer permissions instead
18 // of Reader. Note that Writer permissions imply Reader.
19 func IsAllowed(c context.Context, project string, write bool) bool {
Vadim Sh. 2016/08/15 22:04:52 is 'write' used anywhere currently (or going to be
Ryan Tseng 2016/08/16 00:03:56 Removing for now. It's not currently used anywher
20 p, err := GetProject(c, project)
21 if err != nil {
22 logging.WithError(err).Errorf(c,
23 "Encountered error while fetching project %s", project)
24 return false
Vadim Sh. 2016/08/15 22:04:52 the function should return (bool, error) tuple and
Ryan Tseng 2016/08/16 00:03:56 Done.
25 }
26
27 // This is the list of users to check against. Since writers are implic itly
28 // readers, we populate this list first, and then tack on readers if we' re
29 // in readers mode.
30 users := map[string]bool{}
31 for _, u := range p.Writers {
32 users[u] = true
33 }
34 if !write {
35 for _, u := range p.Readers {
36 users[u] = true
37 }
38 }
39
40 // Alright, so who's our user?
41 cu := auth.CurrentUser(c)
42
43 // First, check the anonomyous case. We just need to see if _any_ of th e entries
44 // are "public", and we're done.
45 if cu.Identity == identity.AnonymousIdentity {
46 if _, ok := users["public"]; ok {
Vadim Sh. 2016/08/15 22:04:52 no need for this: 1) We have group "all", that inc
Ryan Tseng 2016/08/16 00:03:56 Done.
47 return true
48 }
49 return false
50 }
51
52 // Ok, now check to see if the user is listed explicitly in any of the e ntries.
53 if _, ok := users[cu.Email]; ok {
54 return true
55 }
56
57 // Now check for group memberhsip.
58 for entry := range users {
59 ok, err := auth.IsMember(c, entry)
60 if err != nil {
61 logging.WithError(err).Errorf(c,
62 "Could not check if user is a member of %s", ent ry)
63 } else if ok {
64 return true
65 }
66 }
67 return false
68 }
OLDNEW
« no previous file with comments | « no previous file | milo/appengine/settings/acl_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698