Skip to content

Commit

Permalink
Merge pull request #740 from rokwire/develop
Browse files Browse the repository at this point in the history
merge develop into main
  • Loading branch information
stefanvit authored Dec 13, 2024
2 parents 20545b1 + ae6d2e1 commit 01e7e72
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 71 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## [1.45.1] - 2024-13-10
### Fixed
- GET services/accounts returns unsorted response [#733](https://github.com/rokwire/core-building-block/issues/733)

## [1.45.0] - 2024-12-10
### Added
- Public account filtering by unstructured properties [#734](https://github.com/rokwire/core-building-block/issues/734)
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Patches for **Core Building Block** in this repository will only be applied to the following versions:
| Version | Supported |
| -------- | ------------------ |
|1.45.0 | :white_check_mark: |
| < 1.45.0| :x: |
|1.45.1 | :white_check_mark: |
| < 1.45.1| :x: |

## Reporting a Bug or Vulnerability

Expand Down
5 changes: 0 additions & 5 deletions core/app_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package core
import (
"core-building-block/core/model"
"core-building-block/driven/storage"
"slices"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -163,10 +162,6 @@ func (app *application) serGetPublicAccounts(appID string, orgID string, limit i
return nil, errors.WrapErrorAction(logutils.ActionFind, model.TypeAccount, nil, err)
}

slices.SortFunc(accounts, func(i, j model.PublicAccount) int {
return i.OrderForSort(&j)
})

return accounts, nil
}

Expand Down
45 changes: 0 additions & 45 deletions core/model/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,51 +937,6 @@ type PublicAccount struct {
Identifiers []PublicAccountIdentifier `json:"identifiers"`
}

// OrderForSort provides an ordering for sorting PublicAccounts using slices.SortFunc
// It returns -1 when a < other, 1 when a > other, and 0 when a == other or a and other are both nil
func (a *PublicAccount) OrderForSort(other *PublicAccount) int {
if a == nil {
if other == nil {
return 0
}
return 1
}
if other == nil {
return -1
}

lastName := ""
if a.Profile.LastName != nil {
lastName = *a.Profile.LastName
}
lastName2 := ""
if other.Profile.LastName != nil {
lastName2 = *other.Profile.LastName
}

if lastName < lastName2 {
return -1
} else if lastName > lastName2 {
return 1
}

firstName := ""
if a.Profile.FirstName != nil {
firstName = *a.Profile.FirstName
}
firstName2 := ""
if other.Profile.FirstName != nil {
firstName2 = *other.Profile.FirstName
}

if firstName < firstName2 {
return -1
} else if firstName > firstName2 {
return 1
}
return 0
}

// PublicAccountIdentifier represents an account identifier made publicly-known by a user
type PublicAccountIdentifier struct {
Code string `json:"code"`
Expand Down
36 changes: 19 additions & 17 deletions driven/storage/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1513,20 +1513,6 @@ func (sa *Adapter) FindPublicAccounts(context TransactionContext, appID string,
pipeline = append(pipeline, bson.M{"$match": regexFilter})
}

pipeline = append(pipeline, bson.M{"$match": bson.M{"org_apps_memberships.app_org_id": appOrg.ID, "privacy.public": true}})
pipeline = append(pipeline, bson.M{"$lookup": bson.M{
"from": "follows",
"localField": "_id",
"foreignField": "following_id",
"as": "followings",
}})
pipeline = append(pipeline, bson.M{"$lookup": bson.M{
"from": "follows",
"localField": "_id",
"foreignField": "follower_id",
"as": "followers",
}})

if firstName != nil {
firstNameStr = *firstName
pipeline = append(pipeline, bson.M{"$match": bson.M{"profile.first_name": *firstName}})
Expand Down Expand Up @@ -1554,17 +1540,33 @@ func (sa *Adapter) FindPublicAccounts(context TransactionContext, appID string,
pipeline = append(pipeline, bson.M{"$match": bson.M{"profile.unstructured_properties." + k: v}})
}

// adds boolean value whether API calling user is following account
pipeline = append(pipeline, bson.M{"$addFields": bson.M{"is_following": bson.M{"$in": bson.A{userID, "$followings.follower_id"}}}})
pipeline = append(pipeline, bson.M{"$match": bson.M{"org_apps_memberships.app_org_id": appOrg.ID, "privacy.public": true}})
pipeline = append(pipeline, bson.M{"$sort": bson.D{{Key: "profile.last_name", Value: 1}, {Key: "profile.first_name", Value: 1}}})

if offset != nil {
if offset != nil && *offset > 0 {
pipeline = append(pipeline, bson.M{"$skip": *offset})
}

if limit != nil {
pipeline = append(pipeline, bson.M{"$limit": *limit})
}

pipeline = append(pipeline, bson.M{"$lookup": bson.M{
"from": "follows",
"localField": "_id",
"foreignField": "following_id",
"as": "followings",
}})
pipeline = append(pipeline, bson.M{"$lookup": bson.M{
"from": "follows",
"localField": "_id",
"foreignField": "follower_id",
"as": "followers",
}})

// adds boolean value whether API calling user is following account
pipeline = append(pipeline, bson.M{"$addFields": bson.M{"is_following": bson.M{"$in": bson.A{userID, "$followings.follower_id"}}}})

var results []tenantAccount
err = sa.db.tenantsAccounts.Aggregate(pipeline, &results, nil)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion driver/web/docs/gen/def.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: Rokwire Core Building Block API
description: Core Building Block API Documentation
version: 1.45.0
version: 1.45.1
servers:
- url: 'https://api.rokwire.illinois.edu/core'
description: Production server
Expand Down
2 changes: 1 addition & 1 deletion driver/web/docs/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: Rokwire Core Building Block API
description: Core Building Block API Documentation
version: 1.45.0
version: 1.45.1
servers:
- url: https://api.rokwire.illinois.edu/core
description: Production server
Expand Down

0 comments on commit 01e7e72

Please sign in to comment.