tenseleyflow/shithub / 49234c8

Browse files

Use entitlement upgrade metadata in handlers

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
49234c8d30aff00cac3b9916999d6a67ee60c4a7
Parents
2c82cd2
Tree
8362859

4 changed files

StatusFile+-
M internal/web/handlers/orgs/settings_actions.go 7 10
M internal/web/handlers/orgs/settings_actions_test.go 1 1
M internal/web/handlers/orgs/teams.go 6 1
M internal/web/handlers/repo/settings_branches.go 12 2
internal/web/handlers/orgs/settings_actions.gomodified
@@ -37,7 +37,8 @@ func (h *Handlers) settingsActionsSecretSet(w http.ResponseWriter, r *http.Reque
3737
 		return
3838
 	}
3939
 	if !decision.Allowed {
40
-		h.renderOrgActionsSettings(w, r, org, "secrets", orgActionsWriteDeniedMessage(decision, "Organization Actions secrets"), "")
40
+		w.WriteHeader(decision.HTTPStatus())
41
+		h.renderOrgActionsSettings(w, r, org, "secrets", orgActionsWriteDeniedMessage(decision, "Organization Actions secrets", string(org.Slug)), "")
4142
 		return
4243
 	}
4344
 	if h.d.SecretBox == nil {
@@ -100,7 +101,8 @@ func (h *Handlers) settingsActionsVariableSet(w http.ResponseWriter, r *http.Req
100101
 		return
101102
 	}
102103
 	if !decision.Allowed {
103
-		h.renderOrgActionsSettings(w, r, org, "variables", orgActionsWriteDeniedMessage(decision, "Organization Actions variables"), "")
104
+		w.WriteHeader(decision.HTTPStatus())
105
+		h.renderOrgActionsSettings(w, r, org, "variables", orgActionsWriteDeniedMessage(decision, "Organization Actions variables", string(org.Slug)), "")
104106
 		return
105107
 	}
106108
 	if err := r.ParseForm(); err != nil {
@@ -170,7 +172,7 @@ func (h *Handlers) renderOrgActionsSettings(w http.ResponseWriter, r *http.Reque
170172
 		"Notice":                notice,
171173
 		"FormAction":            orgActionsSettingsPath(org.Slug, kind),
172174
 		"WritesDisabled":        !decision.Allowed,
173
-		"WritesDisabledMessage": orgActionsWriteDeniedMessage(decision, orgActionsFeatureLabel(kind)),
175
+		"WritesDisabledMessage": orgActionsWriteDeniedMessage(decision, orgActionsFeatureLabel(kind), string(org.Slug)),
174176
 	}
175177
 	switch kind {
176178
 	case "secrets":
@@ -245,13 +247,8 @@ func orgActionsFeatureLabel(kind string) string {
245247
 	return "Organization Actions variables"
246248
 }
247249
 
248
-func orgActionsWriteDeniedMessage(decision entitlements.Decision, label string) string {
249
-	switch decision.Reason {
250
-	case entitlements.ReasonBillingActionNeeded:
251
-		return label + " are read-only until Team billing is brought back into good standing."
252
-	default:
253
-		return label + " require Team billing. Upgrade this organization to continue editing them."
254
-	}
250
+func orgActionsWriteDeniedMessage(decision entitlements.Decision, label, orgSlug string) string {
251
+	return decision.UpgradeBanner(label, orgSlug).Message
255252
 }
256253
 
257254
 func (h *Handlers) recordOrgActionsAudit(r *http.Request, viewer middleware.CurrentUser, action audit.Action, orgID int64, name string) {
internal/web/handlers/orgs/settings_actions_test.gomodified
@@ -110,7 +110,7 @@ func TestOrgActionsSettingsBlocksWritesWithoutTeamEntitlement(t *testing.T) {
110110
 		"value": {"super-secret"},
111111
 	})
112112
 	mux.ServeHTTP(resp, req)
113
-	if resp.Code != http.StatusOK {
113
+	if resp.Code != http.StatusPaymentRequired {
114114
 		t.Fatalf("POST org secret status=%d body=%s", resp.Code, resp.Body.String())
115115
 	}
116116
 	if got := resp.Body.String(); !strings.Contains(got, "require Team billing") {
internal/web/handlers/orgs/teams.gomodified
@@ -156,8 +156,11 @@ func (h *Handlers) teamCreate(w http.ResponseWriter, r *http.Request) {
156156
 		}
157157
 		if !decision.Allowed {
158158
 			notice := "secret-teams-upgrade"
159
-			if decision.Reason == entitlements.ReasonBillingActionNeeded {
159
+			switch decision.Reason {
160
+			case entitlements.ReasonBillingActionNeeded:
160161
 				notice = "secret-teams-billing"
162
+			case entitlements.ReasonEnterpriseContactSales:
163
+				notice = "secret-teams-enterprise"
161164
 			}
162165
 			http.Redirect(w, r, "/"+string(org.Slug)+"/teams?notice="+notice, http.StatusSeeOther)
163166
 			return
@@ -186,6 +189,8 @@ func teamsNoticeMessage(code string) string {
186189
 		return "Secret teams require Team billing. Upgrade this organization to create them."
187190
 	case "secret-teams-billing":
188191
 		return "Secret teams are read-only until Team billing is brought back into good standing."
192
+	case "secret-teams-enterprise":
193
+		return "Secret teams are unavailable for Enterprise preview organizations. Contact sales to enable them."
189194
 	default:
190195
 		return ""
191196
 	}
internal/web/handlers/repo/settings_branches.gomodified
@@ -219,13 +219,19 @@ func (h *Handlers) branchProtectionEntitlementNotice(ctx context.Context, row re
219219
 
220220
 func branchProtectionNoticeCode(decision entitlements.Decision, requiredReviewers bool) string {
221221
 	if requiredReviewers {
222
-		if decision.Reason == entitlements.ReasonBillingActionNeeded {
222
+		switch decision.Reason {
223
+		case entitlements.ReasonBillingActionNeeded:
223224
 			return "required-reviewers-billing"
225
+		case entitlements.ReasonEnterpriseContactSales:
226
+			return "required-reviewers-enterprise"
224227
 		}
225228
 		return "required-reviewers-upgrade"
226229
 	}
227
-	if decision.Reason == entitlements.ReasonBillingActionNeeded {
230
+	switch decision.Reason {
231
+	case entitlements.ReasonBillingActionNeeded:
228232
 		return "branch-protection-billing"
233
+	case entitlements.ReasonEnterpriseContactSales:
234
+		return "branch-protection-enterprise"
229235
 	}
230236
 	return "branch-protection-upgrade"
231237
 }
@@ -332,10 +338,14 @@ func settingsBranchesNoticeMessage(code string) string {
332338
 		return "Advanced branch protection on private organization repositories requires Team billing."
333339
 	case "branch-protection-billing":
334340
 		return "Advanced branch protection is read-only until Team billing is brought back into good standing."
341
+	case "branch-protection-enterprise":
342
+		return "Advanced branch protection is unavailable for Enterprise preview organizations. Contact sales to enable it."
335343
 	case "required-reviewers-upgrade":
336344
 		return "Required reviewers on private organization repositories require Team billing."
337345
 	case "required-reviewers-billing":
338346
 		return "Required reviewers are read-only until Team billing is brought back into good standing."
347
+	case "required-reviewers-enterprise":
348
+		return "Required reviewers are unavailable for Enterprise preview organizations. Contact sales to enable them."
339349
 	default:
340350
 		return ""
341351
 	}