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

File tree

25 files changed

+222
-37
lines changed

25 files changed

+222
-37
lines changed

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/database/dbauthz/dbauthz.go

Lines changed: 17 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 20 additions & 0 deletions
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

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.';

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy