Skip to content

Commit 07b05e0

Browse files
committed
chore: add github.com user id association
This will eventually be used to show an indicator in the UI to star the repository if you've been using Coder for a while and have not starred the repo. If you have, we'll never show a thing!
1 parent 58b810f commit 07b05e0

File tree

15 files changed

+189
-30
lines changed

15 files changed

+189
-30
lines changed

coderd/database/dbauthz/dbauthz.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,6 +3270,23 @@ func (q *querier) UpdateUserDeletedByID(ctx context.Context, id uuid.UUID) error
32703270
return deleteQ(q.log, q.auth, q.db.GetUserByID, q.db.UpdateUserDeletedByID)(ctx, id)
32713271
}
32723272

3273+
func (q *querier) UpdateUserGithubComUserID(ctx context.Context, arg database.UpdateUserGithubComUserIDParams) error {
3274+
user, err := q.db.GetUserByID(ctx, arg.ID)
3275+
if err != nil {
3276+
return err
3277+
}
3278+
3279+
err = q.authorizeContext(ctx, policy.ActionUpdatePersonal, user)
3280+
if err != nil {
3281+
// Admins can update passwords for other users.
3282+
err = q.authorizeContext(ctx, policy.ActionUpdate, user)
3283+
if err != nil {
3284+
return err
3285+
}
3286+
}
3287+
return q.db.UpdateUserGithubComUserID(ctx, arg)
3288+
}
3289+
32733290
func (q *querier) UpdateUserHashedPassword(ctx context.Context, arg database.UpdateUserHashedPasswordParams) error {
32743291
user, err := q.db.GetUserByID(ctx, arg.ID)
32753292
if err != nil {

coderd/database/dbmem/dbmem.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8094,6 +8094,26 @@ func (q *FakeQuerier) UpdateUserDeletedByID(_ context.Context, id uuid.UUID) err
80948094
return sql.ErrNoRows
80958095
}
80968096

8097+
func (q *FakeQuerier) UpdateUserGithubComUserID(ctx context.Context, arg database.UpdateUserGithubComUserIDParams) error {
8098+
err := validateDatabaseType(arg)
8099+
if err != nil {
8100+
return err
8101+
}
8102+
8103+
q.mutex.Lock()
8104+
defer q.mutex.Unlock()
8105+
8106+
for i, user := range q.users {
8107+
if user.ID != arg.ID {
8108+
continue
8109+
}
8110+
user.GithubComUserID = arg.GithubComUserID
8111+
q.users[i] = user
8112+
return nil
8113+
}
8114+
return sql.ErrNoRows
8115+
}
8116+
80978117
func (q *FakeQuerier) UpdateUserHashedPassword(_ context.Context, arg database.UpdateUserHashedPasswordParams) error {
80988118
if err := validateDatabaseType(arg); err != nil {
80998119
return err

coderd/database/dbmetrics/dbmetrics.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dump.sql

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE users DROP COLUMN github_com_user_id;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALTER TABLE users ADD COLUMN github_com_user_id BIGINT;
2+
3+
COMMENT ON COLUMN users.github_com_user_id IS 'The GitHub.com numerical user ID. At time of implementation, this is used to check if the user has starred the Coder repository.';

coderd/database/models.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 46 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)