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

batches: surface batch change feature availability in JS context LicenseInfo#52044

Merged
courier-new merged 3 commits into
mainfrom
kr/bc-license-info-context
May 17, 2023
Merged

batches: surface batch change feature availability in JS context LicenseInfo#52044
courier-new merged 3 commits into
mainfrom
kr/bc-license-info-context

Conversation

@courier-new

@courier-new courier-new commented May 16, 2023

Copy link
Copy Markdown
Contributor

License info was recently added to the JS Context, which makes a lot of sense given it's pretty much guaranteed to be constant over the lifetime of a user's visit to Sourcegraph and it's useful to make the very earliest of rendering decisions when the web app loads.

One such decision is whether or not to display the Batch Changes tab in the nav bar, or whether or not to show the main Batch Changes list page when visiting that part of the web app. Not properly handling this decision was what led to https://github.com/sourcegraph/sourcegraph/issues/49714, a bug which Becca is working on fixes for. This PR attempts to enable a part of that fix -- namely, that if a site has a license that explicitly does not include Batch Changes in its provisions, we should not show the Batch Changes list page, only the "Getting Started" page. It does so by surfacing the Batch Changes feature configuration in that JS Context LicenseInfo object.

This PR is just the backend changes; Becca's got the corresponding frontend ones incoming.

What's also notable about this is that it would allow us to refactor away from the somewhat outdated, redundant frontend logic around assessing the license and the maxUnlicensedChangesets property on the GraphQL schema that we query and rely on in a couple other places in the frontend in order to inform users when they're about to take an action that would exceed their license capabilities. 🙂

Test plan

No Batch Changes:

  • Mock a license plan without the Batch Changes feature included
  • Load the frontend web app
  • console.log(window.context.licenseInfo)
  • Observe presence of property batchChanges: null

Dotcom

  • Run sg start dotcom
  • Load the frontend web app
  • console.log(window.context.licenseInfo)
  • Observe presence of property batchChanges: null

Limited Batch Changes

  • Mock a license plan with Batch Changes included with a MaxNumChangesets set
  • Load the frontend web app
  • console.log(window.context.licenseInfo)
  • Observe presence of property batchChanges: { maxNumChangesets: 10, unrestricted: false}

Unlimited Batch Changes

  • Mock a license plan with Batch Changes included with Unrestricted: true set
  • Load the frontend web app
  • console.log(window.context.licenseInfo)
  • Observe presence of property batchChanges: { maxNumChangesets: -1, unrestricted: true}

@courier-new courier-new requested a review from a team May 16, 2023 22:45
@courier-new courier-new self-assigned this May 16, 2023
@cla-bot cla-bot Bot added the cla-signed label May 16, 2023
@courier-new courier-new added the batch-changes Issues related to Batch Changes label May 16, 2023
@sourcegraph-bot

sourcegraph-bot commented May 16, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 78d95e6...212906f.

Notify File(s)
@unknwon enterprise/cmd/frontend/internal/licensing/init/init.go

Comment on lines +173 to 179
// BatchChangesEnabled is true if:
// * Batch Changes is NOT disabled by a flag in the site config
// * Batch Changes is NOT limited to admins-only, or it is, but the user issuing
// the request is an admin and thus can access batch changes
// It does NOT reflect whether or not the site license has batch changes available.
// Use LicenseInfo for that.
BatchChangesEnabled bool `json:"batchChangesEnabled"`

@courier-new courier-new May 16, 2023

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 added this comment to clarify that this other property on the JS Context is NOT related to the license at all, as it's kinda confusing that an instance would have batchChangesEnabled: true if their site license doesn't permit Batch Changes, and yet that's exactly what would happen haha.

We considered modifying the behavior of this field instead, but it's fundamentally trying to achieve something a bit different. This field is false if Batch Changes is explicitly disabled by a site admin with a flag in the site config, or if Batch Changes has been limited to admins only. If it's false, the admin actually is saying they do not want other users on the instance to see Batch Changes. Whereas, what we're going for is essentially product discovery/marketing for a Sourcegraph customer that just hasn't paid for Batch Changes yet. This property should probably be renamed to reflect this usage difference, but it didn't feel in scope to make this change at present.

@st0nebreaker st0nebreaker 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.

This is great, thank you! While we're exposing more of this license info I'm wondering:

(1) Should we leave window.context.licenseInfo entirely null for OSS? That makes sense to me, but not sure if we want to be more explicit here.

(2) Dotcom is being set with the following. Should we fix this to be more explicit as well since dotcom shouldn't have unrestricted batch changes?
Screenshot 2023-05-16 at 4 44 42 PM

@courier-new

Copy link
Copy Markdown
Contributor Author

Should we leave window.context.licenseInfo entirely null for OSS? That makes sense to me, but not sure if we want to be more explicit here.

Yeah I guess I feel like this is still the right call because fundamentally there is no concept of a license if you're running Sourcegraph as OSS (you gotta actually talk to us to get a license), so unless we introduce some concept of a default "OSS license" then really null feels like the most accurate representation of "license info" here.

Dotcom is being set with the following. Should we fix this to be more explicit as well since dotcom shouldn't have unrestricted batch changes?

Oh Dotcom. Yeah probably, that's a good call. 🙂

@courier-new

Copy link
Copy Markdown
Contributor Author

Updated! Now dotcom will have batchChanges: null

@st0nebreaker st0nebreaker 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.

🎇 looks great on all use cases ~ thank you!

@BolajiOlajide BolajiOlajide 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.

Looks good to me. Thanks for the fix.

@courier-new courier-new merged commit baee619 into main May 17, 2023
@courier-new courier-new deleted the kr/bc-license-info-context branch May 17, 2023 15:52
st0nebreaker added a commit that referenced this pull request May 25, 2023
Closes #49714
- Uses new batch change licensing info exposed on the JS Context (from
#52044)
- Hides Batch Change nav item on OSS
- Shows Get Started page for dotcom & enterprise customers without a
Batch Changes license

## Test plan
- Run `sg start oss` - observe missing batch changes nav item (route is
inaccessible too)
- Run `sg start dotcom` - observe batch changes page, only the `Get
started` content displays (subrotues are inaccessible)
- Mock enterprise with limited batch changes - observe limited batch
change warning once executing a SSBC

---------

Co-authored-by: Kelli Rockwell <kelli@sourcegraph.com>
ErikaRS pushed a commit that referenced this pull request Jun 22, 2023
Closes #49714
- Uses new batch change licensing info exposed on the JS Context (from
#52044)
- Hides Batch Change nav item on OSS
- Shows Get Started page for dotcom & enterprise customers without a
Batch Changes license

## Test plan
- Run `sg start oss` - observe missing batch changes nav item (route is
inaccessible too)
- Run `sg start dotcom` - observe batch changes page, only the `Get
started` content displays (subrotues are inaccessible)
- Mock enterprise with limited batch changes - observe limited batch
change warning once executing a SSBC

---------

Co-authored-by: Kelli Rockwell <kelli@sourcegraph.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

batch-changes Issues related to Batch Changes cla-signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants