Skip to content

Commit

Permalink
Revert "fix: cleanup"
Browse files Browse the repository at this point in the history
This reverts commit 728173f.
  • Loading branch information
aymanbagabas committed Jul 26, 2023
1 parent 728173f commit d9a682f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions server/access/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package access

import "context"

// ContextKey is the context key for the access level.
var ContextKey = &struct{ string }{"access"}

// FromContext returns the access level from the context.
func FromContext(ctx context.Context) AccessLevel {
if ac, ok := ctx.Value(ContextKey).(AccessLevel); ok {
return ac
}

Check warning on line 12 in server/access/context.go

View check run for this annotation

Codecov / codecov/patch

server/access/context.go#L9-L12

Added lines #L9 - L12 were not covered by tests

return -1

Check warning on line 14 in server/access/context.go

View check run for this annotation

Codecov / codecov/patch

server/access/context.go#L14

Added line #L14 was not covered by tests
}

// WithContext returns a new context with the access level.
func WithContext(ctx context.Context, ac AccessLevel) context.Context {
return context.WithValue(ctx, ContextKey, ac)

Check warning on line 19 in server/access/context.go

View check run for this annotation

Codecov / codecov/patch

server/access/context.go#L18-L19

Added lines #L18 - L19 were not covered by tests
}
2 changes: 2 additions & 0 deletions server/web/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ func withAccess(next http.Handler) http.HandlerFunc {
}

Check warning on line 260 in server/web/git.go

View check run for this annotation

Codecov / codecov/patch

server/web/git.go#L257-L260

Added lines #L257 - L260 were not covered by tests

accessLevel := be.AccessLevelForUser(ctx, repoName, user)
ctx = access.WithContext(ctx, accessLevel)
r = r.WithContext(ctx)

logger.Info("access level", "repo", repoName, "level", accessLevel)

Check warning on line 266 in server/web/git.go

View check run for this annotation

Codecov / codecov/patch

server/web/git.go#L262-L266

Added lines #L262 - L266 were not covered by tests

Expand Down

0 comments on commit d9a682f

Please sign in to comment.