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

permissions-center: expose new permissionSyncJobs GraphQL API.#47933

Merged
sashaostrikov merged 7 commits into
mainfrom
ao/pc/sync-job-api
Feb 21, 2023
Merged

permissions-center: expose new permissionSyncJobs GraphQL API.#47933
sashaostrikov merged 7 commits into
mainfrom
ao/pc/sync-job-api

Conversation

@sashaostrikov

@sashaostrikov sashaostrikov commented Feb 21, 2023

Copy link
Copy Markdown
Contributor

This substitutes experimental permissionsSyncJobs API and removes storing permission sync stats into Redis.

Test plan:
Unit tests updated and added.
Local sg run and API query tests.

Closes https://github.com/sourcegraph/sourcegraph/issues/47731.
Closes https://github.com/sourcegraph/sourcegraph/issues/47308.

@sashaostrikov sashaostrikov added the permissions-center Tracking issue for all-things permissions center. label Feb 21, 2023
@sashaostrikov sashaostrikov requested review from a team and bobheadxi February 21, 2023 08:29
@sashaostrikov sashaostrikov self-assigned this Feb 21, 2023
@cla-bot cla-bot Bot added the cla-signed label Feb 21, 2023
@sourcegraph-bot

sourcegraph-bot commented Feb 21, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff ccfa75c...a0efa5d.

Notify File(s)
@indradhanush enterprise/cmd/repo-updater/internal/authz/perms_syncer.go
enterprise/cmd/repo-updater/internal/authz/perms_syncer_worker.go
@unknwon enterprise/cmd/frontend/internal/authz/init.go
enterprise/cmd/frontend/internal/authz/resolvers/permission_sync_jobs.go
enterprise/cmd/frontend/internal/authz/resolvers/permission_sync_jobs_test.go
enterprise/cmd/frontend/internal/authz/resolvers/permissions_sync_jobs.go
enterprise/cmd/frontend/internal/authz/resolvers/resolver.go
enterprise/cmd/frontend/internal/authz/resolvers/resolver_test.go
enterprise/cmd/repo-updater/internal/authz/perms_syncer.go
enterprise/cmd/repo-updater/internal/authz/perms_syncer_worker.go
enterprise/internal/authz/syncjobs/BUILD.bazel
enterprise/internal/authz/syncjobs/mocks_test.go
enterprise/internal/authz/syncjobs/records_reader.go
enterprise/internal/authz/syncjobs/records_reader_test.go
enterprise/internal/authz/syncjobs/records_store.go
enterprise/internal/authz/syncjobs/records_store_test.go
enterprise/internal/authz/syncjobs/status.go

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently we use a reason as a message, I'm still not 100% sure should we convert stuff like REASON_USER_EMAIL_REMOVED to more user friendly string in frontend or backend.

Anyway, I will add this function to our backend/UI code in one of the following PRs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, I won't mind doing it on frontend eve. Your choice.

@sg-e2e-regression-test-bob

sg-e2e-regression-test-bob commented Feb 21, 2023

Copy link
Copy Markdown

Bundle size report 📦

Initial size Total size Async size Modules
0.02% (+0.51 kb) 0.00% (+0.58 kb) 0.00% (+0.07 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits 309a464 and ccfa75c or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realised we are not showing the priority on the frontend. Might be a good idea to show it somehow.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is PermissionSyncJobProvider ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is effectively a code host AFAIR
described here https://github.com/sourcegraph/sourcegraph/issues/47301

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO, any user can also trigger manual sync for themselves.

It should be CheckSiteAdminOrSameUser

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, this is an unintended change, something weird must have happened during rebase. Will revert it

@0xnmn 0xnmn Feb 21, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NO, any user can also view their own perms info.

It should be CheckSiteAdminOrSameUser

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ This. I recently changed it so that users can view the info as well, so please don't take it away 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First will be nil in case of backward pagination. This condition is wrong.

You should be able to remove this check safely.

@0xnmn 0xnmn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good except the 2 security checks. Non-site admin users can also view their own perms info and trigger a manual sync for themselves.

This substitutes experimental `permissionsSyncJobs` API and removes storing permission sync stats into Redis.

Test plan:
Unit tests updated and added.
Local sg run and API query tests.
Comment thread CHANGELOG.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this TODO? Where should the link point to? This PR? :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, forgot about it 😬

Comment thread CHANGELOG.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Comment thread cmd/frontend/graphqlbackend/authz.go Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we change from a pointer to a non-pointer on args? As far as I see, the graphql schema is defined in almost the same way, so would like to understand this for my own sake.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListPermissionSyncJobsArgs is an interface (we sometimes declare interfaces, sometimes don't, I just like the former approach)

Comment on lines 374 to 377

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between MANUAL and SOURCEGRAPH?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MANUAL is a manual sync for a user triggered by user.
SOURCEGRAPH is a sync due to internal sg event (email is added/deleted, user is added to sg org, etc.)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if both UserID and RepositoryID are 0? Should we return an error in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is mutually exclusive via DB constraint.
Should not happen (c)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

☝️ This. I recently changed it so that users can view the info as well, so please don't take it away 😄

Comment thread internal/gqlutil/datetime.go Outdated
Comment on lines 22 to 29

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A unit test would be nice for a lib function like this...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added here!

@sashaostrikov sashaostrikov requested a review from 0xnmn February 21, 2023 12:49
@sashaostrikov sashaostrikov merged commit e8416fc into main Feb 21, 2023
@sashaostrikov sashaostrikov deleted the ao/pc/sync-job-api branch February 21, 2023 18:09
Comment thread CHANGELOG.md
### Changed

-
- Experimental GraphQL query, `permissionsSyncJobs` is removed and substituted with new non-experimental `permissionSyncJobs` query (mind the singular form of permission) which provides full information about permission sync jobs stored in the database. `authz.syncJobsRecordsTTL`. [#47933](https://github.com/sourcegraph/sourcegraph/pull/47933)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete sentence I think? there's a mention of authz.syncJobsRecordsTTL that seems to have been moved to the removed section

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, that's true, I'm gonna fix it now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for catching it!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed permissions-center Tracking issue for all-things permissions center.

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

Expose new basic perms sync API Graphql API: expose provider status

6 participants