Repository navigation
Conversation
| this.props.onSettingsChanged(newSettings) | ||
| } | ||
|
|
||
| private isUserOnFreePlan() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
iAmWillShepherd
left a comment
There was a problem hiding this comment.
Did first pass, but we still gotta do some testing for corner cases.
|
|
||
| export type Plan = 'developer' | 'free' | 'team' | 'business' | ||
|
|
||
| interface IAccountWithPlan { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| readonly author: IAPIUser | null | ||
| } | ||
|
|
||
| export type Plan = 'developer' | 'free' | 'team' | 'business' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| /** The friendly name associated with this account */ | ||
| public readonly name: string | ||
| public readonly name: string, | ||
| public readonly plan?: { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| export type Plan = 'developer' | 'free' | 'team' | 'business' | ||
|
|
||
| interface IAccountWithPlan { | ||
| readonly plan: { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| export function canCreatePrivateRepo( | ||
| userAccount: Account, | ||
| targetOrg?: IAPIUserWithPlan | null |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| userAccount: Account, | ||
| targetOrg?: IAPIUserWithPlan | null | ||
| ): boolean { | ||
| if (targetOrg == null) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| this.updateSettings({ org: null }) | ||
| this.updateSettings({ | ||
| org: null, | ||
| canCreatePrivateRepo: canCreatePrivateRepo(this.props.account), |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
@iAmWillShepherd I think this might be all good. |
niik
left a comment
There was a problem hiding this comment.
Thanks for working on this @damaneice!
I've left some suggestions and comments on top of @iAmWillShepherd's for you to look at when you've got a moment.
I'd like to raise a concern about the direction here with regards to the private checkbox being disabled and unchecked.
I believe that we should make every effort to avoid users accidentally publishing a private repository as public. While GitHub.com defaults to public repositories the difference here is that you're not just creating an empty repository. With Desktop you could be importing an existing project with sensitive information.
There isn't a lot of documentation around the plan field in the API and from experience I know it has changed several times in the past with new plans being added and renamed. To make matters worse we have to contend with GitHub Enterprise instances which could run old versions where these API changes still live on.
The only system which can definitively answer the question about whether a repository can be published as private is the server in question, be it GitHub or GitHub Enterprise.
I know the original issue called for the behavior of disable and uncheck but after looking at this PR I'd like to reopen that discussion.
My suggestion would be that we change the logic subtly so that we explicitly check to see whether we can positively say that the account is a free account and only then do we disable the checkbox. Additionally I think we must add a message coupled right next to the checkbox that says something similar to “In order to make this repository private, you’ll need to upgrade your account. “ with a link to the upgrade page on GitHub.com. The disabled state for the checkbox is pretty much undetectable as it stands now so without a coupled message I doubt users will even register that it’s disabled.
In fact, I’m not even sure if we should ever disable the checkbox. Perhaps the information text is good enough. I envision a scenario where a free user attempts to create a repository, sees that they need to upgrade, goes off and does so and then comes back and now has to relaunch the app in order to be able to create the repository. So either we keep the checkbox enabled or we re-fetch the user info whenever the app regains focus.
So the pseudo logic would be
export function canCreatePrivateRepo(
userAccount: Account,
targetOrg: IAPIUserWithPlan | null
): boolean {
return targetOrg === null
? !isFreeAccount(userAccount)
: !isFreeAccount(targetOrg) && memberCanCreateRepositories(targetOrg)
}
export function isFreeAccount(account: Account | IAPIUserWithPlan) {
if (account.plan === undefined) {
return false
}
if (account.plan.private_repos !== undefined && account.plan.private_repos > 0) {
return false
}
if (account.plan.name === 'free') {
return true
}
return false
}
export function memberCanCreateRepositories(org: IAPIUserWithPlan) {
return org.members_can_create_repositories !== false
}It’s a subtle change but it means that if we can’t for certain say that the plan is free we’re going to treat it as paid. The worst scenario here is if we get it wrong users will get an error when they try to publish a private repo just like they do today. As this PR stands today it would effectively prevent enterprise users (who don’t have a plan field in their API user model) from creating private repositories but with a more conservative approach like the one I outlined above they still can.
I'm sorry to jump in so last minute with all this feedback but we didn't do our homework upfront on this and that's all on us. We're so grateful that you have taken time out of your day to contribute to Desktop and once we've ironed out these last kinks my plan is still to be able to land this PR with a few tweaks.
Cc @desktop/product @desktop/design
| readonly author: IAPIUser | null | ||
| } | ||
|
|
||
| export type PlanType = 'developer' | 'free' | 'team' | 'business' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| targetOrg: IAPIUserWithPlan | null | ||
| ): boolean { | ||
| if (targetOrg == null) { | ||
| return userAccount.plan != null && userAccount.plan.name !== 'free' |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| import { IAPIUserWithPlan } from '../../lib/api' | ||
| import { Account } from '../../models/account' | ||
|
|
||
| export function canCreatePrivateRepo( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| */ | ||
| readonly email: string | null | ||
| readonly type: 'User' | 'Organization' | ||
| readonly members_can_create_repositories?: boolean |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| @@ -0,0 +1,17 @@ | |||
| import { IAPIUserWithPlan } from '../../lib/api' | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| } | ||
| } | ||
|
|
||
| /** Fetch all the orgs to which the user belongs. */ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
Removed the ready-for-review label while the feedback get address. @damaneice, I'll try to knock this out next week as I think this is an excellent change. Sorry for the churn on this 🙇 |
|
This can be closed as everyone has access to private repos now 🎉 🙌 🎊 |
|
@j-f1 Publishing to an organization still has these restrictions private repositories, and I think we need to revisit the original issue to wrap our heads around what the app should do - particularly things in this comment #5273 (review). I'm going to bump the original issue with this news and link to that comment as I still think there's changes to make. I see @iAmWillShepherd has had interest in getting it across the line but I think a fresh PR might be the best approach here after we've hashed out what @niik has raised. Thanks again @damaneice for your work in this area! |
Fixes #2165