Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge develop into main #505

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,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.51.0] - 2024-08-23
### Added
- Calendar events issues [#503](https://github.com/rokwire/groups-building-block/issues/503)

## [1.50.0] - 2024-08-22
### Added
- Add "group_id" to the bbs get group membership API [#500](https://github.com/rokwire/groups-building-block/issues/500)
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Patches for **Groups Building Block** in this repository will only be applied to

| Version | Supported |
| ------- | ------------------ |
| 1.50.0 | :white_check_mark: |
| <1.50.0 | :red_cross_mark: |
| 1.51.0 | :white_check_mark: |
| <1.51.0 | :red_cross_mark: |



Expand Down
9 changes: 7 additions & 2 deletions core/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (app *Application) createCalendarEventForGroups(clientID string, adminIdent

if memberships.GetMembershipByAccountID(current.ID) != nil {
currentAccount := model.AccountIdentifiers{AccountID: &current.ID, ExternalID: &current.NetID}
createdEvent, err := app.calendar.CreateCalendarEvent(adminIdentifiers, currentAccount, event, current.OrgID, current.AppID)
createdEvent, err := app.calendar.CreateCalendarEvent(adminIdentifiers, currentAccount, event, current.OrgID, current.AppID, groupIDs)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -209,9 +209,14 @@ func (app *Application) createCalendarEventSingleGroup(clientID string, current
return nil, nil, err
}

var groupIDs []string
if groupID != "" {
groupIDs = append(groupIDs, groupID)
}

if memberships.GetMembershipByAccountID(current.ID) != nil {
currentAccount := model.AccountIdentifiers{AccountID: &current.ID, ExternalID: &current.ExternalID}
createdEvent, err := app.calendar.CreateCalendarEvent([]model.AccountIdentifiers{}, currentAccount, event, current.OrgID, current.AppID)
createdEvent, err := app.calendar.CreateCalendarEvent([]model.AccountIdentifiers{}, currentAccount, event, current.OrgID, current.AppID, groupIDs)
if err != nil {
return nil, nil, err
}
Expand Down
8 changes: 7 additions & 1 deletion core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Services interface {
DeleteEvent(clientID string, current *model.User, eventID string, groupID string) error
GetEventUserIDs(eventID string) ([]string, error)
GetGroupMembershipsStatusAndGroupTitle(userID string) ([]model.GetGroupMembershipsResponse, error)
GetGroupsEvents(eventIDs []string) ([]model.GetGroupsEvents, error)

GetPosts(clientID string, current *model.User, filter model.PostsFilter, filterPrivatePostsValue *bool, filterByToMembers bool) ([]model.Post, error)
GetPost(clientID string, userID *string, groupID string, postID string, skipMembershipCheck bool, filterByToMembers bool) (*model.Post, error)
Expand Down Expand Up @@ -211,6 +212,10 @@ func (s *servicesImpl) GetGroupMembershipsStatusAndGroupTitle(userID string) ([]
return s.app.findGroupMembershipsStatusAndGroupsTitle(userID)
}

func (s *servicesImpl) GetGroupsEvents(eventIDs []string) ([]model.GetGroupsEvents, error) {
return s.app.findGroupsEvents(eventIDs)
}

func (s *servicesImpl) GetPosts(clientID string, current *model.User, filter model.PostsFilter, filterPrivatePostsValue *bool, filterByToMembers bool) ([]model.Post, error) {
return s.app.getPosts(clientID, current, filter, filterPrivatePostsValue, filterByToMembers)
}
Expand Down Expand Up @@ -426,6 +431,7 @@ type Storage interface {

FindEventUserIDs(context storage.TransactionContext, eventID string) ([]string, error)
FindGroupMembershipStatusAndGroupTitle(context storage.TransactionContext, userID string) ([]model.GetGroupMembershipsResponse, error)
FindGroupsEvents(context storage.TransactionContext, eventIDs []string) ([]model.GetGroupsEvents, error)

ReportGroupAsAbuse(clientID string, userID string, group *model.Group) error
ReportPostAsAbuse(clientID string, userID string, group *model.Group, post *model.Post) error
Expand Down Expand Up @@ -537,7 +543,7 @@ type Rewards interface {

// Calendar exposes Calendar BB APIs for the driver adapters
type Calendar interface {
CreateCalendarEvent(adminIdentifier []model.AccountIdentifiers, currentAccountIdentifier model.AccountIdentifiers, event map[string]interface{}, orgID string, appID string) (map[string]interface{}, error)
CreateCalendarEvent(adminIdentifier []model.AccountIdentifiers, currentAccountIdentifier model.AccountIdentifiers, event map[string]interface{}, orgID string, appID string, groupIDs []string) (map[string]interface{}, error)
UpdateCalendarEvent(currentAccountIdentifier model.AccountIdentifiers, eventID string, event map[string]interface{}, orgID string, appID string) (map[string]interface{}, error)
GetGroupCalendarEvents(currentAccountIdentifier model.AccountIdentifiers, eventIDs []string, appID string, orgID string, published *bool, filter model.GroupEventFilter) (map[string]interface{}, error)
AddPeopleToCalendarEvent(people []string, eventID string, orgID string, appID string) error
Expand Down
6 changes: 6 additions & 0 deletions core/model/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ type AccountIdentifiers struct {
ExternalID *string `json:"external_id"`
} // @name AccountIdentifiers

// GetGroupsEvents response
type GetGroupsEvents struct {
EventID string `json:"event_id" bson:"event_id"`
GroupID string `json:"group_id" bson:"group_id"`
} // @name GetGroupsEvents

// HasToMembersList Checks if the ToMembersList is not empty
func (e Event) HasToMembersList() bool {
return len(e.ToMembersList) > 0
Expand Down
4 changes: 4 additions & 0 deletions core/services_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ func (app *Application) findEventUserIDs(eventID string) ([]string, error) {
func (app *Application) findGroupMembershipsStatusAndGroupsTitle(userID string) ([]model.GetGroupMembershipsResponse, error) {
return app.storage.FindGroupMembershipStatusAndGroupTitle(nil, userID)
}

func (app *Application) findGroupsEvents(eventIDs []string) ([]model.GetGroupsEvents, error) {
return app.storage.FindGroupsEvents(nil, eventIDs)
}
5 changes: 3 additions & 2 deletions driven/calendar/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,18 @@ func NewCalendarAdapter(baseURL string, serviceAccountManager *authservice.Servi
}

// CreateCalendarEvent creates calendar event
func (a *Adapter) CreateCalendarEvent(adminIdentifier []model.AccountIdentifiers, currentAccountIdentifier model.AccountIdentifiers, event map[string]interface{}, orgID string, appID string) (map[string]interface{}, error) {
func (a *Adapter) CreateCalendarEvent(adminIdentifier []model.AccountIdentifiers, currentAccountIdentifier model.AccountIdentifiers, event map[string]interface{}, orgID string, appID string, groupIDs []string) (map[string]interface{}, error) {

type calendarRequest struct {
AdminsIdentifiers []model.AccountIdentifiers `json:"admins_identifiers"`
Event map[string]interface{} `json:"event"`
CurrentAccountIdentifiers model.AccountIdentifiers `json:"current_account_identifiers"`
AppID string `json:"app_id"`
OrgID string `json:"org_id"`
GroupIDs []string `json:"group_ids"`
}

body := calendarRequest{AdminsIdentifiers: adminIdentifier, Event: event, CurrentAccountIdentifiers: currentAccountIdentifier, AppID: appID, OrgID: orgID}
body := calendarRequest{AdminsIdentifiers: adminIdentifier, Event: event, CurrentAccountIdentifiers: currentAccountIdentifier, AppID: appID, OrgID: orgID, GroupIDs: groupIDs}
data, err := json.Marshal(body)
if err != nil {
return nil, err
Expand Down
19 changes: 19 additions & 0 deletions driven/storage/adapter_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"groups/core/model"
"time"

"github.com/rokwire/logging-library-go/v2/errors"
"github.com/rokwire/logging-library-go/v2/logutils"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
)
Expand Down Expand Up @@ -263,3 +265,20 @@ func (sa *Adapter) FindGroupMembershipStatusAndGroupTitle(context TransactionCon

return results, nil
}

// FindGroupsEvents Find group ID and event ID
func (sa *Adapter) FindGroupsEvents(context TransactionContext, eventIDs []string) ([]model.GetGroupsEvents, error) {
filter := bson.D{}

if len(eventIDs) > 0 {
filter = append(filter, bson.E{Key: "event_id", Value: bson.M{"$in": eventIDs}})
}

var groupsEvents []model.GetGroupsEvents
err := sa.db.events.Find(filter, &groupsEvents, nil)
if err != nil {
return nil, errors.WrapErrorAction(logutils.ActionFind, "groups events", nil, err)
}

return groupsEvents, nil
}
1 change: 1 addition & 0 deletions driver/web/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func (we *Adapter) Start() {
bbsSubrouter := restSubrouter.PathPrefix("/bbs").Subrouter()
bbsSubrouter.HandleFunc("/event/{event_id}/aggregated-users", we.wrapFunc(we.bbsAPIHandler.GetEventUserIDs, we.auth2.bbs.Permissions)).Methods("GET")
bbsSubrouter.HandleFunc("/groups/{user_id}/memberships", we.wrapFunc(we.bbsAPIHandler.GetGroupMemberships, we.auth2.bbs.Permissions)).Methods("GET")
bbsSubrouter.HandleFunc("/groups/events", we.wrapFunc(we.bbsAPIHandler.GetGroupsEvents, we.auth2.bbs.Permissions)).Methods("GET")

log.Fatal(http.ListenAndServe(":"+we.port, router))
}
Expand Down
3 changes: 2 additions & 1 deletion driver/web/authorization_bbs_permission_policy.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
p, all_bbs_groups, /gr/api/bbs/*, (GET)|(POST)|(PUT)|(DELETE), All BBs APIs

p, get_aggregated-users, /gr/api/bbs/event/*/aggregated-users, (GET), Get event group users (aggregated)
p, get_user_membership, /gr/api/bbs/groups/*/memberships, (GET), Gets all related group memberships status and group title using userID
p, get_user_membership, /gr/api/bbs/groups/*/memberships, (GET), Gets all related group memberships status and group title using userID
p, get_groups_events, /gr/api/bbs/groups/events*, (GET), Gets all related eventID and groupID using eventIDs
28 changes: 28 additions & 0 deletions driver/web/rest/bbapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"groups/core"
"groups/core/model"
"net/http"
"strings"

"github.com/gorilla/mux"
"github.com/rokwire/logging-library-go/v2/logs"
Expand Down Expand Up @@ -78,3 +79,30 @@ func (h *BBSApisHandler) GetGroupMemberships(log *logs.Log, req *http.Request, u
return log.HTTPResponseSuccessJSON(data)

}

// GetGroupsEvents Gets all related eventID and groupID using eventIDs
// @Description Gets all related eventID and groupID using eventIDs
// @ID GetGroupsEvents
// @Tags BBS
// @Param comma separated eventIDs query
// @Success 200 {array} []model.GetGroupsEvents
// @Security AppUserAuth
// @Router /api/bbs/groups/events [get]
func (h *BBSApisHandler) GetGroupsEvents(log *logs.Log, req *http.Request, user *model.User) logs.HTTPResponse {
var eventsIDs []string
eventsArg := req.URL.Query().Get("events-ids")
if eventsArg != "" {
eventsIDs = strings.Split(eventsArg, ",")
}

groupevents, err := h.app.Services.GetGroupsEvents(eventsIDs)
if err != nil {
return log.HTTPResponseErrorAction(logutils.ActionGet, logutils.TypeError, nil, err, http.StatusBadRequest, false)
}
data, err := json.Marshal(groupevents)
if err != nil {
return log.HTTPResponseErrorAction(logutils.ActionGet, logutils.TypeError, nil, err, http.StatusBadRequest, false)
}

return log.HTTPResponseSuccessJSON(data)
}
Loading