Skip to content

Commit 6e36082

Browse files
kylecarbsEmyrk
andauthored
chore: add github.com user id association (#14045)
* 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! * gen * Fix model query * Fix linting * Ignore auditing github.com user id * Add test * Fix gh url var name * Update migration * Update coderd/database/dbauthz/dbauthz.go Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com> * Fix updating to when the token changes * Fix migration --------- Co-authored-by: Steven Masley <Emyrk@users.noreply.github.com>
1 parent 4d4d27c commit 6e36082

25 files changed

+222
-37
lines changed

coderd/apidoc/docs.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbauthz/dbauthz.go

+17
Original file line numberDiff line numberDiff line change
@@ -3260,6 +3260,23 @@ func (q *querier) UpdateUserDeletedByID(ctx context.Context, id uuid.UUID) error
32603260
return deleteQ(q.log, q.auth, q.db.GetUserByID, q.db.UpdateUserDeletedByID)(ctx, id)
32613261
}
32623262

3263+
func (q *querier) UpdateUserGithubComUserID(ctx context.Context, arg database.UpdateUserGithubComUserIDParams) error {
3264+
user, err := q.db.GetUserByID(ctx, arg.ID)
3265+
if err != nil {
3266+
return err
3267+
}
3268+
3269+
err = q.authorizeContext(ctx, policy.ActionUpdatePersonal, user)
3270+
if err != nil {
3271+
// System user can also update
3272+
err = q.authorizeContext(ctx, policy.ActionUpdate, user)
3273+
if err != nil {
3274+
return err
3275+
}
3276+
}
3277+
return q.db.UpdateUserGithubComUserID(ctx, arg)
3278+
}
3279+
32633280
func (q *querier) UpdateUserHashedPassword(ctx context.Context, arg database.UpdateUserHashedPasswordParams) error {
32643281
user, err := q.db.GetUserByID(ctx, arg.ID)
32653282
if err != nil {

coderd/database/dbauthz/dbauthz_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,12 @@ func (s *MethodTestSuite) TestUser() {
11051105
u := dbgen.User(s.T(), db, database.User{})
11061106
check.Args(u.ID).Asserts(u, policy.ActionDelete).Returns()
11071107
}))
1108+
s.Run("UpdateUserGithubComUserID", s.Subtest(func(db database.Store, check *expects) {
1109+
u := dbgen.User(s.T(), db, database.User{})
1110+
check.Args(database.UpdateUserGithubComUserIDParams{
1111+
ID: u.ID,
1112+
}).Asserts(u, policy.ActionUpdatePersonal)
1113+
}))
11081114
s.Run("UpdateUserHashedPassword", s.Subtest(func(db database.Store, check *expects) {
11091115
u := dbgen.User(s.T(), db, database.User{})
11101116
check.Args(database.UpdateUserHashedPasswordParams{

coderd/database/dbmem/dbmem.go

+20
Original file line numberDiff line numberDiff line change
@@ -7985,6 +7985,26 @@ func (q *FakeQuerier) UpdateUserDeletedByID(_ context.Context, id uuid.UUID) err
79857985
return sql.ErrNoRows
79867986
}
79877987

7988+
func (q *FakeQuerier) UpdateUserGithubComUserID(_ context.Context, arg database.UpdateUserGithubComUserIDParams) error {
7989+
err := validateDatabaseType(arg)
7990+
if err != nil {
7991+
return err
7992+
}
7993+
7994+
q.mutex.Lock()
7995+
defer q.mutex.Unlock()
7996+
7997+
for i, user := range q.users {
7998+
if user.ID != arg.ID {
7999+
continue
8000+
}
8001+
user.GithubComUserID = arg.GithubComUserID
8002+
q.users[i] = user
8003+
return nil
8004+
}
8005+
return sql.ErrNoRows
8006+
}
8007+
79888008
func (q *FakeQuerier) UpdateUserHashedPassword(_ context.Context, arg database.UpdateUserHashedPasswordParams) error {
79898009
if err := validateDatabaseType(arg); err != nil {
79908010
return err

coderd/database/dbmetrics/dbmetrics.go

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dump.sql

+4-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE users DROP COLUMN github_com_user_id;
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/modelqueries.go

+1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ func (q *sqlQuerier) GetAuthorizedUsers(ctx context.Context, arg GetUsersParams,
361361
&i.QuietHoursSchedule,
362362
&i.ThemePreference,
363363
&i.Name,
364+
&i.GithubComUserID,
364365
&i.Count,
365366
); err != nil {
366367
return nil, err

coderd/database/models.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)