| OLD | NEW |
| (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/luci_config/common/cfgtypes" | |
| 9 "github.com/luci/luci-go/luci_config/server/cfgclient/access" | |
| 10 "github.com/luci/luci-go/luci_config/server/cfgclient/backend" | |
| 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. | |
| 18 func IsAllowed(c context.Context, project string) (bool, error) { | |
| 19 // Get the project, because that's where the ACLs lie. | |
| 20 err := access.Check( | |
| 21 c, backend.AsUser, | |
| 22 cfgtypes.ProjectConfigSet(cfgtypes.ProjectName(project))) | |
| 23 switch err { | |
| 24 case nil: | |
| 25 return true, nil | |
| 26 case access.ErrNoAccess: | |
| 27 return false, nil | |
| 28 default: | |
| 29 return false, err | |
| 30 } | |
| 31 } | |
| 32 | |
| 33 // IsAllowedInternal is a shorthand for checking to see if the user is a reader | |
| 34 // of a magic project named "chrome". | |
| 35 func IsAllowedInternal(c context.Context) (bool, error) { | |
| 36 // TODO(hinoka): Move this to luci-cfg. | |
| 37 return IsAllowed(c, "chrome") | |
| 38 } | |
| OLD | NEW |