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

batches: add SSBC support for organisations#42131

Merged
LawnGnome merged 12 commits into
mainfrom
aharvey/ssbc-orgs
Sep 29, 2022
Merged

batches: add SSBC support for organisations#42131
LawnGnome merged 12 commits into
mainfrom
aharvey/ssbc-orgs

Conversation

@LawnGnome

@LawnGnome LawnGnome commented Sep 27, 2022

Copy link
Copy Markdown
Contributor

This PR adds full support for creating and applying batch changes within organisations from SSBC. The vast majority of the work here was around our permission handling, rather than anything to do with SSBC or the UI specifically.

Fixes #36536.

Permissions

As a refresher (because I certainly needed one), this is how permissions are documented to work in Batch Changes.

I discovered that our organisation handling was basically broken when querying batch changes that the user has admin rights to — batch changes owned by organisations that the user belongs to would never be returned. This affected both client and server side batch change functionality, and has been fixed.

Fixing this broke a number of tests that didn't set up full user, organisation, and user/org membership fixtures. These tests have been updated to set up more realistic environments.

Fixing that made me realise how hard some of the batch change store tests were to update, since their state was essentially linked to specific cs indices doing magic things upon creation. I made that creation explicit, rather than implicit, and updated tests that needed updating from there. (I chose not to do a full conversion of those tests to use assert and require, but did make spot updates as I rewrote specific subtests.)

One remaining issue here is that (non-admin) users belonging to an organisation may not be able to see all executions of a batch change in that organisation — right now, they only have access to their own executions. On balance, this might be the right thing to do, but input welcome there.

UI changes

This PR reverted #37187 to reinstate a usable namespace selector when creating a batch change from the UI. I took the opportunity to simplify the NamespaceSelector prop types along the way, since our cases are now somewhat simpler.

While testing this work, I also realised that there were a few potential banners on the batch change details page that are unactionable if the user doesn't have admin access to that batch change, so I've removed those in that case.

One final change that I would like feedback on is that users who cannot administer a batch change will now not see the Edit and Close buttons on the batch change. The alternative here would be to disable them with tooltips, but showing them at all feels a bit wrong to me. Thoughts?

Test plan

I believe I've tested all the possible combinations here (site admin in an org, site admin not in an org but using their site admin powers (maybe) responsibly, user in an org, user not in an org), and have added what I think are reasonable unit tests covering this at the resolver and store levels.

@cla-bot cla-bot Bot added the cla-signed label Sep 27, 2022
@LawnGnome LawnGnome marked this pull request as ready for review September 28, 2022 00:33
@sourcegraph-bot

sourcegraph-bot commented Sep 28, 2022

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff cc07fd8...a91ac89.

Notify File(s)
@courier-new client/web/src/enterprise/batches/create/ConfigurationForm.tsx
client/web/src/enterprise/batches/create/NamespaceSelector.tsx
client/web/src/enterprise/batches/detail/BatchChangeDetailsPage.tsx
client/web/src/enterprise/batches/list/BatchChangeListPage.tsx
@efritz enterprise/cmd/worker/internal/batches/workers/reconciler_worker_test.go
@eseliger client/web/src/enterprise/batches/create/ConfigurationForm.tsx
client/web/src/enterprise/batches/create/NamespaceSelector.tsx
client/web/src/enterprise/batches/detail/BatchChangeDetailsPage.tsx
client/web/src/enterprise/batches/list/BatchChangeListPage.tsx
enterprise/cmd/worker/internal/batches/workers/reconciler_worker_test.go
enterprise/internal/batches/service/service.go
enterprise/internal/batches/service/service_test.go
enterprise/internal/batches/store/batch_changes.go
enterprise/internal/batches/store/batch_changes_test.go
enterprise/internal/batches/testing/org.go

@LawnGnome LawnGnome requested a review from a team September 28, 2022 00:47
"testing"

"github.com/keegancsmith/sqlf"
"github.com/stretchr/testify/require"

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've seen a number of patterns for assertion within the codebase but this is new. Is there a difference between require.NoError and assert.NoError

@LawnGnome LawnGnome Sep 28, 2022

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.

I see require and assert the same way as t.Fatal versus t.Error, respectively (and, indeed, that's what they ultimately map to under the hood). Errors from fixture setup or teardown I would tend to handle with require, since there's usually no sensible way to continue, whereas error from assertions related to the actual test I would tend to use assert for, since there may be utility in continuing to run the test case.

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.

Yep! I use require when there should never be an error (set setups). If an error occurs, there is no reason to continue since something is super broke. require will stop a test in its tracks, but assert will let the test continue even is the assertion fails (that way you can see all the assertion failures at once instead one at a time)

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.

Thanks all!

Comment thread client/web/src/enterprise/batches/detail/BatchChangeDetailsPage.tsx Outdated
…e.tsx

Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
@adeola-ak

Copy link
Copy Markdown
Contributor

I agree, I think omitting the buttons is better than disabling them. Thanks for the fix @LawnGnome. Do you mind adding the comment summary descriptor for CanAdministerInNamespace? I think this is something I can use in something im working on and a summary might make it clearer

@adeola-ak adeola-ak self-requested a review September 29, 2022 18:44
@LawnGnome

Copy link
Copy Markdown
Contributor Author

Do you mind adding the comment summary descriptor for CanAdministerInNamespace?

Sure thing! Added.

@LawnGnome LawnGnome enabled auto-merge (squash) September 29, 2022 19:15
@LawnGnome LawnGnome merged commit 1a387de into main Sep 29, 2022
@LawnGnome LawnGnome deleted the aharvey/ssbc-orgs branch September 29, 2022 19:26
@adeola-ak adeola-ak removed their request for review September 29, 2022 21:37

@eseliger eseliger left a comment

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.

awesome! big gap closed :)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSBC in orgs

6 participants