Skip to content

Commit

Permalink
merge changes from rokwire-develop (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
roberlander2 authored Oct 30, 2024
1 parent 6e46d98 commit 12afee1
Show file tree
Hide file tree
Showing 27 changed files with 1,325 additions and 331 deletions.
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Add CORS support

## [1.53.0] - 2024-10-22
### Added
- FERPA issues for group memberships [#513](https://github.com/rokwire/groups-building-block/issues/513)

## [1.52.0] - 2024-09-11
### Fixed
- New Event notifications are not sent to Group members [#506](https://github.com/rokwire/groups-building-block/issues/506)

## [1.51.1] - 2024-09-04
### Fixed
- Bad Authman sync for user who has alternative auth method for first login [#509](https://github.com/rokwire/groups-building-block/issues/509)

## [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)

## [1.49.0] - 2024-08-19
### Fixed
- Fix Aggregation pipeline [#497](https://github.com/rokwire/groups-building-block/issues/497)
### Added
- BBs Api for getting group memberships [#494](https://github.com/rokwire/groups-building-block/issues/494)

## [1.48.0] - 2024-08-09
### Added
- Approve all API [#484](https://github.com/rokwire/groups-building-block/issues/484)
### Fixed
- Fix Groups Stats are not updated [#490](https://github.com/rokwire/groups-building-block/issues/490)

## [1.47.0] - 2024-08-08
### Fixed
- The value for "current_member" is not available in group json [#485](https://github.com/rokwire/groups-building-block/issues/485)
- Groups Stats are not updated [#483](https://github.com/rokwire/groups-building-block/issues/483)
### Added
- POST request for loading group members [#455](https://github.com/rokwire/groups-building-block/issues/455)

## [1.46.3] - 2024-07-24
### Fixed
- Use "get_groups" permission for loading user groups in the admin API [#481](https://github.com/rokwire/groups-building-block/issues/481)
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.20.0 | :white_check_mark: |
| <1.20.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/admin_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ func (app *Application) adminAddGroupMemberships(clientID string, current *model
}
}
if len(memberships) > 0 {
return app.storage.CreateMemberships(context, clientID, current, group, memberships)
err := app.storage.CreateMemberships(context, clientID, current, group, memberships)
if err != nil {
return err
}
}
}

return app.storage.UpdateGroupStats(context, clientID, groupID, true, true, false, true)
}

return nil
Expand All @@ -81,7 +86,7 @@ func (app *Application) adminDeleteMembershipsByID(clientID string, current *mod
}
}

return nil
return app.storage.UpdateGroupStats(context, clientID, groupID, true, true, false, true)
})

return err
Expand Down
184 changes: 0 additions & 184 deletions core/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,190 +125,6 @@ func (app *Application) startScheduledPostTask() {
log.Printf("successful running of post scheduling task")
}

func (app *Application) createCalendarEventForGroups(clientID string, adminIdentifiers []model.AccountIdentifiers, current *model.User, event map[string]interface{}, groupIDs []string) (map[string]interface{}, []string, error) {
memberships, err := app.findGroupMemberships(clientID, model.MembershipFilter{
GroupIDs: groupIDs,
UserID: &current.ID,
Statuses: []string{"admin"},
})
if err != nil {
return nil, nil, err
}

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)
if err != nil {
return nil, nil, err
}

if createdEvent != nil {
var mappedGroupIDs []string
eventID := createdEvent["id"].(string)

for _, membership := range memberships.Items {
mapping, err := app.storage.CreateEvent(clientID, eventID, membership.GroupID, nil, &model.Creator{
UserID: current.ID,
Name: current.Name,
Email: current.Email,
})
if err != nil {
log.Printf("Error create goup mapping: %s", err)
}
if mapping != nil {
mappedGroupIDs = append(mappedGroupIDs, mapping.GroupID)
}
}
return createdEvent, mappedGroupIDs, nil
}
}

return nil, nil, nil
}

func (app *Application) createCalendarEventForGroupsMembers(clientID string, orgID string, appID string, eventID string, groupIDs []string, members []model.ToMember) error {
for _, groupID := range groupIDs {

var userIDs []string
memberships, err := app.findGroupMemberships(clientID, model.MembershipFilter{
GroupIDs: []string{groupID},
Statuses: []string{"admin", "member"},
})
if err != nil {
return err
}

for _, membership := range memberships.Items {
if len(members) > 0 {
for _, toMember := range members {
if toMember.UserID == membership.UserID {
userIDs = append(userIDs, membership.UserID)
break
}
}
} else {
userIDs = append(userIDs, membership.UserID)
}
}
err = app.calendar.AddPeopleToCalendarEvent(userIDs, eventID, orgID, appID)
if err != nil {
return err
}
}

return nil
}

func (app *Application) createCalendarEventSingleGroup(clientID string, current *model.User, event map[string]interface{}, groupID string, members []model.ToMember) (map[string]interface{}, []model.ToMember, error) {
memberships, err := app.findGroupMemberships(clientID, model.MembershipFilter{
GroupIDs: []string{groupID},
UserID: &current.ID,
Statuses: []string{"admin"},
})
if err != nil {
return nil, nil, err
}

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)
if err != nil {
return nil, nil, err
}

if createdEvent != nil {
var mappedGroupIDs []string
eventID := createdEvent["id"].(string)

mapping, err := app.storage.CreateEvent(clientID, eventID, groupID, members, &model.Creator{
UserID: current.ID,
Name: current.Name,
Email: current.Email,
})
if err != nil {
log.Printf("Error create goup mapping: %s", err)
}
if mapping != nil {
mappedGroupIDs = append(mappedGroupIDs, mapping.GroupID)
}

return createdEvent, members, nil
}
}

return nil, nil, nil
}

func (app *Application) updateCalendarEventSingleGroup(clientID string, current *model.User, event map[string]interface{}, groupID string, members []model.ToMember) (map[string]interface{}, []model.ToMember, error) {
memberships, err := app.findGroupMemberships(clientID, model.MembershipFilter{
GroupIDs: []string{groupID},
UserID: &current.ID,
Statuses: []string{"admin"},
})
if err != nil {
return nil, nil, err
}

if len(memberships.Items) > 0 {
var groupIDs []string
for _, membership := range memberships.Items {
groupIDs = append(groupIDs, membership.GroupID)
}

eventID := event["id"].(string)
currentAccount := model.AccountIdentifiers{AccountID: &current.ID, ExternalID: &current.NetID}
createdEvent, err := app.calendar.UpdateCalendarEvent(currentAccount, eventID, event, current.OrgID, current.AppID)
if err != nil {
return nil, nil, err
}

if createdEvent != nil {
var mappedGroupIDs []string
eventID := createdEvent["id"].(string)

err := app.storage.UpdateEvent(clientID, eventID, groupID, members)
if err != nil {
return nil, nil, err
}

for _, groupID := range groupIDs {
mapping, err := app.storage.CreateEvent(clientID, eventID, groupID, members, &model.Creator{
UserID: current.ID,
Name: current.Name,
Email: current.Email,
})
if err != nil {
log.Printf("app.updateCalendarEventSingleGroup() Error create goup mapping: %s", err)
}
if mapping != nil {
mappedGroupIDs = append(mappedGroupIDs, mapping.GroupID)
}
}
return createdEvent, members, nil
}
}

return nil, nil, nil
}

func (app *Application) getGroupCalendarEvents(clientID string, current *model.User, groupID string, published *bool, filter model.GroupEventFilter) (map[string]interface{}, error) {
mappings, err := app.storage.FindEvents(clientID, current, groupID, true)
if err != nil {
return nil, err
}

if len(mappings) > 0 {
var eventIDs []string
for _, eventMapping := range mappings {
eventIDs = append(eventIDs, eventMapping.EventID)
}
currentAccount := model.AccountIdentifiers{AccountID: &current.ID, ExternalID: &current.NetID}
return app.calendar.GetGroupCalendarEvents(currentAccount, eventIDs, current.AppID, current.OrgID, published, filter)
}

return nil, err
}

// NewApplication creates new Application
func NewApplication(version string, build string, storage Storage, notifications Notifications, authman Authman, core *corebb.Adapter,
rewards *rewards.Adapter, calendar *calendar.Adapter, serviceID string, logger *logs.Logger, config *model.ApplicationConfig) *Application {
Expand Down
27 changes: 23 additions & 4 deletions core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ type Services interface {

ApplyMembershipApproval(clientID string, current *model.User, membershipID string, approve bool, rejectReason string) error
UpdateMembership(clientID string, current *model.User, membershipID string, status *string, dateAttended *time.Time, notificationsPreferences *model.NotificationsPreferences) error
UpdateMemberships(clientID string, user *model.User, group *model.Group, operation model.MembershipMultiUpdate) error

GetEvents(clientID string, current *model.User, groupID string, filterByToMembers bool) ([]model.Event, error)
CreateEvent(clientID string, current *model.User, eventID string, group *model.Group, toMemberList []model.ToMember, creator *model.Creator) (*model.Event, error)
UpdateEvent(clientID string, current *model.User, eventID string, groupID string, toMemberList []model.ToMember) error
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 @@ -181,6 +184,10 @@ func (s *servicesImpl) UpdateMembership(clientID string, current *model.User, me
return s.app.updateMembership(clientID, current, membershipID, status, dateAttended, notificationsPreferences)
}

func (s *servicesImpl) UpdateMemberships(clientID string, user *model.User, group *model.Group, operation model.MembershipMultiUpdate) error {
return s.app.updateMemberships(clientID, user, group, operation)
}

func (s *servicesImpl) GetEvents(clientID string, current *model.User, groupID string, filterByToMembers bool) ([]model.Event, error) {
return s.app.getEvents(clientID, current, groupID, filterByToMembers)
}
Expand All @@ -201,6 +208,14 @@ func (s *servicesImpl) GetEventUserIDs(eventID string) ([]string, error) {
return s.app.findEventUserIDs(eventID)
}

func (s *servicesImpl) GetGroupMembershipsStatusAndGroupTitle(userID string) ([]model.GetGroupMembershipsResponse, error) {
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 @@ -276,7 +291,7 @@ func (s *servicesImpl) FindGroupsV3(clientID string, filter model.GroupsFilter)
}

func (s *servicesImpl) FindGroupMemberships(clientID string, filter model.MembershipFilter) (model.MembershipCollection, error) {
return s.app.findGroupMemberships(clientID, filter)
return s.app.findGroupMemberships(nil, clientID, filter)
}

func (s *servicesImpl) FindGroupMembership(clientID string, groupID string, userID string) (*model.GroupMembership, error) {
Expand Down Expand Up @@ -409,12 +424,14 @@ type Storage interface {
DeleteUsersByAccountsIDs(log *logs.Logger, context storage.TransactionContext, accountsIDs []string) error

FindEvents(clientID string, current *model.User, groupID string, filterByToMembers bool) ([]model.Event, error)
CreateEvent(clientID string, eventID string, groupID string, toMemberList []model.ToMember, creator *model.Creator) (*model.Event, error)
CreateEvent(context storage.TransactionContext, clientID string, eventID string, groupID string, toMemberList []model.ToMember, creator *model.Creator) (*model.Event, error)
UpdateEvent(clientID string, eventID string, groupID string, toMemberList []model.ToMember) error
DeleteEvent(clientID string, eventID string, groupID string) error
PullMembersFromEventsByUserIDs(log *logs.Logger, context storage.TransactionContext, accountsIDs []string) error

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 @@ -444,7 +461,7 @@ type Storage interface {
DeleteManagedGroupConfig(id string, clientID string) error

// V3
FindGroupsV3(clientID string, filter model.GroupsFilter) ([]model.Group, error)
FindGroupsV3(context storage.TransactionContext, clientID string, filter model.GroupsFilter) ([]model.Group, error)
FindGroupMemberships(clientID string, filter model.MembershipFilter) (model.MembershipCollection, error)
FindGroupMembershipsWithContext(context storage.TransactionContext, clientID string, filter model.MembershipFilter) (model.MembershipCollection, error)

Expand All @@ -462,6 +479,7 @@ type Storage interface {
CreatePendingMembership(clientID string, current *model.User, group *model.Group, member *model.GroupMembership) error
ApplyMembershipApproval(clientID string, membershipID string, approve bool, rejectReason string) (*model.GroupMembership, error)
UpdateMembership(clientID string, _ *model.User, membershipID string, membership *model.GroupMembership) error
UpdateMemberships(clientID string, user *model.User, groupID string, operation model.MembershipMultiUpdate) error
DeleteMembership(clientID string, groupID string, userID string) error
DeleteMembershipByID(clientID string, current *model.User, membershipID string) error
DeleteUnsyncedGroupMemberships(clientID string, groupID string, syncID string) (int64, error)
Expand Down Expand Up @@ -516,6 +534,7 @@ type Core interface {
GetAllCoreAccountsWithExternalIDs(externalIDs []string, appID *string, orgID *string) ([]model.CoreAccount, error)
GetAccountsCount(searchParams map[string]interface{}, appID *string, orgID *string) (int64, error)
LoadDeletedMemberships() ([]model.DeletedUserData, error)
RetrieveFerpaAccounts(ids []string) ([]string, error)
}

// Rewards exposes Rewards internal APIs for giving rewards to the users
Expand All @@ -525,7 +544,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
Loading

0 comments on commit 12afee1

Please sign in to comment.