Skip to content

Commit 629d315

Browse files
committed
checkpoint: one passing test
1 parent b44fc99 commit 629d315

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

coderd/authz/authz.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package authz
22

3-
import "github.com/coder/coder/coderd/authz/rbac"
3+
import (
4+
"errors"
5+
6+
"github.com/coder/coder/coderd/authz/rbac"
7+
)
8+
9+
var ErrUnauthorized = errors.New("unauthorized")
410

511
// TODO: Implement Authorize
6-
func Authorize(subj Subject, obj Resource, action rbac.Operation) error {
12+
func Authorize(subj Subject, res Resource, action rbac.Operation) error {
713
// TODO: Expand subject roles into their permissions as appropriate. Apply scopes.
814

9-
return nil
15+
if SiteEnforcer.RolesHavePermission(subj.Roles(), res.ResourceType(), action) {
16+
return nil
17+
}
18+
19+
return ErrUnauthorized
1020
}

coderd/authz/subject.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Subject interface {
1313
// object, we can assume the object is owned by this subject.
1414
ID() string
1515

16-
Roles() (rbac.Roles, error)
16+
Roles() rbac.Roles
1717

1818
// OrgRoles only need to be returned for the organization in question.
1919
// This is because users typically belong to more than 1 organization,
@@ -38,8 +38,8 @@ func (s SubjectTODO) ID() string {
3838
return s.UserID
3939
}
4040

41-
func (s SubjectTODO) Roles() (rbac.Roles, error) {
42-
return s.Site, nil
41+
func (s SubjectTODO) Roles() rbac.Roles {
42+
return s.Site
4343
}
4444

4545
func (s SubjectTODO) OrgRoles(_ context.Context, orgID string) (rbac.Roles, error) {

0 commit comments

Comments
 (0)