tenseleyflow/shithub / 74a52ec

Browse files

web/handlers/profile: thread entitled cap into profilePinsRemaining; Pro users see correct slots left

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
74a52ecd2d380ca286302cf17eb77dd09d99da57
Parents
fb87e1d
Tree
d7e5eea

3 changed files

StatusFile+-
M internal/web/handlers/profile/org_profile.go 1 1
M internal/web/handlers/profile/pins.go 9 3
M internal/web/handlers/profile/profile.go 2 1
internal/web/handlers/profile/org_profile.gomodified
@@ -133,7 +133,7 @@ func (h *Handlers) serveOrgProfile(w http.ResponseWriter, r *http.Request, orgID
133
 		"OrgRepositoriesURL": orgRepositoriesBaseURL(string(org.Slug)),
133
 		"OrgRepositoriesURL": orgRepositoriesBaseURL(string(org.Slug)),
134
 		"PinnedRepos":        pinnedRepos,
134
 		"PinnedRepos":        pinnedRepos,
135
 		"PinCandidates":      pinCandidates,
135
 		"PinCandidates":      pinCandidates,
136
-		"PinsRemaining":      profilePinsRemaining(pinCandidates),
136
+		"PinsRemaining":      profilePinsRemaining(pinCandidates, profilePinLimit),
137
 		"RepoCount":          int64(len(repos)),
137
 		"RepoCount":          int64(len(repos)),
138
 		"TeamCount":          teamCount,
138
 		"TeamCount":          teamCount,
139
 		"MemberCount":        memberCount,
139
 		"MemberCount":        memberCount,
internal/web/handlers/profile/pins.gomodified
@@ -501,15 +501,21 @@ func sortPinCandidates(candidates []profilePinCandidate) {
501
 	})
501
 	})
502
 }
502
 }
503
 
503
 
504
-func profilePinsRemaining(candidates []profilePinCandidate) int {
504
+// profilePinsRemaining reports how many additional pins the owner
505
+// can add given the entitled cap. PRO08 C5: the cap is now a
506
+// parameter — for orgs, callers pass profilePinLimit; for users,
507
+// callers resolve via userProfilePinCap which reads entitlements.
508
+// Previously the function hard-coded profilePinLimit and would
509
+// under-count a Pro user's remaining slots.
510
+func profilePinsRemaining(candidates []profilePinCandidate, cap int64) int {
505
 	count := 0
511
 	count := 0
506
 	for _, candidate := range candidates {
512
 	for _, candidate := range candidates {
507
 		if candidate.IsPinned {
513
 		if candidate.IsPinned {
508
 			count++
514
 			count++
509
 		}
515
 		}
510
 	}
516
 	}
511
-	if count >= profilePinLimit {
517
+	if int64(count) >= cap {
512
 		return 0
518
 		return 0
513
 	}
519
 	}
514
-	return profilePinLimit - count
520
+	return int(cap) - count
515
 }
521
 }
internal/web/handlers/profile/profile.gomodified
@@ -182,6 +182,7 @@ func (h *Handlers) serveProfile(w http.ResponseWriter, r *http.Request) {
182
 	followState := h.userFollowState(r.Context(), user.ID, viewer)
182
 	followState := h.userFollowState(r.Context(), user.ID, viewer)
183
 	visibleRepos := h.visibleUserRepos(r.Context(), user.ID, viewer)
183
 	visibleRepos := h.visibleUserRepos(r.Context(), user.ID, viewer)
184
 	pinnedRepos, pinCandidates := h.userPinData(r.Context(), user)
184
 	pinnedRepos, pinCandidates := h.userPinData(r.Context(), user)
185
+	userPinsCap, _ := h.userProfilePinCap(r.Context(), user.ID)
185
 	readme, hasReadme := h.profileReadme(r.Context(), user, viewer)
186
 	readme, hasReadme := h.profileReadme(r.Context(), user, viewer)
186
 	displayName := user.DisplayName
187
 	displayName := user.DisplayName
187
 	if displayName == "" {
188
 	if displayName == "" {
@@ -213,7 +214,7 @@ func (h *Handlers) serveProfile(w http.ResponseWriter, r *http.Request) {
213
 		"Contributions":              h.contributionCalendar(r.Context(), user, viewer, r.URL.Query()),
214
 		"Contributions":              h.contributionCalendar(r.Context(), user, viewer, r.URL.Query()),
214
 		"PinnedRepos":                pinnedRepos,
215
 		"PinnedRepos":                pinnedRepos,
215
 		"PinCandidates":              pinCandidates,
216
 		"PinCandidates":              pinCandidates,
216
-		"PinsRemaining":              profilePinsRemaining(pinCandidates),
217
+		"PinsRemaining":              profilePinsRemaining(pinCandidates, userPinsCap),
217
 		"CanCustomizePins":           isSelf,
218
 		"CanCustomizePins":           isSelf,
218
 		"PinsAction":                 "/" + url.PathEscape(user.Username) + "/pins",
219
 		"PinsAction":                 "/" + url.PathEscape(user.Username) + "/pins",
219
 		"ContributionSettingsAction": "/" + url.PathEscape(user.Username) + "/contribution-settings",
220
 		"ContributionSettingsAction": "/" + url.PathEscape(user.Username) + "/contribution-settings",