Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit fa90531

Browse files
authored
Fix explicit perms label being missing on repo permissions page (#57583)
1 parent e014f5e commit fa90531

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

client/web/src/enterprise/repo/settings/RepoSettingsPermissionsPage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,10 @@ const PermissionReasonBadgeProps: { [reason: string]: BadgeProps } = {
260260
},
261261
Unrestricted: { variant: 'primary', tooltip: 'The repository is accessible to all the users. ' },
262262
'Site Admin': { variant: 'secondary', tooltip: 'The user is site admin and has access to all the repositories.' },
263+
'Explicit API': {
264+
variant: 'success',
265+
tooltip: 'The permission was granted through explicit permissions API.',
266+
},
263267
}
264268

265269
interface ScheduleRepositoryPermissionsSyncActionContainerProps {

internal/database/perms_store.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ func (s *permsStore) ListRepoPermissions(ctx context.Context, repoID api.RepoID,
20752075

20762076
perms := make([]*RepoPermission, 0)
20772077
for rows.Next() {
2078-
user, updatedAt, err := s.scanUsersPermissionsInfo(rows)
2078+
user, updatedAt, source, err := scanUsersPermissionsInfo(rows)
20792079
if err != nil {
20802080
return nil, err
20812081
}
@@ -2087,6 +2087,8 @@ func (s *permsStore) ListRepoPermissions(ctx context.Context, repoID api.RepoID,
20872087
} else if user.SiteAdmin && !authzParams.AuthzEnforceForSiteAdmins {
20882088
reason = UserRepoPermissionReasonSiteAdmin
20892089
updatedAt = time.Time{}
2090+
} else if source == authz.SourceAPI {
2091+
reason = UserRepoPermissionReasonExplicitPerms
20902092
}
20912093

20922094
perms = append(perms, &RepoPermission{User: user, Reason: reason, UpdatedAt: updatedAt})
@@ -2095,9 +2097,10 @@ func (s *permsStore) ListRepoPermissions(ctx context.Context, repoID api.RepoID,
20952097
return perms, nil
20962098
}
20972099

2098-
func (s *permsStore) scanUsersPermissionsInfo(rows dbutil.Scanner) (*types.User, time.Time, error) {
2100+
func scanUsersPermissionsInfo(rows dbutil.Scanner) (*types.User, time.Time, authz.PermsSource, error) {
20992101
var u types.User
21002102
var updatedAt time.Time
2103+
var source *string
21012104
var displayName, avatarURL sql.NullString
21022105

21032106
err := rows.Scan(
@@ -2112,15 +2115,21 @@ func (s *permsStore) scanUsersPermissionsInfo(rows dbutil.Scanner) (*types.User,
21122115
&u.InvalidatedSessionsAt,
21132116
&u.TosAccepted,
21142117
&dbutil.NullTime{Time: &updatedAt},
2118+
&source,
21152119
)
21162120
if err != nil {
2117-
return nil, time.Time{}, err
2121+
return nil, time.Time{}, "", err
21182122
}
21192123

21202124
u.DisplayName = displayName.String
21212125
u.AvatarURL = avatarURL.String
21222126

2123-
return &u, updatedAt, nil
2127+
var permsSource authz.PermsSource
2128+
if source != nil {
2129+
permsSource = authz.PermsSource(*source)
2130+
}
2131+
2132+
return &u, updatedAt, permsSource, nil
21242133
}
21252134

21262135
const usersPermissionsInfoQueryFmt = `
@@ -2135,7 +2144,8 @@ SELECT
21352144
users.passwd IS NOT NULL,
21362145
users.invalidated_sessions_at,
21372146
users.tos_accepted,
2138-
urp.updated_at AS permissions_updated_at
2147+
urp.updated_at AS permissions_updated_at,
2148+
urp.source
21392149
FROM
21402150
users
21412151
LEFT JOIN user_repo_permissions urp ON urp.user_id = users.id AND urp.repo_id = %d

internal/database/perms_store_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4126,7 +4126,7 @@ func TestPermsStore_ListRepoPermissions(t *testing.T) {
41264126
}
41274127
}
41284128

4129-
q := sqlf.Sprintf(`INSERT INTO user_repo_permissions(user_id, repo_id) VALUES(555, 1), (666, 1), (NULL, 3), (666, 4)`)
4129+
q := sqlf.Sprintf(`INSERT INTO user_repo_permissions(user_id, repo_id, source) VALUES(555, 1, 'user_sync'), (666, 1, 'api'), (NULL, 3, 'api'), (666, 4, 'user_sync')`)
41304130
if err := s.execute(ctx, q); err != nil {
41314131
t.Fatal(err)
41324132
}
@@ -4145,7 +4145,7 @@ func TestPermsStore_ListRepoPermissions(t *testing.T) {
41454145
{
41464146
// have access
41474147
UserID: 666,
4148-
Reason: UserRepoPermissionReasonPermissionsSync,
4148+
Reason: UserRepoPermissionReasonExplicitPerms,
41494149
},
41504150
{
41514151
// have access
@@ -4184,7 +4184,7 @@ func TestPermsStore_ListRepoPermissions(t *testing.T) {
41844184
WantResults: []*listRepoPermissionsResult{
41854185
{
41864186
UserID: 666,
4187-
Reason: UserRepoPermissionReasonPermissionsSync,
4187+
Reason: UserRepoPermissionReasonExplicitPerms,
41884188
},
41894189
},
41904190
},
@@ -4197,7 +4197,7 @@ func TestPermsStore_ListRepoPermissions(t *testing.T) {
41974197
WantResults: []*listRepoPermissionsResult{
41984198
{
41994199
UserID: 666,
4200-
Reason: UserRepoPermissionReasonPermissionsSync,
4200+
Reason: UserRepoPermissionReasonExplicitPerms,
42014201
},
42024202
},
42034203
},
@@ -4290,7 +4290,7 @@ func TestPermsStore_ListRepoPermissions(t *testing.T) {
42904290
{
42914291
// have access
42924292
UserID: 666,
4293-
Reason: UserRepoPermissionReasonPermissionsSync,
4293+
Reason: UserRepoPermissionReasonExplicitPerms,
42944294
},
42954295
{
42964296
// have access

0 commit comments

Comments
 (0)