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
133133
 		"OrgRepositoriesURL": orgRepositoriesBaseURL(string(org.Slug)),
134134
 		"PinnedRepos":        pinnedRepos,
135135
 		"PinCandidates":      pinCandidates,
136
-		"PinsRemaining":      profilePinsRemaining(pinCandidates),
136
+		"PinsRemaining":      profilePinsRemaining(pinCandidates, profilePinLimit),
137137
 		"RepoCount":          int64(len(repos)),
138138
 		"TeamCount":          teamCount,
139139
 		"MemberCount":        memberCount,
internal/web/handlers/profile/pins.gomodified
@@ -501,15 +501,21 @@ func sortPinCandidates(candidates []profilePinCandidate) {
501501
 	})
502502
 }
503503
 
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 {
505511
 	count := 0
506512
 	for _, candidate := range candidates {
507513
 		if candidate.IsPinned {
508514
 			count++
509515
 		}
510516
 	}
511
-	if count >= profilePinLimit {
517
+	if int64(count) >= cap {
512518
 		return 0
513519
 	}
514
-	return profilePinLimit - count
520
+	return int(cap) - count
515521
 }
internal/web/handlers/profile/profile.gomodified
@@ -182,6 +182,7 @@ func (h *Handlers) serveProfile(w http.ResponseWriter, r *http.Request) {
182182
 	followState := h.userFollowState(r.Context(), user.ID, viewer)
183183
 	visibleRepos := h.visibleUserRepos(r.Context(), user.ID, viewer)
184184
 	pinnedRepos, pinCandidates := h.userPinData(r.Context(), user)
185
+	userPinsCap, _ := h.userProfilePinCap(r.Context(), user.ID)
185186
 	readme, hasReadme := h.profileReadme(r.Context(), user, viewer)
186187
 	displayName := user.DisplayName
187188
 	if displayName == "" {
@@ -213,7 +214,7 @@ func (h *Handlers) serveProfile(w http.ResponseWriter, r *http.Request) {
213214
 		"Contributions":              h.contributionCalendar(r.Context(), user, viewer, r.URL.Query()),
214215
 		"PinnedRepos":                pinnedRepos,
215216
 		"PinCandidates":              pinCandidates,
216
-		"PinsRemaining":              profilePinsRemaining(pinCandidates),
217
+		"PinsRemaining":              profilePinsRemaining(pinCandidates, userPinsCap),
217218
 		"CanCustomizePins":           isSelf,
218219
 		"PinsAction":                 "/" + url.PathEscape(user.Username) + "/pins",
219220
 		"ContributionSettingsAction": "/" + url.PathEscape(user.Username) + "/contribution-settings",