mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-15 18:56:59 +00:00
Lint check
This commit is contained in:
parent
2d1bff4254
commit
4c281936b5
3 changed files with 54 additions and 5 deletions
|
@ -136,3 +136,46 @@ func loadOrganizationOwners(ctx context.Context, users user_model.UserList, orgI
|
|||
}
|
||||
return ownerMaps, nil
|
||||
}
|
||||
|
||||
// GetUserPublicMemberships returns a map of organization IDs to boolean values
|
||||
// indicating whether the user's membership in each organization is public
|
||||
func GetUserPublicMemberships(ctx context.Context, userID int64, orgIDs []int64) (map[int64]bool, error) {
|
||||
result := make(map[int64]bool)
|
||||
|
||||
// Set default value (not public) for all orgs
|
||||
for _, orgID := range orgIDs {
|
||||
result[orgID] = false
|
||||
}
|
||||
|
||||
if len(orgIDs) == 0 {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
type PublicMembership struct {
|
||||
OrgID int64 `xorm:"org_id"`
|
||||
}
|
||||
|
||||
publicMemberships := make([]PublicMembership, 0, len(orgIDs))
|
||||
|
||||
sess := db.GetEngine(ctx).
|
||||
Table("org_user").
|
||||
Where("uid = ?", userID).
|
||||
And("is_public = ?", true)
|
||||
|
||||
// Add the IN condition only if there are orgIDs
|
||||
if len(orgIDs) > 0 {
|
||||
sess = sess.In("org_id", orgIDs)
|
||||
}
|
||||
|
||||
err := sess.Cols("org_id").Find(&publicMemberships)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Mark public memberships
|
||||
for _, membership := range publicMemberships {
|
||||
result[membership.OrgID] = true
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
|
|
@ -217,13 +217,19 @@ func Organization(ctx *context.Context) {
|
|||
|
||||
// Get public membership status for each organization
|
||||
orgsIsPublicMember := make(map[int64]bool)
|
||||
if len(orgs) > 0 {
|
||||
// Extract all org IDs
|
||||
orgIDs := make([]int64, 0, len(orgs))
|
||||
for _, org := range orgs {
|
||||
isPublic, err := organization.IsPublicMembership(ctx, org.ID, ctx.Doer.ID)
|
||||
orgIDs = append(orgIDs, org.ID)
|
||||
}
|
||||
|
||||
var err error
|
||||
orgsIsPublicMember, err = organization.GetUserPublicMemberships(ctx, ctx.Doer.ID, orgIDs)
|
||||
if err != nil {
|
||||
ctx.ServerError("IsPublicMembership", err)
|
||||
ctx.ServerError("GetUserPublicMemberships", err)
|
||||
return
|
||||
}
|
||||
orgsIsPublicMember[org.ID] = isPublic
|
||||
}
|
||||
|
||||
ctx.Data["Orgs"] = orgs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue