diff --git a/dao/address.go b/dao/address.go index eefb61b..61ca496 100644 --- a/dao/address.go +++ b/dao/address.go @@ -5,11 +5,10 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func AddressInsert(ctx context.Context, i *models.AddressCreate, token *vcapool.AccessToken) (result *models.Address, err error) { +func AddressInsert(ctx context.Context, i *models.AddressCreate, token *models.AccessToken) (result *models.Address, err error) { result = i.Address(token.ID) if err = AddressesCollection.InsertOne(ctx, result); err != nil { return @@ -17,7 +16,7 @@ func AddressInsert(ctx context.Context, i *models.AddressCreate, token *vcapool. return } -func UsersAddressInsert(ctx context.Context, i *models.UsersAddressCreate, token *vcapool.AccessToken) (result *models.Address, err error) { +func UsersAddressInsert(ctx context.Context, i *models.UsersAddressCreate, token *models.AccessToken) (result *models.Address, err error) { if err = models.AddressPermission(token); err != nil { return } @@ -28,7 +27,7 @@ func UsersAddressInsert(ctx context.Context, i *models.UsersAddressCreate, token return } -func AddressGet(ctx context.Context, i *models.AddressQuery, token *vcapool.AccessToken) (result *[]models.Address, err error) { +func AddressGet(ctx context.Context, i *models.AddressQuery, token *models.AccessToken) (result *[]models.Address, err error) { filter := i.PermittedFilter(token) result = new([]models.Address) if err = AddressesCollection.Find(ctx, filter, result); err != nil { @@ -37,7 +36,7 @@ func AddressGet(ctx context.Context, i *models.AddressQuery, token *vcapool.Acce return } -func AddressGetByID(ctx context.Context, i *models.AddressParam, token *vcapool.AccessToken) (result *models.Address, err error) { +func AddressGetByID(ctx context.Context, i *models.AddressParam, token *models.AccessToken) (result *models.Address, err error) { filter := i.PermittedFilter(token) if err = AddressesCollection.FindOne(ctx, filter, &result); err != nil { return @@ -45,7 +44,7 @@ func AddressGetByID(ctx context.Context, i *models.AddressParam, token *vcapool. return } -func UsersAddressUpdate(ctx context.Context, i *models.AddressUpdate, token *vcapool.AccessToken) (result *models.Address, err error) { +func UsersAddressUpdate(ctx context.Context, i *models.AddressUpdate, token *models.AccessToken) (result *models.Address, err error) { if err = models.AddressPermission(token); err != nil { return @@ -56,7 +55,7 @@ func UsersAddressUpdate(ctx context.Context, i *models.AddressUpdate, token *vca return } -func AddressUpdate(ctx context.Context, i *models.AddressUpdate, token *vcapool.AccessToken) (result *models.Address, err error) { +func AddressUpdate(ctx context.Context, i *models.AddressUpdate, token *models.AccessToken) (result *models.Address, err error) { filter := i.PermittedFilter(token) if err = AddressesCollection.UpdateOne(ctx, filter, vmdb.UpdateSet(i), &result); err != nil { return @@ -64,7 +63,7 @@ func AddressUpdate(ctx context.Context, i *models.AddressUpdate, token *vcapool. return } -func AddressDelete(ctx context.Context, i *models.AddressParam, token *vcapool.AccessToken) (result *models.NVM, err error) { +func AddressDelete(ctx context.Context, i *models.AddressParam, token *models.AccessToken) (result *models.NVM, err error) { filter := i.PermittedFilter(token) if err = AddressesCollection.DeleteOne(ctx, filter); err != nil { return @@ -75,7 +74,7 @@ func AddressDelete(ctx context.Context, i *models.AddressParam, token *vcapool.A return } -func UsersAddressDelete(ctx context.Context, i *models.AddressParam, token *vcapool.AccessToken) (result *models.NVM, err error) { +func UsersAddressDelete(ctx context.Context, i *models.AddressParam, token *models.AccessToken) (result *models.NVM, err error) { if err = models.AddressPermission(token); err != nil { return } diff --git a/dao/artist.go b/dao/artist.go index ae552ef..8d33cbe 100644 --- a/dao/artist.go +++ b/dao/artist.go @@ -5,10 +5,9 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" ) -func ArtistInsert(ctx context.Context, i *models.ArtistCreate, token *vcapool.AccessToken) (result *models.Artist, err error) { +func ArtistInsert(ctx context.Context, i *models.ArtistCreate, token *models.AccessToken) (result *models.Artist, err error) { if err = models.ArtistPermission(token); err != nil { return } @@ -36,7 +35,7 @@ func ArtistGetByID(ctx context.Context, i *models.ArtistParam) (result *models.A return } -func ArtistUpdate(ctx context.Context, i *models.ArtistUpdate, token *vcapool.AccessToken) (result *models.Artist, err error) { +func ArtistUpdate(ctx context.Context, i *models.ArtistUpdate, token *models.AccessToken) (result *models.Artist, err error) { if err = models.ArtistPermission(token); err != nil { return } @@ -47,7 +46,7 @@ func ArtistUpdate(ctx context.Context, i *models.ArtistUpdate, token *vcapool.Ac return } -func ArtistDelete(ctx context.Context, i *models.ArtistParam, token *vcapool.AccessToken) (err error) { +func ArtistDelete(ctx context.Context, i *models.ArtistParam, token *models.AccessToken) (err error) { if err = models.ArtistDeletePermission(token); err != nil { return } diff --git a/dao/connection.go b/dao/connection.go index 148400a..536cb42 100644 --- a/dao/connection.go +++ b/dao/connection.go @@ -40,12 +40,14 @@ var ( AvatarCollection *vmdb.Collection // PoolRoleCollection represents the database collection of the PoolRole Collection. - PoolRoleCollection *vmdb.Collection - PoolRoleHistoryCollection *vmdb.Collection + PoolRoleCollection *vmdb.Collection + PoolRoleHistoryCollection *vmdb.Collection + EventStateHistoryCollection *vmdb.Collection MailboxCollection *vmdb.Collection MessageCollection *vmdb.Collection + OrganisationCollection *vmdb.Collection ArtistCollection *vmdb.Collection ParticipationCollection *vmdb.Collection OrganizerCollection *vmdb.Collection @@ -63,6 +65,8 @@ var ( ReasonForPaymentCollection *vmdb.Collection UserViewCollection *vmdb.Collection + EventViewCollection *vmdb.Collection + PublicEventViewCollection *vmdb.Collection NewsletterCollection *vmdb.Collection @@ -70,13 +74,18 @@ var ( ParticipationEventPipe = vmdb.NewPipeline() ActitityUserPipe = vmdb.NewPipeline() UserPipe = vmdb.NewPipeline() + EventPipe = vmdb.NewPipeline() + PublicEventPipe = vmdb.NewPipeline() UpdateCollection *vmdb.Collection + Updates *vmdb.CollectionUpdate + ReceiptFileCollection *vmdb.Collection TestLogin bool ) func InitialDatabase() { Database = vmdb.NewDatabase("pool-backend").Connect() + Database.Database.Collection(models.CrewCollection).Indexes().DropAll(context.Background()) // UserCollection represents the database collection of the User model. UserCollection = Database.Collection(models.UserCollection).CreateIndex("email", true) @@ -94,7 +103,7 @@ func InitialDatabase() { AddressesCollection = Database.Collection(models.AddressesCollection).CreateIndex("user_id", true) // CrewsCollection represents the database collection of the Crew model. - CrewsCollection = Database.Collection(models.CrewCollection).CreateIndex("name", true) + CrewsCollection = Database.Collection(models.CrewCollection).CreateIndex("name", true).CreateIndex("organisation_id", false) // ProfileCollection represents the database collection of the Profile model. ProfileCollection = Database.Collection(models.ProfileCollection).CreateIndex("user_id", true) @@ -105,11 +114,13 @@ func InitialDatabase() { // PoolRoleCollection represents the database collection of the PoolRole Collection. PoolRoleCollection = Database.Collection(models.PoolRoleCollection).CreateIndex("user_id", false).CreateMultiIndex(bson.D{{Key: "name", Value: 1}, {Key: "user_id", Value: 1}}, true) PoolRoleHistoryCollection = Database.Collection(models.PoolRoleHistoryCollection).CreateIndex("user_id", false).CreateIndex("crew_id", false) + EventStateHistoryCollection = Database.Collection(models.EventStateHistoryCollection).CreateIndex("user_id", false).CreateIndex("crew_id", false).CreateIndex("event_id", false).CreateIndex("new_state", false).CreateIndex("date", false) // MailboxCollection = Database.Collection(models.MailboxCollection) MessageCollection = Database.Collection(models.MessageCollection).CreateIndex("user_id", false).CreateIndex("mailbox_id", false) + OrganisationCollection = Database.Collection(models.OrganisationCollection).CreateIndex("name", true).CreateIndex("abbreviation", true) ArtistCollection = Database.Collection(models.ArtistCollection).CreateIndex("name", true) ParticipationCollection = Database.Collection(models.ParticipationCollection).CreateIndex("user_id", false).CreateMultiIndex( bson.D{ @@ -119,9 +130,9 @@ func InitialDatabase() { OrganizerCollection = Database.Collection(models.OrganizerCollection).CreateIndex("name", true) EventCollection = Database.Collection(models.EventCollection) SourceCollection = Database.Collection(models.SourceCollection) - TakingCollection = Database.Collection(models.TakingCollection) + TakingCollection = Database.Collection(models.TakingCollection).CreateIndex("crew_id", false) DepositCollection = Database.Collection(models.DepositCollection) - DepositUnitCollection = Database.Collection(models.DepositUnitCollection).CreateMultiIndex(bson.D{{Key: "taking_id", Value: 1}, {Key: "deposit_id", Value: 1}}, true) + DepositUnitCollection = Database.Collection(models.DepositUnitCollection).CreateMultiIndex(bson.D{{Key: "taking_id", Value: 1}, {Key: "deposit_id", Value: 1}}, true).CreateIndex("taking_id", false).CreateIndex("deposit_id", false) FSChunkCollection = Database.Collection(models.FSChunkCollection) FSFilesCollection = Database.Collection(models.FSFilesCollection) @@ -148,6 +159,30 @@ func InitialDatabase() { ) UserViewCollection = Database.Collection(models.UserView) + PublicEventPipe.Lookup(models.ParticipationCollection, "_id", "event_id", "participations") + PublicEventPipe.LookupUnwind(models.OrganizerCollection, "organizer_id", "_id", "organizer") + PublicEventPipe.LookupList(models.ArtistCollection, "artist_ids", "_id", "artists") + PublicEventPipe.LookupUnwind(models.CrewCollection, "crew_id", "_id", "crew") + Database.Database.CreateView( + context.Background(), + models.PublicEventView, + models.EventCollection, + models.EventPipelinePublic().Pipe, + ) + PublicEventViewCollection = Database.Collection(models.PublicEventView) + + EventPipe.Lookup(models.ParticipationCollection, "_id", "event_id", "participations") + EventPipe.LookupUnwind(models.OrganizerCollection, "organizer_id", "_id", "organizer") + EventPipe.LookupList(models.ArtistCollection, "artist_ids", "_id", "artists") + EventPipe.LookupUnwind(models.CrewCollection, "crew_id", "_id", "crew") + Database.Database.CreateView( + context.Background(), + models.EventView, + models.EventCollection, + models.EventPipeline(&models.AccessToken{ID: ""}), + ) + EventViewCollection = Database.Collection(models.EventView) + DepositUnitTakingPipe.LookupUnwind(models.DepositCollection, "deposit_id", "_id", "deposit") Database.Database.CreateView( context.Background(), @@ -171,6 +206,14 @@ func InitialDatabase() { ActitityUserPipe.Pipe, ) UpdateCollection = Database.Collection("updates").CreateIndex("name", true) + Updates = vmdb.NewCollectionUpdate(UpdateCollection) + ReceiptFileCollection = Database.Collection(models.ReceiptFileCollection).CreateIndex("deposit_id", false) + Database.Database.CreateView( + context.Background(), + models.TakingDepositView, + models.TakingCollection, + models.TakingPipelineDeposit().Pipe, + ) } func FixDatabase() { diff --git a/dao/crew.go b/dao/crew.go index a65b8f4..4430781 100644 --- a/dao/crew.go +++ b/dao/crew.go @@ -7,11 +7,11 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo/options" ) -func CrewInsert(ctx context.Context, i *models.CrewCreate, token *vcapool.AccessToken) (result *models.Crew, err error) { +func CrewInsert(ctx context.Context, i *models.CrewCreate, token *models.AccessToken) (result *models.Crew, err error) { if err = models.CrewPermission(token); err != nil { return @@ -32,19 +32,22 @@ func CrewInsert(ctx context.Context, i *models.CrewCreate, token *vcapool.Access return } -func CrewGet(ctx context.Context, i *models.CrewQuery, token *vcapool.AccessToken) (result *[]models.Crew, err error) { +func CrewGet(ctx context.Context, i *models.CrewQuery, token *models.AccessToken) (result *[]models.Crew, err error) { if err = models.CrewPermission(token); err != nil { return } filter := i.Filter() result = new([]models.Crew) - if err = CrewsCollection.Find(ctx, filter, result); err != nil { + opt := options.Find().SetSort(bson.D{{Key: "name", Value: 1}}) + opt.Collation = &options.Collation{Locale: "en", Strength: 2} + + if err = CrewsCollection.Aggregate(ctx, models.CrewPipeline().Match(filter).Pipe, result); err != nil { return } return } -func CrewGetByID(ctx context.Context, i *models.CrewParam, token *vcapool.AccessToken) (result *models.Crew, err error) { +func CrewGetByID(ctx context.Context, i *models.CrewParam, token *models.AccessToken) (result *models.Crew, err error) { filter := i.PermittedFilter(token) if err = CrewsCollection.FindOne(ctx, filter, &result); err != nil { return @@ -61,7 +64,7 @@ func CrewPublicGet(ctx context.Context, i *models.CrewQuery) (result *[]models.C return } -func CrewGetAsMember(ctx context.Context, i *models.CrewQuery, token *vcapool.AccessToken) (result *models.Crew, err error) { +func CrewGetAsMember(ctx context.Context, i *models.CrewQuery, token *models.AccessToken) (result *models.Crew, err error) { filter := i.PermittedFilter(token) if err = CrewsCollection.FindOne(ctx, filter, &result); err != nil { return @@ -69,7 +72,7 @@ func CrewGetAsMember(ctx context.Context, i *models.CrewQuery, token *vcapool.Ac return } -func CrewUpdate(ctx context.Context, i *models.CrewUpdate, token *vcapool.AccessToken) (result *models.Crew, err error) { +func CrewUpdate(ctx context.Context, i *models.CrewUpdate, token *models.AccessToken) (result *models.Crew, err error) { if err = models.CrewUpdatePermission(token); err != nil { return } @@ -88,7 +91,7 @@ func CrewUpdate(ctx context.Context, i *models.CrewUpdate, token *vcapool.Access if crew.AspSelection == "selected" && match < len(strings) && strings[match] == i.AspSelection { RoleHistoryDelete(ctx, &models.RoleHistoryRequest{CrewID: i.ID, Confirmed: false}, token) } - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { if err = CrewsCollection.UpdateOne(ctx, filter, vmdb.UpdateSet(i.ToCrewUpdateASP()), &result); err != nil { return } @@ -97,18 +100,17 @@ func CrewUpdate(ctx context.Context, i *models.CrewUpdate, token *vcapool.Access return } } - if crew.Email != i.Email || crew.Name != i.Name { + if crew.Email != i.Email || crew.Name != i.Name || crew.OrganisationID != i.OrganisationID { filter := bson.D{{Key: "crew_id", Value: i.ID}} - update := bson.D{{Key: "email", Value: i.Email}, {Key: "name", Value: i.Name}} + update := bson.D{{Key: "email", Value: i.Email}, {Key: "name", Value: i.Name}, {Key: "organisation_id", Value: i.OrganisationID}} if err = UserCrewCollection.UpdateMany(ctx, filter, vmdb.UpdateSet(update)); err != nil { return } - } return } -func CrewUpdateAspSelection(ctx context.Context, i *models.CrewParam, value string, token *vcapool.AccessToken) (result *models.Crew, err error) { +func CrewUpdateAspSelection(ctx context.Context, i *models.CrewParam, value string, token *models.AccessToken) (result *models.Crew, err error) { if err = models.CrewUpdatePermission(token); err != nil { return } @@ -124,7 +126,7 @@ func CrewUpdateAspSelection(ctx context.Context, i *models.CrewParam, value stri return } -func CrewDelete(ctx context.Context, i *models.CrewParam, token *vcapool.AccessToken) (err error) { +func CrewDelete(ctx context.Context, i *models.CrewParam, token *models.AccessToken) (err error) { if err = models.CrewPermission(token); err != nil { return } diff --git a/dao/defaults.go b/dao/defaults.go index ec37997..c8770a2 100644 --- a/dao/defaults.go +++ b/dao/defaults.go @@ -1,8 +1,9 @@ package dao import ( + "pool-backend/models" + "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" ) type Check struct { @@ -17,7 +18,7 @@ func (i *Check) Return() error { return i.Error } -func (i *Check) ASP(token *vcapool.AccessToken) *Check { +func (i *Check) ASP(token *models.AccessToken) *Check { if !token.PoolRoles.Validate("finance;network;education;") { i.Error = vcago.NewPermissionDenied("permission_denied", nil) } diff --git a/dao/deposit.go b/dao/deposit.go index 4f97bc8..3c2889d 100644 --- a/dao/deposit.go +++ b/dao/deposit.go @@ -8,11 +8,10 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func validateDepositUnits(ctx context.Context, takingID string, amount int64, crewID string, token *vcapool.AccessToken) (err error) { +func validateDepositUnits(ctx context.Context, takingID string, amount int64, crewID string, token *models.AccessToken) (err error) { taking := new(models.Taking) takingPipeline := models.TakingPipeline() if err = TakingCollection.AggregateOne( @@ -25,13 +24,13 @@ func validateDepositUnits(ctx context.Context, takingID string, amount int64, cr if amount > taking.Money.Amount { return vcago.NewBadRequest(models.DepositCollection, "taking_amount_failure", nil) } - if (!token.Roles.Validate("admin;employee") && crewID != token.CrewID) || taking.CrewID != crewID { + if (!token.Roles.Validate("admin;employee;pool_employee") && crewID != token.CrewID) || taking.CrewID != crewID { return vcago.NewBadRequest(models.DepositCollection, "taking_crew_failure", nil) } return } -func DepositInsert(ctx context.Context, i *models.DepositCreate, token *vcapool.AccessToken) (result *models.Deposit, err error) { +func DepositInsert(ctx context.Context, i *models.DepositCreate, token *models.AccessToken) (result *models.Deposit, err error) { if err = models.DepositPermission(token); err != nil { return } @@ -60,7 +59,7 @@ func DepositInsert(ctx context.Context, i *models.DepositCreate, token *vcapool. return } -func DepositUpdate(ctx context.Context, i *models.DepositUpdate, token *vcapool.AccessToken) (result *models.Deposit, err error) { +func DepositUpdate(ctx context.Context, i *models.DepositUpdate, token *models.AccessToken) (result *models.Deposit, err error) { if err = models.DepositPermission(token); err != nil { return } @@ -74,7 +73,7 @@ func DepositUpdate(ctx context.Context, i *models.DepositUpdate, token *vcapool. return } i.Money = deposit.Money - if deposit.Status == "confirmed" && !token.Roles.Validate("admin;employee") { + if deposit.Status == "confirmed" && !token.Roles.Validate("admin;employee;pool_employee") { return nil, vcago.NewBadRequest("deposit", "deposit_confirmed_failure", nil) } depositUpdate, depositUnitCreate, depositUnitUpdate, depositUnitDelete := i.DepositDatabase(deposit) @@ -182,7 +181,7 @@ func DepositUpdate(ctx context.Context, i *models.DepositUpdate, token *vcapool. return } -func DepositSync(ctx context.Context, i *models.DepositParam, token *vcapool.AccessToken) (result *models.Deposit, err error) { +func DepositSync(ctx context.Context, i *models.DepositParam, token *models.AccessToken) (result *models.Deposit, err error) { filter := bson.D{{Key: "_id", Value: i.ID}} if err = DepositCollection.AggregateOne( @@ -260,7 +259,7 @@ func DepositSync(ctx context.Context, i *models.DepositParam, token *vcapool.Acc return } -func DepositGet(ctx context.Context, i *models.DepositQuery, token *vcapool.AccessToken) (result *[]models.Deposit, err error) { +func DepositGet(ctx context.Context, i *models.DepositQuery, token *models.AccessToken) (result *[]models.Deposit, err error) { if err = models.DepositPermission(token); err != nil { return } @@ -277,7 +276,7 @@ func DepositGet(ctx context.Context, i *models.DepositQuery, token *vcapool.Acce return } -func DepositGetByID(ctx context.Context, i *models.DepositParam, token *vcapool.AccessToken) (result *models.Deposit, err error) { +func DepositGetByID(ctx context.Context, i *models.DepositParam, token *models.AccessToken) (result *models.Deposit, err error) { if err = models.DepositPermission(token); err != nil { return } diff --git a/dao/event.go b/dao/event.go index 28b5189..89bdbcb 100644 --- a/dao/event.go +++ b/dao/event.go @@ -3,19 +3,27 @@ package dao import ( "context" "pool-backend/models" + "time" "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" + "github.com/Viva-con-Agua/vcago/vmod" "github.com/labstack/gommon/log" "go.mongodb.org/mongo-driver/bson" ) -func EventInsert(ctx context.Context, i *models.EventCreate, token *vcapool.AccessToken) (result *models.Event, err error) { +func EventInsert(ctx context.Context, i *models.EventCreate, token *models.AccessToken) (result *models.Event, err error) { if err = models.EventPermission(token); err != nil { return } event := i.EventDatabase(token) + if !token.Roles.Validate("admin;employee;pool_employee") { + crew := new(models.Crew) + if crew, err = CrewGetByID(ctx, &models.CrewParam{ID: i.CrewID}, token); err != nil { + return + } + event.OrganisationID = crew.OrganisationID + } taking := event.TakingDatabase() event.TakingID = taking.ID if err = EventCollection.InsertOne(ctx, event); err != nil { @@ -36,19 +44,36 @@ func EventInsert(ctx context.Context, i *models.EventCreate, token *vcapool.Acce if err = EventCollection.AggregateOne(ctx, models.EventPipeline(token).Match(filter).Pipe, &result); err != nil { return } + history := result.NewEventStateHistory("", result.EventState.State, token) + if err = EventStateHistoryInsert(ctx, history, token); err != nil { + return + } return } -func EventGet(ctx context.Context, i *models.EventQuery, token *vcapool.AccessToken) (result *[]models.ListEvent, err error) { +func EventGet(i *models.EventQuery, token *models.AccessToken) (result *[]models.ListEvent, list_size int64, err error) { + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() filter := i.PermittedFilter(token) + sort := i.Sort() + pipeline := models.EventPipeline(token).SortFields(sort).Match(filter).Sort(sort).Skip(i.Skip, 0).Limit(i.Limit, 100).Pipe result = new([]models.ListEvent) - if err = EventCollection.Aggregate(ctx, models.EventPipeline(token).Match(filter).Pipe, result); err != nil { + if err = EventCollection.Aggregate(ctx, pipeline, result); err != nil { return } + + count := vmod.Count{} + var cErr error + if cErr = EventCollection.AggregateOne(ctx, models.EventPipeline(token).Match(filter).Count().Pipe, &count); cErr != nil { + list_size = 1 + } else { + list_size = int64(count.Total) + } return } -func EventGetByID(ctx context.Context, i *models.EventParam, token *vcapool.AccessToken) (result *models.Event, err error) { +func EventGetByID(ctx context.Context, i *models.EventParam, token *models.AccessToken) (result *models.Event, err error) { filter := i.PermittedFilter(token) if err = EventCollection.AggregateOne( ctx, @@ -60,7 +85,19 @@ func EventGetByID(ctx context.Context, i *models.EventParam, token *vcapool.Acce return } -func EventAspGetByID(ctx context.Context, i *models.EventParam, token *vcapool.AccessToken) (result *models.Event, err error) { +func EventGetInternalByID(ctx context.Context, i *models.EventParam) (result *models.Event, err error) { + filter := i.FilterID() + if err = EventCollection.AggregateOne( + ctx, + models.EventPipelinePublic().Match(filter).Pipe, + &result, + ); err != nil { + return + } + return +} + +func EventAspGetByID(ctx context.Context, i *models.EventParam, token *models.AccessToken) (result *models.Event, err error) { filter := i.PermittedFilter(token) if err = EventCollection.AggregateOne( ctx, @@ -84,16 +121,30 @@ func EventViewGetByID(ctx context.Context, i *models.EventParam) (result *models return } -func EventGetPublic(ctx context.Context, i *models.EventQuery) (result *[]models.EventPublic, err error) { +func EventGetPublic(i *models.EventQuery) (result *[]models.EventPublic, list_size int64, err error) { + + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() filter := i.PublicFilter() + sort := i.Sort() + pipeline := models.EventPipelinePublic().SortFields(sort).Match(filter).Sort(sort).Skip(i.Skip, 0).Limit(i.Limit, 100).Pipe result = new([]models.EventPublic) - if err = EventCollection.Aggregate(ctx, models.EventPipelinePublic().Match(filter).Pipe, result); err != nil { + if err = EventCollection.Aggregate(ctx, pipeline, result); err != nil { return } + + count := vmod.Count{} + var cErr error + if cErr = EventCollection.AggregateOne(ctx, models.EventPipelinePublic().Match(filter).Count().Pipe, &count); cErr != nil { + print(cErr) + list_size = 1 + } else { + list_size = int64(count.Total) + } return } -func EventsGetReceiverEvents(ctx context.Context, i *models.EventQuery, token *vcapool.AccessToken) (result *[]models.EventPublic, err error) { +func EventsGetReceiverEvents(ctx context.Context, i *models.EventQuery, token *models.AccessToken) (result *[]models.EventPublic, err error) { filter := i.FilterEmailEvents(token) result = new([]models.EventPublic) if err = EventCollection.Aggregate(ctx, models.EventPipelinePublic().Match(filter).Pipe, result); err != nil { @@ -102,7 +153,7 @@ func EventsGetReceiverEvents(ctx context.Context, i *models.EventQuery, token *v return } -func EventGetAps(ctx context.Context, i *models.EventQuery, token *vcapool.AccessToken) (result *[]models.ListDetailsEvent, err error) { +func EventGetAps(ctx context.Context, i *models.EventQuery, token *models.AccessToken) (result *[]models.ListDetailsEvent, err error) { filter := i.FilterAsp(token) result = new([]models.ListDetailsEvent) if err = EventCollection.Aggregate(ctx, models.EventPipeline(token).Match(filter).Pipe, result); err != nil { @@ -112,13 +163,20 @@ func EventGetAps(ctx context.Context, i *models.EventQuery, token *vcapool.Acces return } -func EventUpdate(ctx context.Context, i *models.EventUpdate, token *vcapool.AccessToken) (result *models.Event, err error) { +func EventUpdate(ctx context.Context, i *models.EventUpdate, token *models.AccessToken) (result *models.Event, err error) { event := new(models.EventValidate) filter := i.PermittedFilter(token) if err = EventCollection.AggregateOne(ctx, models.EventPipelinePublic().Match(filter).Pipe, event); err != nil { return } + if !token.Roles.Validate("admin;employee;pool_employee") { + crew := new(models.Crew) + if crew, err = CrewGetByID(ctx, &models.CrewParam{ID: token.CrewID}, token); err != nil { + return + } + i.OrganisationID = crew.OrganisationID + } taking := new(models.Taking) if taking, err = TakingGetByIDSystem(ctx, event.TakingID); err != nil { if !vmdb.ErrNoDocuments(err) { @@ -139,6 +197,10 @@ func EventUpdate(ctx context.Context, i *models.EventUpdate, token *vcapool.Acce return } if event.EventState.State != result.EventState.State { + history := result.NewEventStateHistory(event.EventState.State, result.EventState.State, token) + if err = EventStateHistoryInsert(ctx, history, token); err != nil { + return + } if result.EventState.State == "canceled" { EventParticipantsNotification(ctx, result, "event_cancel") updateTaking := bson.D{{Key: "state.no_income", Value: true}} @@ -150,7 +212,7 @@ func EventUpdate(ctx context.Context, i *models.EventUpdate, token *vcapool.Acce if result.EventState.State == "published" || result.EventState.State == "canceled" || (result.EventState.State == "requested" && result.EventState.CrewConfirmation == "") { - EventStateNotification(ctx, result, "event_state") + EventStateNotification(ctx, result) } } else if event.StartAt != result.StartAt || event.EndAt != result.EndAt || @@ -159,12 +221,33 @@ func EventUpdate(ctx context.Context, i *models.EventUpdate, token *vcapool.Acce EventParticipantsNotification(ctx, result, "event_update") } if event.EventASPID != result.EventASPID && result.EventASPID != token.ID { - EventASPNotification(ctx, result, "event_asp") + EventASPNotification(ctx, result) + } + if event.EndAt != i.EndAt { + updateTaking := bson.D{{Key: "date_of_taking", Value: i.EndAt}} + filterTaking := bson.D{{Key: "_id", Value: event.TakingID}} + if err = TakingCollection.UpdateOne(ctx, filterTaking, vmdb.UpdateSet(updateTaking), nil); err != nil { + return + } + } + return +} + +func EventApplicationsUpdate(ctx context.Context, i *models.EventApplicationsUpdate) (result *models.Event, err error) { + + filter := bson.D{{Key: "_id", Value: i.ID}} + if err = EventCollection.UpdateOne( + ctx, + filter, + vmdb.UpdateSet(i), + &result, + ); err != nil { + return } return } -func EventDelete(ctx context.Context, i *models.EventParam, token *vcapool.AccessToken) (err error) { +func EventDelete(ctx context.Context, i *models.EventParam, token *models.AccessToken) (err error) { if err = models.EventDeletePermission(token); err != nil { return } @@ -223,6 +306,13 @@ func EventImport(ctx context.Context, i *models.EventImport) (result *models.Eve return } event.EventASPID = aspRole.UserID + + crew := new(models.Crew) + if err = CrewsCollection.FindOne(ctx, bson.D{{Key: "_id", Value: event.CrewID}}, &crew); err != nil { + return + } + event.OrganisationID = crew.OrganisationID + } else { event.EventASPID = admin.ID } @@ -270,7 +360,7 @@ func EventImport(ctx context.Context, i *models.EventImport) (result *models.Eve return } -func EventSync(ctx context.Context, i *models.EventParam, token *vcapool.AccessToken) (result *models.Event, err error) { +func EventSync(ctx context.Context, i *models.EventParam, token *models.AccessToken) (result *models.Event, err error) { if err = EventCollection.AggregateOne(ctx, models.EventPipeline(token).Match(i.Match()).Pipe, &result); err != nil { return } @@ -309,7 +399,7 @@ func EventParticipantsNotification(ctx context.Context, i *models.Event, templat return } -func EventASPNotification(ctx context.Context, i *models.Event, template string) (err error) { +func EventASPNotification(ctx context.Context, i *models.Event) (err error) { if i.EventASPID == "" { return vcago.NewNotFound(models.EventCollection, i) @@ -320,6 +410,7 @@ func EventASPNotification(ctx context.Context, i *models.Event, template string) return } + template := "event_asp" mail := vcago.NewMailData(user.Email, "pool-backend", template, "pool", user.Country) mail.AddUser(user.User()) mail.AddContent(i.ToContent()) @@ -332,7 +423,7 @@ func EventASPNotification(ctx context.Context, i *models.Event, template string) return } -func EventStateNotification(ctx context.Context, i *models.Event, template string) (err error) { +func EventStateNotification(ctx context.Context, i *models.Event) (err error) { if i.EventASPID == "" { return vcago.NewNotFound(models.EventCollection, i) @@ -343,6 +434,7 @@ func EventStateNotification(ctx context.Context, i *models.Event, template strin return } + template := "event_state" mail := vcago.NewMailData(eventAps.Email, "pool-backend", template, "pool", eventAps.Country) mail.AddUser(eventAps.User()) mail.AddContent(i.ToContent()) @@ -353,3 +445,23 @@ func EventStateNotification(ctx context.Context, i *models.Event, template strin //vcago.Nats.Publish("system.notification.job", notification) return } + +func EventHistoryAdminNotification(ctx context.Context, data []models.EventStateHistoryNotification) (err error) { + mail := vcago.NewMailData("netzwerk@vivaconagua.org", "pool-backend", "events_published", "pool", "de") + mail.AddContent(models.EventHistoryAdminContent(data)) + vcago.Nats.Publish("system.mail.job", mail) + + mail2 := vcago.NewMailData("festival@vivaconagua.org", "pool-backend", "events_published", "pool", "de") + mail2.AddContent(models.EventHistoryAdminContent(data)) + vcago.Nats.Publish("system.mail.job", mail2) + return +} + +func EventHistoryCrewNotification(ctx context.Context, data_collection map[string][]models.EventStateHistoryNotification) (err error) { + for email, data := range data_collection { + mail := vcago.NewMailData(email, "pool-backend", "events_crew_published", "pool", "de") + mail.AddContent(models.EventHistoryAdminContent(data)) + vcago.Nats.Publish("system.mail.job", mail) + } + return +} diff --git a/dao/event_history.go b/dao/event_history.go new file mode 100644 index 0000000..f1efd94 --- /dev/null +++ b/dao/event_history.go @@ -0,0 +1,36 @@ +package dao + +import ( + "context" + "pool-backend/models" + + "github.com/Viva-con-Agua/vcago/vmod" +) + +func EventStateHistoryInsert(ctx context.Context, i *models.EventStateHistoryCreate, token *models.AccessToken) (err error) { + if err = EventStateHistoryCollection.InsertOne(ctx, i); err != nil { + return + } + return +} + +func EventStateHistoryGet(ctx context.Context, i *models.EventStateHistoryQuery, token *models.AccessToken) (result *[]models.EventStateHistory, list_size int64, err error) { + result = new([]models.EventStateHistory) + pipeline := models.EventStatePipeline().Match(i.Filter()) + if err = EventStateHistoryCollection.Aggregate( + ctx, + pipeline.Pipe, + result, + ); err != nil { + return + } + count := vmod.Count{} + var cErr error + if cErr = EventStateHistoryCollection.AggregateOne(ctx, pipeline.Count().Pipe, &count); cErr != nil { + print(cErr) + list_size = 1 + } else { + list_size = int64(count.Total) + } + return +} diff --git a/dao/mailbox.go b/dao/mailbox.go index 43a29c5..efb18e7 100644 --- a/dao/mailbox.go +++ b/dao/mailbox.go @@ -3,11 +3,9 @@ package dao import ( "context" "pool-backend/models" - - "github.com/Viva-con-Agua/vcapool" ) -func MailboxGetByID(ctx context.Context, i *models.MailboxParam, token *vcapool.AccessToken) (result *models.Mailbox, err error) { +func MailboxGetByID(ctx context.Context, i *models.MailboxParam, token *models.AccessToken) (result *models.Mailbox, err error) { filter := i.PermittedFilter(token) if err = MailboxCollection.AggregateOne(ctx, models.MailboxPipeline(token).Match(filter).Pipe, &result); err != nil { return diff --git a/dao/message.go b/dao/message.go index f27112f..411a263 100644 --- a/dao/message.go +++ b/dao/message.go @@ -7,11 +7,10 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func MessageInsert(ctx context.Context, i *models.MessageCreate, token *vcapool.AccessToken) (result *models.Message, err error) { +func MessageInsert(ctx context.Context, i *models.MessageCreate, token *models.AccessToken) (result *models.Message, err error) { crew := new(models.Crew) CrewsCollection.FindOne(ctx, bson.D{{Key: "_id", Value: token.CrewID}}, crew) event := new(models.Event) @@ -26,7 +25,7 @@ func MessageInsert(ctx context.Context, i *models.MessageCreate, token *vcapool. return } -func MessageGetByID(ctx context.Context, i *models.MessageParam, token *vcapool.AccessToken) (result *models.Message, err error) { +func MessageGetByID(ctx context.Context, i *models.MessageParam, token *models.AccessToken) (result *models.Message, err error) { crew := new(models.Crew) if err = CrewsCollection.FindOne(ctx, bson.D{{Key: "_id", Value: token.CrewID}}, crew); err != nil { log.Print("No crew for user") @@ -38,7 +37,7 @@ func MessageGetByID(ctx context.Context, i *models.MessageParam, token *vcapool. return } -func MessageUpdate(ctx context.Context, i *models.MessageUpdate, token *vcapool.AccessToken) (result *models.Message, err error) { +func MessageUpdate(ctx context.Context, i *models.MessageUpdate, token *models.AccessToken) (result *models.Message, err error) { crew := new(models.Crew) if err = CrewsCollection.FindOne(ctx, bson.D{{Key: "_id", Value: token.CrewID}}, crew); err != nil { log.Print("No crew for user") @@ -55,7 +54,7 @@ func MessageUpdate(ctx context.Context, i *models.MessageUpdate, token *vcapool. return } -func MessageDelete(ctx context.Context, i *models.MessageParam, token *vcapool.AccessToken) (err error) { +func MessageDelete(ctx context.Context, i *models.MessageParam, token *models.AccessToken) (err error) { crew := new(models.Crew) if err = CrewsCollection.FindOne(ctx, bson.D{{Key: "_id", Value: token.CrewID}}, crew); err != nil { log.Print("No crew for user") @@ -67,7 +66,7 @@ func MessageDelete(ctx context.Context, i *models.MessageParam, token *vcapool.A return } -func MessageCrewUser(ctx context.Context, i *models.RecipientGroup, token *vcapool.AccessToken) (result []models.TOData, err error) { +func MessageCrewUser(ctx context.Context, i *models.RecipientGroup, token *models.AccessToken) (result []models.TOData, err error) { if err = models.MessageCrewPermission(token); err != nil { return } @@ -83,7 +82,7 @@ func MessageCrewUser(ctx context.Context, i *models.RecipientGroup, token *vcapo return } -func MessageEventUser(ctx context.Context, i *models.RecipientGroup, token *vcapool.AccessToken) (result []models.TOData, err error) { +func MessageEventUser(ctx context.Context, i *models.RecipientGroup, token *models.AccessToken) (result []models.TOData, err error) { event := new(models.Event) filter := i.FilterEvent() if err = EventCollection.FindOne(ctx, filter, event); err != nil { @@ -104,7 +103,7 @@ func MessageEventUser(ctx context.Context, i *models.RecipientGroup, token *vcap return } -func MessageSendCycular(ctx context.Context, i *models.MessageParam, token *vcapool.AccessToken) (result *models.Message, mail *vcago.CycularMail, err error) { +func MessageSendCycular(ctx context.Context, i *models.MessageParam, token *models.AccessToken) (result *models.Message, mail *vcago.CycularMail, err error) { // get message via filter by mailbox and message ids crew := new(models.Crew) if err = CrewsCollection.FindOne(ctx, bson.D{{Key: "_id", Value: token.CrewID}}, crew); err != nil { diff --git a/dao/nats.go b/dao/nats.go index 937bd09..f62bee9 100644 --- a/dao/nats.go +++ b/dao/nats.go @@ -19,6 +19,20 @@ func InitialNats() { vcago.Nats.Subscribe("system.notification.publish", SubscribeNotificationPublish) } +func PublishRoles() { + result := vmod.WebappAccess{ + Name: "pool", + Roles: []vmod.AccessRole{{ + Name: "pool_employee", + Root: []string{"employee", "pool_employee"}, + }, { + Name: "pool_finance", + Root: []string{"employee", "pool_employee", "pool_finance"}, + }}, + } + vcago.Nats.Publish("webapp_role.update", result) +} + func SubscribeUserUpdate(m *models.UserUpdate) { result := new(models.User) if err := UserCollection.UpdateOne( diff --git a/dao/newsletter.go b/dao/newsletter.go index f8f9ed5..613a8d3 100644 --- a/dao/newsletter.go +++ b/dao/newsletter.go @@ -6,13 +6,12 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func NewsletterCreate(ctx context.Context, i *models.NewsletterCreate, token *vcapool.AccessToken) (result *models.Newsletter, err error) { +func NewsletterCreate(ctx context.Context, i *models.NewsletterCreate, token *models.AccessToken) (result *models.Newsletter, err error) { - if !token.Roles.Validate("employee;admin") || i.UserID == "" { + if !token.Roles.Validate("admin;employee;pool_employee") || i.UserID == "" { if i.Value == "regional" && token.CrewID == "" { return nil, vcago.NewBadRequest(models.NewsletterCollection, "not part of an crew", nil) } @@ -36,7 +35,7 @@ func NewsletterCreate(ctx context.Context, i *models.NewsletterCreate, token *vc return } -func NewsletterDelete(ctx context.Context, i *models.NewsletterParam, token *vcapool.AccessToken) (result *models.Newsletter, err error) { +func NewsletterDelete(ctx context.Context, i *models.NewsletterParam, token *models.AccessToken) (result *models.Newsletter, err error) { filter := i.Match() if err = NewsletterCollection.FindOne(ctx, filter, &result); err != nil { return @@ -69,7 +68,7 @@ func NewsletterImport(ctx context.Context, i *models.NewsletterImport) (result * return } -func NewsletterSync(ctx context.Context, i *models.User, token *vcapool.AccessToken) (result *[]models.Newsletter, err error) { +func NewsletterSync(ctx context.Context, i *models.User, token *models.AccessToken) (result *[]models.Newsletter, err error) { export := &models.NewsletterExport{ UserID: i.ID, Newsletter: i.Newsletter, diff --git a/dao/organisation.go b/dao/organisation.go new file mode 100644 index 0000000..bd0d4f1 --- /dev/null +++ b/dao/organisation.go @@ -0,0 +1,59 @@ +package dao + +import ( + "context" + "pool-backend/models" + + "github.com/Viva-con-Agua/vcago/vmdb" +) + +func OrganisationInsert(ctx context.Context, i *models.OrganisationCreate, token *models.AccessToken) (result *models.Organisation, err error) { + if err = token.AccessPermission(); err != nil { + return + } + result = i.Organisation() + if err = OrganisationCollection.InsertOne(ctx, result); err != nil { + return + } + return +} + +func OrganisationGet(ctx context.Context, i *models.OrganisationQuery) (result *[]models.Organisation, err error) { + filter := i.Filter() + result = new([]models.Organisation) + + if err = OrganisationCollection.Aggregate(ctx, models.OrganisationPipeline().Match(filter).Pipe, result); err != nil { + return + } + return +} + +func OrganisationGetByID(ctx context.Context, i *models.OrganisationParam) (result *models.Organisation, err error) { + filter := i.Match() + if err = OrganisationCollection.FindOne(ctx, filter, &result); err != nil { + return + } + return +} + +func OrganisationUpdate(ctx context.Context, i *models.OrganisationUpdate, token *models.AccessToken) (result *models.Organisation, err error) { + if err = token.AccessPermission(); err != nil { + return + } + filter := i.Match() + if err = OrganisationCollection.UpdateOne(ctx, filter, vmdb.UpdateSet(i), &result); err != nil { + return + } + return +} + +func OrganisationDelete(ctx context.Context, i *models.OrganisationParam, token *models.AccessToken) (err error) { + if err = token.AccessPermission(); err != nil { + return + } + filter := i.Match() + if err = OrganisationCollection.DeleteOne(ctx, filter); err != nil { + return + } + return +} diff --git a/dao/organizer.go b/dao/organizer.go index 51d01f3..d758bed 100644 --- a/dao/organizer.go +++ b/dao/organizer.go @@ -5,10 +5,9 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" ) -func OrganizerInsert(ctx context.Context, i *models.OrganizerCreate, token *vcapool.AccessToken) (result *models.Organizer, err error) { +func OrganizerInsert(ctx context.Context, i *models.OrganizerCreate, token *models.AccessToken) (result *models.Organizer, err error) { if err = models.OrganizerPermission(token); err != nil { return } @@ -36,7 +35,7 @@ func OrganizerGetByID(ctx context.Context, i *models.OrganizerParam) (result *mo return } -func OrganizerUpdate(ctx context.Context, i *models.OrganizerUpdate, token *vcapool.AccessToken) (result *models.Organizer, err error) { +func OrganizerUpdate(ctx context.Context, i *models.OrganizerUpdate, token *models.AccessToken) (result *models.Organizer, err error) { if err = models.OrganizerPermission(token); err != nil { return } @@ -47,7 +46,7 @@ func OrganizerUpdate(ctx context.Context, i *models.OrganizerUpdate, token *vcap return } -func OrganizerDelete(ctx context.Context, i *models.OrganizerParam, token *vcapool.AccessToken) (err error) { +func OrganizerDelete(ctx context.Context, i *models.OrganizerParam, token *models.AccessToken) (err error) { if err = models.OrganizerDeletePermission(token); err != nil { return } diff --git a/dao/participation.go b/dao/participation.go index 36042d8..d6cc13e 100644 --- a/dao/participation.go +++ b/dao/participation.go @@ -6,15 +6,32 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func ParticipationInsert(ctx context.Context, i *models.ParticipationCreate, token *vcapool.AccessToken) (result *models.Participation, err error) { - database := i.ParticipationDatabase(token) +func ParticipationInsert(ctx context.Context, i *models.ParticipationCreate, token *models.AccessToken) (result *models.Participation, err error) { + + event := new(models.Event) + if err = EventCollection.FindOne( + ctx, + bson.D{{Key: "_id", Value: i.EventID}}, + event, + ); err != nil { + return + } + database := i.ParticipationDatabase(token, event) if err = ParticipationCollection.InsertOne(ctx, database); err != nil { return } + if event, err = EventGetInternalByID(ctx, &models.EventParam{ID: i.EventID}); err != nil { + return + } + if _, err = EventApplicationsUpdate(ctx, &models.EventApplicationsUpdate{ID: i.EventID, Applications: models.EventApplications{ + Requested: event.Applications.Requested + 1, + Total: event.Applications.Total + 1, + }}); err != nil { + return + } filter := database.Match() if err = ParticipationCollection.AggregateOne( ctx, @@ -26,7 +43,7 @@ func ParticipationInsert(ctx context.Context, i *models.ParticipationCreate, tok return } -func ParticipationGet(ctx context.Context, i *models.ParticipationQuery, token *vcapool.AccessToken) (result *[]models.Participation, err error) { +func ParticipationGet(ctx context.Context, i *models.ParticipationQuery, token *models.AccessToken) (result *[]models.Participation, err error) { if err = models.ParticipationPermission(token); err != nil { return } @@ -42,7 +59,7 @@ func ParticipationGet(ctx context.Context, i *models.ParticipationQuery, token * return } -func ParticipationGetByID(ctx context.Context, i *models.ParticipationParam, token *vcapool.AccessToken) (result *models.Participation, err error) { +func ParticipationGetByID(ctx context.Context, i *models.ParticipationParam, token *models.AccessToken) (result *models.Participation, err error) { filter := i.PermittedFilter(token) if err = ParticipationCollection.AggregateOne( ctx, @@ -54,7 +71,7 @@ func ParticipationGetByID(ctx context.Context, i *models.ParticipationParam, tok return } -func ParticipationUserGet(ctx context.Context, i *models.ParticipationQuery, token *vcapool.AccessToken) (result *[]models.UserParticipation, err error) { +func ParticipationUserGet(ctx context.Context, i *models.ParticipationQuery, token *models.AccessToken) (result *[]models.UserParticipation, err error) { filter := i.FilterUser(token) result = new([]models.UserParticipation) if err = ParticipationCollection.Aggregate( @@ -68,7 +85,7 @@ func ParticipationUserGet(ctx context.Context, i *models.ParticipationQuery, tok return } -func ParticipationAspGet(ctx context.Context, i *models.ParticipationQuery, token *vcapool.AccessToken) (result *models.EventDetails, err error) { +func ParticipationAspGet(ctx context.Context, i *models.ParticipationQuery, token *models.AccessToken) (result *models.EventDetails, err error) { filter := i.FilterAspInformation(token) participation := new(models.Participation) if err = ParticipationCollection.AggregateOne( @@ -82,7 +99,7 @@ func ParticipationAspGet(ctx context.Context, i *models.ParticipationQuery, toke return } -func ParticipationEventGet(ctx context.Context, i *models.EventParam, token *vcapool.AccessToken) (result *[]models.EventParticipation, err error) { +func ParticipationEventGet(ctx context.Context, i *models.EventParam, token *models.AccessToken) (result *[]models.EventParticipation, err error) { filter := i.FilterEvent(token) result = new([]models.EventParticipation) if err = ParticipationCollection.Aggregate( @@ -95,16 +112,16 @@ func ParticipationEventGet(ctx context.Context, i *models.EventParam, token *vca return } -func ParticipationUpdate(ctx context.Context, i *models.ParticipationUpdate, token *vcapool.AccessToken) (result *models.Participation, err error) { - event := new(models.Participation) +func ParticipationUpdate(ctx context.Context, i *models.ParticipationUpdate, token *models.AccessToken) (result *models.Participation, err error) { + participation := new(models.Participation) if err = ParticipationCollection.AggregateOne( ctx, models.ParticipationPipeline().Match(i.Match()).Pipe, - event, + participation, ); err != nil { return } - if err = i.ParticipationUpdatePermission(token, event); err != nil { + if err = i.ParticipationUpdatePermission(token, participation); err != nil { return } filter := i.Match() @@ -117,7 +134,13 @@ func ParticipationUpdate(ctx context.Context, i *models.ParticipationUpdate, tok ); err != nil { return } - if event.Status != result.Status { + applications := new(models.EventApplications) + applicationsUpdate := participation.UpdateEventApplicationsUpdate(-1, applications) + applicationsUpdate = result.UpdateEventApplicationsUpdate(1, &applicationsUpdate.Applications) + if _, err = EventApplicationsUpdate(ctx, applicationsUpdate); err != nil { + return + } + if participation.Status != result.Status { if result.Status == "confirmed" || result.Status == "rejected" { ParticipationNotification(ctx, result) } @@ -128,10 +151,19 @@ func ParticipationUpdate(ctx context.Context, i *models.ParticipationUpdate, tok return } -func ParticipationDelete(ctx context.Context, i *models.ParticipationParam, token *vcapool.AccessToken) (err error) { +func ParticipationDelete(ctx context.Context, i *models.ParticipationParam, token *models.AccessToken) (err error) { if err = models.ParticipationDeletePermission(token); err != nil { return } + participation := new(models.Participation) + if participation, err = ParticipationGetByID(ctx, i, token); err != nil { + return + } + applications := new(models.EventApplications) + applicationsUpdate := participation.UpdateEventApplicationsUpdate(-1, applications) + if _, err = EventApplicationsUpdate(ctx, applicationsUpdate); err != nil { + return + } if err = ParticipationCollection.DeleteOne(ctx, bson.D{{Key: "_id", Value: i.ID}}); err != nil { return } diff --git a/dao/profile.go b/dao/profile.go index 9a3ffb3..cf9e1f5 100644 --- a/dao/profile.go +++ b/dao/profile.go @@ -4,13 +4,13 @@ import ( "context" "log" "pool-backend/models" + "time" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func ProfileInsert(ctx context.Context, i *models.ProfileCreate, token *vcapool.AccessToken) (result *models.Profile, err error) { +func ProfileInsert(ctx context.Context, i *models.ProfileCreate, token *models.AccessToken) (result *models.Profile, err error) { result = i.Profile(token.ID) if err = ProfileCollection.InsertOne(ctx, result); err != nil { return @@ -18,7 +18,7 @@ func ProfileInsert(ctx context.Context, i *models.ProfileCreate, token *vcapool. return } -func ProfileGetByID(ctx context.Context, i *models.UserParam, token *vcapool.AccessToken) (result *models.User, err error) { +func ProfileGetByID(ctx context.Context, i *models.UserParam, token *models.AccessToken) (result *models.User, err error) { if err = models.UsersDetailsPermission(token); err != nil { return } @@ -28,8 +28,14 @@ func ProfileGetByID(ctx context.Context, i *models.UserParam, token *vcapool.Acc return } -func ProfileUpdate(ctx context.Context, i *models.ProfileUpdate, token *vcapool.AccessToken) (result *models.Profile, err error) { +func ProfileUpdate(ctx context.Context, i *models.ProfileUpdate, token *models.AccessToken) (result *models.Profile, err error) { filter := i.PermittedFilter(token) + birthdate := time.Unix(i.Birthdate, 0) + if i.Birthdate != 0 { + i.BirthdateDatetime = birthdate.Format("2006-01-02") + } else { + i.BirthdateDatetime = "" + } if err = ProfileCollection.UpdateOne( ctx, filter, @@ -51,7 +57,7 @@ func ProfileUpdate(ctx context.Context, i *models.ProfileUpdate, token *vcapool. return } -func ProfileSync(ctx context.Context, i models.Profile, token *vcapool.AccessToken) (result *models.Profile, err error) { +func ProfileSync(ctx context.Context, i models.Profile, token *models.AccessToken) (result *models.Profile, err error) { go func() { if err = IDjango.Post(i, "/v1/pool/profile/"); err != nil { log.Print(err) @@ -60,7 +66,7 @@ func ProfileSync(ctx context.Context, i models.Profile, token *vcapool.AccessTok return } -func UsersProfileUpdate(ctx context.Context, i *models.ProfileUpdate, token *vcapool.AccessToken) (result *models.Profile, err error) { +func UsersProfileUpdate(ctx context.Context, i *models.ProfileUpdate, token *models.AccessToken) (result *models.Profile, err error) { if err = models.UsersEditPermission(token); err != nil { return } diff --git a/dao/receipts.go b/dao/receipts.go new file mode 100644 index 0000000..27b45fc --- /dev/null +++ b/dao/receipts.go @@ -0,0 +1,122 @@ +package dao + +import ( + "archive/zip" + "bytes" + "context" + "io" + "pool-backend/models" + "strconv" + + "github.com/Viva-con-Agua/vcago/vmod" + "go.mongodb.org/mongo-driver/bson" +) + +func ReceiptFileCreate( + ctx context.Context, + create *models.ReceiptFileCreate, + file *vmod.File, + token *models.AccessToken, +) ( + result *models.ReceiptFile, + err error, +) { + if err = models.DepositPermission(token); err != nil { + return + } + deposit := new(models.Deposit) + filter := bson.D{{Key: "_id", Value: create.DepositID}} + if err = DepositCollection.FindOne(ctx, filter, deposit); err != nil { + return + } + //permission check + result = create.ReceiptFile() + if err = ReceiptFileCollection.InsertOne(ctx, result); err != nil { + return + } + if err = Database.UploadFile(file, result.ID); err != nil { + return + } + return +} + +func ReceiptFileGetByID( + ctx context.Context, + id *vmod.IDParam, + token *models.AccessToken, +) ( + result []byte, + err error, +) { + if err = models.DepositPermission(token); err != nil { + return + } + file := new(models.ReceiptFile) + if err = ReceiptFileCollection.FindOne(ctx, id.Filter(), file); err != nil { + return + } + //permission check + if result, err = Database.DownloadFile(id.ID); err != nil { + return + } + return +} + +func ReceiptFileZipGetByID( + ctx context.Context, + id *vmod.IDParam, + token *models.AccessToken, +) ( + result []byte, + err error, +) { + if err = models.DepositPermission(token); err != nil { + return + } + deposit := new(models.Deposit) + if err = DepositCollection.AggregateOne(ctx, models.DepositPipeline().Match(id.Filter()).Pipe, deposit); err != nil { + return + } + buf := new(bytes.Buffer) + w := zip.NewWriter(buf) + for index, file := range deposit.Receipts { + var bbuffer []byte + if bbuffer, err = Database.DownloadFile(file.ID); err != nil { + return + } + var f io.Writer + if f, err = w.Create(deposit.ReasonForPayment + "_" + strconv.Itoa(index+1) + ".png"); err != nil { + return + } + if _, err = f.Write(bbuffer); err != nil { + return + } + } + err = w.Close() + result = buf.Bytes() + return +} + +func ReceiptFileDeleteByID( + ctx context.Context, + id *vmod.IDParam, + token *models.AccessToken, +) ( + result *vmod.DeletedResponse, + err error, +) { + if err = models.DepositPermission(token); err != nil { + return + } + file := new(models.ReceiptFile) + if err = ReceiptFileCollection.FindOne(ctx, id.Filter(), file); err != nil { + return + } + //permission check + if err = Database.DeleteFile(ctx, id.ID); err != nil { + return + } + err = ReceiptFileCollection.DeleteOne(ctx, id.Filter()) + result = vmod.NewDeletedResponse(id.ID) + return +} diff --git a/dao/role.go b/dao/role.go index f6e2fa0..cabc21c 100644 --- a/dao/role.go +++ b/dao/role.go @@ -9,11 +9,10 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func RoleInsert(ctx context.Context, i *models.RoleRequest, token *vcapool.AccessToken) (result *vmod.Role, err error) { +func RoleInsert(ctx context.Context, i *models.RoleRequest, token *models.AccessToken) (result *vmod.Role, err error) { filter := i.MatchUser() user := new(models.User) if err = UserCollection.AggregateOne( @@ -38,7 +37,7 @@ func RoleInsert(ctx context.Context, i *models.RoleRequest, token *vcapool.Acces return } -func RoleBulkUpdate(ctx context.Context, i *models.RoleBulkRequest, token *vcapool.AccessToken) (result *models.RoleBulkExport, userRolesMap map[string]*models.BulkUserRoles, err error) { +func RoleBulkUpdate(ctx context.Context, i *models.RoleBulkRequest, token *models.AccessToken) (result *models.RoleBulkExport, userRolesMap map[string]*models.BulkUserRoles, err error) { if err = models.RolesBulkPermission(token); err != nil { return } @@ -84,7 +83,7 @@ func RoleBulkUpdate(ctx context.Context, i *models.RoleBulkRequest, token *vcapo if userRolesMap[role.UserID] == nil { userRolesMap[role.UserID] = &models.BulkUserRoles{} } - userRolesMap[role.UserID].AddedRoles = append(userRolesMap[role.UserID].AddedRoles, createdRole.Label) + userRolesMap[role.UserID].AddedRoles = append(userRolesMap[role.UserID].AddedRoles, createdRole.Name) } } @@ -129,14 +128,14 @@ func RoleBulkUpdate(ctx context.Context, i *models.RoleBulkRequest, token *vcapo if userRolesMap[role.UserID] == nil { userRolesMap[role.UserID] = &models.BulkUserRoles{} } - userRolesMap[role.UserID].DeletedRoles = append(userRolesMap[role.UserID].DeletedRoles, deleteRole.Label) + userRolesMap[role.UserID].DeletedRoles = append(userRolesMap[role.UserID].DeletedRoles, deleteRole.Name) } } result.CrewID = i.CrewID return } -func RoleBulkConfirm(ctx context.Context, i *[]models.RoleHistory, crew_id string, token *vcapool.AccessToken) (result *models.RoleBulkExport, userRolesMap map[string]*models.AspBulkUserRoles, err error) { +func RoleBulkConfirm(ctx context.Context, i *[]models.RoleHistory, crew_id string, token *models.AccessToken) (result *models.RoleBulkExport, userRolesMap map[string]*models.AspBulkUserRoles, err error) { if err = models.RolesAdminPermission(token); err != nil { return } @@ -190,13 +189,13 @@ func RoleBulkConfirm(ctx context.Context, i *[]models.RoleHistory, crew_id strin userRolesMap[role.UserID] = &models.AspBulkUserRoles{} } if index := getIndex(createdRole, *deleted_roles); index >= 0 { - userRolesMap[role.UserID].UnchangedRoles = append(userRolesMap[role.UserID].UnchangedRoles, createdRole.Label) + userRolesMap[role.UserID].UnchangedRoles = append(userRolesMap[role.UserID].UnchangedRoles, createdRole.Name) *deleted_roles = (*deleted_roles)[:index+copy((*deleted_roles)[index:], (*deleted_roles)[index+1:])] } else { if userRolesMap[role.UserID] == nil { userRolesMap[role.UserID] = &models.AspBulkUserRoles{} } - userRolesMap[role.UserID].AddedRoles = append(userRolesMap[role.UserID].AddedRoles, createdRole.Label) + userRolesMap[role.UserID].AddedRoles = append(userRolesMap[role.UserID].AddedRoles, createdRole.Name) } } } @@ -206,7 +205,7 @@ func RoleBulkConfirm(ctx context.Context, i *[]models.RoleHistory, crew_id strin if userRolesMap[role.UserID] == nil { userRolesMap[role.UserID] = &models.AspBulkUserRoles{} } - userRolesMap[role.UserID].DeletedRoles = append(userRolesMap[role.UserID].DeletedRoles, role.Label) + userRolesMap[role.UserID].DeletedRoles = append(userRolesMap[role.UserID].DeletedRoles, role.Name) } } result.CrewID = crew_id @@ -220,7 +219,7 @@ func getIndex(role *vmod.Role, data []vmod.Role) (index int) { } return -1 } -func RoleDelete(ctx context.Context, i *models.RoleRequest, token *vcapool.AccessToken) (result *vmod.Role, err error) { +func RoleDelete(ctx context.Context, i *models.RoleRequest, token *models.AccessToken) (result *vmod.Role, err error) { filter := i.MatchUser() user := new(models.User) if err = UserCollection.FindOne( diff --git a/dao/role_history.go b/dao/role_history.go index ff34184..244cee1 100644 --- a/dao/role_history.go +++ b/dao/role_history.go @@ -9,11 +9,10 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func RoleHistoryInsert(ctx context.Context, i *models.RoleHistoryCreate, token *vcapool.AccessToken) (result *models.RoleHistory, err error) { +func RoleHistoryInsert(ctx context.Context, i *models.RoleHistoryCreate, token *models.AccessToken) (result *models.RoleHistory, err error) { if err = models.RolesHistoryAdminPermission(token); err != nil { return } @@ -26,12 +25,12 @@ func RoleHistoryInsert(ctx context.Context, i *models.RoleHistoryCreate, token * return } -func RoleHistoryBulkInsert(ctx context.Context, i *models.RoleHistoryBulkRequest, token *vcapool.AccessToken) (result *models.RoleBulkExport, err error) { +func RoleHistoryBulkInsert(ctx context.Context, i *models.RoleHistoryBulkRequest, token *models.AccessToken) (result *models.RoleBulkExport, err error) { if err = models.RolesBulkPermission(token); err != nil { return } - if token.Roles.Validate("admin;employee") { + if token.Roles.Validate("admin;employee;pool_employee") { RoleHistoryDelete(ctx, &models.RoleHistoryRequest{CrewID: i.CrewID, Confirmed: false}, token) } result = new(models.RoleBulkExport) @@ -64,7 +63,7 @@ func RoleHistoryBulkInsert(ctx context.Context, i *models.RoleHistoryBulkRequest return } -func RoleHistoryGet(ctx context.Context, i *models.RoleHistoryRequest, token *vcapool.AccessToken) (result *[]models.RoleHistory, list_size int64, err error) { +func RoleHistoryGet(ctx context.Context, i *models.RoleHistoryRequest, token *models.AccessToken) (result *[]models.RoleHistory, list_size int64, err error) { result = new([]models.RoleHistory) pipeline := models.RolesHistoryPermittedPipeline() if err = PoolRoleHistoryCollection.Aggregate( @@ -78,7 +77,7 @@ func RoleHistoryGet(ctx context.Context, i *models.RoleHistoryRequest, token *vc return } -func RoleHistoryConfirm(ctx context.Context, i *models.RoleHistoryRequest, token *vcapool.AccessToken) (result *[]models.RoleHistory, err error) { +func RoleHistoryConfirm(ctx context.Context, i *models.RoleHistoryRequest, token *models.AccessToken) (result *[]models.RoleHistory, err error) { if err = models.RolesHistoryAdminPermission(token); err != nil { return } @@ -95,7 +94,7 @@ func RoleHistoryConfirm(ctx context.Context, i *models.RoleHistoryRequest, token return } -func RoleHistoryDelete(ctx context.Context, i *models.RoleHistoryRequest, token *vcapool.AccessToken) (result *models.RoleHistory, err error) { +func RoleHistoryDelete(ctx context.Context, i *models.RoleHistoryRequest, token *models.AccessToken) (result *models.RoleHistory, err error) { if err = models.RolesHistoryAdminPermission(token); err != nil { return } diff --git a/dao/taking.go b/dao/taking.go index 1503bd5..62fe55c 100644 --- a/dao/taking.go +++ b/dao/taking.go @@ -4,11 +4,10 @@ import ( "context" "pool-backend/models" + "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo/options" ) var ( @@ -16,7 +15,7 @@ var ( TakingUpdatedActivity = &models.ActivityDatabase{ModelType: "taking", Comment: "Successfully updated", Status: "updated"} ) -func TakingInsert(ctx context.Context, i *models.TakingCreate, token *vcapool.AccessToken) (result *models.Taking, err error) { +func TakingInsert(ctx context.Context, i *models.TakingCreate, token *models.AccessToken) (result *models.Taking, err error) { if err = models.TakingPermission(token); err != nil { return } @@ -45,7 +44,7 @@ func TakingInsert(ctx context.Context, i *models.TakingCreate, token *vcapool.Ac return } -func TakingUpdate(ctx context.Context, i *models.TakingUpdate, token *vcapool.AccessToken) (result *models.Taking, err error) { +func TakingUpdate(ctx context.Context, i *models.TakingUpdate, token *models.AccessToken) (result *models.Taking, err error) { if err = models.TakingPermission(token); err != nil { return } @@ -108,35 +107,42 @@ func TakingUpdate(ctx context.Context, i *models.TakingUpdate, token *vcapool.Ac return } -func TakingGet(ctx context.Context, query *models.TakingQuery, token *vcapool.AccessToken) (result *[]models.Taking, listSize int64, err error) { +type Count struct { + ListSize int64 `bson:"list_size" json:"list_size"` +} + +func TakingGet(ctx context.Context, query *models.TakingQuery, token *models.AccessToken) (result []models.Taking, listSize int64, err error) { if err = models.TakingPermission(token); err != nil { return } - result = new([]models.Taking) + result = []models.Taking{} filter := query.PermittedFilter(token) sort := query.Sort() pipeline := models.TakingPipeline().SortFields(sort).Match(filter).Sort(sort).Skip(query.Skip, 0).Limit(query.Limit, 100).Pipe if err = TakingCollection.Aggregate( ctx, pipeline, - result, + &result, ); err != nil { return } - opts := options.Count().SetHint("_id_") - if query.FullCount != "true" { - opts.SetSkip(query.Skip).SetLimit(query.Limit) + count := new([]Count) + if err = TakingCollection.Aggregate( + context.Background(), + models.TakingCountPipeline(filter).Pipe, + count, + ); err != nil { + return } - if cursor, cErr := UserViewCollection.Collection.CountDocuments(ctx, filter, opts); cErr != nil { - print(cErr) + if len(*count) == 0 { listSize = 0 } else { - listSize = cursor + listSize = (*count)[0].ListSize } return } -func TakingGetByID(ctx context.Context, param *vmod.IDParam, token *vcapool.AccessToken) (result *models.Taking, err error) { +func TakingGetByID(ctx context.Context, param *vmod.IDParam, token *models.AccessToken) (result *models.Taking, err error) { if err = models.TakingPermission(token); err != nil { return } @@ -169,10 +175,25 @@ func TakingDeletetByIDSystem(ctx context.Context, id string) (err error) { return } -func TakingDeletetByID(ctx context.Context, param *vmod.IDParam, token *vcapool.AccessToken) (err error) { +func TakingDeletetByID(ctx context.Context, param *vmod.IDParam, token *models.AccessToken) (err error) { if err = models.TakingPermission(token); err != nil { return } - err = TakingCollection.DeleteOne(ctx, models.TakingPermittedFilter(param, token)) + taking := new(models.Taking) + filter := models.TakingPermittedFilter(param, token) + if err = TakingCollection.AggregateOne( + ctx, + models.TakingPipeline().Match(filter).Pipe, + &taking, + ); err != nil { + return + } + if taking.Event.ID != "" { + return vcago.NewBadRequest("taking", "depending_on_event") + } + if len(taking.DepositUnits) > 0 { + return vcago.NewBadRequest("taking", "depending_on_deposit") + } + err = TakingCollection.DeleteOne(ctx, filter) return } diff --git a/dao/update_ticker.go b/dao/update_ticker.go index 6aa3b2b..c2b2d75 100644 --- a/dao/update_ticker.go +++ b/dao/update_ticker.go @@ -16,12 +16,18 @@ func UpdateTicker() { quit := make(chan struct{}) EventStateFinishTicker() EventStateClosedTicker() + UserActiveStateTicker() + //SendWeeklyNotification() + SendWeeklyCrewNotification() go func() { for { select { case <-ticker.C: + //SendWeeklyNotification() + //SendWeeklyCrewNotification() EventStateFinishTicker() EventStateClosedTicker() + UserActiveStateTicker() case <-quit: ticker.Stop() return @@ -36,23 +42,11 @@ func EventStateFinishTicker() { filter.EqualString("event_state.state", "published") filter.LteInt64("end_at", fmt.Sprint(time.Now().Unix())) update := bson.D{{Key: "event_state.state", Value: "finished"}} - events := new([]models.Event) - if err := EventCollection.Find(context.Background(), filter.Bson(), events); err != nil { - log.Print(err) - } if err := EventCollection.UpdateMany(context.Background(), filter.Bson(), vmdb.UpdateSet(update)); err != nil { if !vmdb.ErrNoDocuments(err) { log.Print(err) } } - for _, value := range *events { - filterTaking := bson.D{{Key: "_id", Value: value.TakingID}, {Key: "taking_id", Value: bson.D{{Key: "$ne", Value: ""}}}} - updateTaking := bson.D{{Key: "date_of_taking", Value: value.EndAt}} - if err := TakingCollection.UpdateOne(context.Background(), filterTaking, vmdb.UpdateSet(updateTaking), nil); err != nil { - log.Print(err) - } - } - } // EventStateClosed @@ -101,3 +95,97 @@ func EventStateClosedTicker() { } } + +func UserActiveStateTicker() { + checkDate := time.Now().Unix() - 15768000 + filter := bson.D{ + {Key: "last_login_date", Value: bson.D{{Key: "$lte", Value: checkDate}}}, + {Key: "active.status", Value: "confirmed"}, + } + userList := []models.User{} + pipeline := models.UserPipeline(false).Match(filter).Pipe + if err := UserCollection.Aggregate(context.Background(), pipeline, &userList); err != nil { + log.Print(err) + } + for _, user := range userList { + update := bson.D{{Key: "status", Value: "rejected"}} + userFilter := bson.D{{Key: "_id", Value: user.Active.ID}} + if err := ActiveCollection.UpdateOne(context.Background(), userFilter, vmdb.UpdateSet(update), nil); err != nil { + log.Print(err) + } + } + +} + +// SendWeeklyNotification Send a notification mail to festival@ and netzwerk@ for all published events last 7 days +func SendWeeklyNotification() { + + h, _, _ := time.Now().Clock() + if time.Now().Weekday() != time.Monday { + return + } else if h < 9 || h >= 10 { + return + } + + filter := models.EventPublishedLastWeek() + + events := []models.EventStateHistory{} + pipeline := models.EventStatePipeline().Match(filter).Pipe + if err := EventStateHistoryCollection.Aggregate(context.Background(), pipeline, &events); err != nil { + log.Print(err) + } + + eventNotifications := []models.EventStateHistoryNotification{} + for _, e := range events { + eventNotifications = append(eventNotifications, models.EventStateHistoryNotification{ + EventID: e.EventID, + EventName: e.Event.Name, + EventCrew: e.Crew.Name, + EventStart: time.Unix(e.Event.StartAt, 0).Format("02.01.2006 15:04"), + EventArtist: models.ToArtistList(e.Event.Artists), + EventLocation: e.Event.GetLocation(), + PublishedDate: time.Unix(e.Date, 0).Format("02.01.2006"), + }) + } + + if err := EventHistoryAdminNotification(context.Background(), eventNotifications); err != nil { + log.Print(err) + + } +} + +// SendWeeklyCrewNotification Send a notification mail to each crew email address for all published events last 7 days +func SendWeeklyCrewNotification() { + + h, _, _ := time.Now().Clock() + if time.Now().Weekday() != time.Monday { + return + } else if h < 9 || h >= 10 { + return + } + + filter := models.EventPublishedLastWeek() + events := []models.EventStateHistory{} + pipeline := models.EventStatePipeline().Match(filter).Pipe + if err := EventStateHistoryCollection.Aggregate(context.Background(), pipeline, &events); err != nil { + log.Print(err) + } + m := make(map[string][]models.EventStateHistoryNotification) + for _, e := range events { + if e.CrewID == "" { + continue + } + m[e.Crew.Email] = append(m[e.Crew.Email], models.EventStateHistoryNotification{ + EventID: e.EventID, + EventName: e.Event.Name, + EventCrew: e.Crew.Name, + EventStart: time.Unix(e.Event.StartAt, 0).Format("02.01.2006 15:04"), + EventArtist: models.ToArtistList(e.Event.Artists), + EventLocation: e.Event.GetLocation(), + PublishedDate: time.Unix(e.Date, 0).Format("02.01.2006"), + }) + } + if err := EventHistoryCrewNotification(context.Background(), m); err != nil { + log.Print(err) + } +} diff --git a/dao/updates.go b/dao/updates.go index 7d47f8a..ebae43a 100644 --- a/dao/updates.go +++ b/dao/updates.go @@ -4,75 +4,79 @@ import ( "context" "log" "pool-backend/models" + "time" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) -type Updated struct { - ID string `bson:"_id"` - Name string `bson:"name"` -} - -func CheckUpdated(ctx context.Context, name string) bool { - update := new(Updated) - if err := UpdateCollection.FindOne(ctx, bson.D{{Key: "name", Value: name}}, update); err != nil { - if vmdb.ErrNoDocuments(err) { - return false - } - log.Print(err) - } - return true -} - -func InsertUpdate(ctx context.Context, name string) { - update := &Updated{ID: uuid.NewString(), Name: name} - if err := UpdateCollection.InsertOne(ctx, update); err != nil { - log.Print(err) - } - -} - func UpdateDatabase() { ctx := context.Background() - if !CheckUpdated(ctx, "update_crew_mailbox") { + if !Updates.Check(ctx, "update_crew_mailbox") { UpdateCrewMaibox(ctx) - InsertUpdate(ctx, "update_crew_mailbox") + Updates.Insert(ctx, "update_crew_mailbox") } - if !CheckUpdated(ctx, "update_usercrew3_mailbox") { + if !Updates.Check(ctx, "update_usercrew3_mailbox") { UpdateUserCrewMaibox(ctx) - InsertUpdate(ctx, "update_usercrew3_mailbox") + Updates.Insert(ctx, "update_usercrew3_mailbox") } - if !CheckUpdated(ctx, "update_delete_confirmed") { + if !Updates.Check(ctx, "update_delete_confirmed") { UpdateDeleteUnconfirmd(ctx) - InsertUpdate(ctx, "update_delete_confirmed") + Updates.Insert(ctx, "update_delete_confirmed") } - if !CheckUpdated(ctx, "update_confirm_admin") { + if !Updates.Check(ctx, "update_confirm_admin") { UpdateConfirmAdmin(ctx) - InsertUpdate(ctx, "update_confirm_admin") + Updates.Insert(ctx, "update_confirm_admin") } - if !CheckUpdated(ctx, "taking_currency1") { + if !Updates.Check(ctx, "taking_currency1") { UpdateTakingCurrency(ctx) - InsertUpdate(ctx, "taking_currency1") + Updates.Insert(ctx, "taking_currency1") } - if !CheckUpdated(ctx, "deposit_currency") { + if !Updates.Check(ctx, "deposit_currency") { UpdateDepositCurrency(ctx) - InsertUpdate(ctx, "deposit_currency") + Updates.Insert(ctx, "deposit_currency") } - if !CheckUpdated(ctx, "deposit_unit_currency") { + if !Updates.Check(ctx, "deposit_unit_currency") { UpdateDepositUnitCurrency(ctx) - InsertUpdate(ctx, "deposit_unit_currency") + Updates.Insert(ctx, "deposit_unit_currency") } - if !CheckUpdated(ctx, "taking_no_income_event_canceled") { + if !Updates.Check(ctx, "taking_no_income_event_canceled") { UpdateEventCanceledNoIncome(ctx) - InsertUpdate(ctx, "taking_no_income_event_canceled") + Updates.Insert(ctx, "taking_no_income_event_canceled") } - if !CheckUpdated(ctx, "currency_problem") { + if !Updates.Check(ctx, "currency_problem") { UpdateDepositCurrency(ctx) UpdateDepositUnitCurrency(ctx) UpdateTakingCurrency(ctx) - InsertUpdate(ctx, "currency_problem") + Updates.Insert(ctx, "currency_problem") + } + if !Updates.Check(ctx, "date_of_taking_1") { + UpdateDateOfTaking1(ctx) + Updates.Insert(ctx, "date_of_taking_1") + } + if !Updates.Check(ctx, "birthdate_1") { + UpdateProfileBirthdate(ctx) + Updates.Insert(ctx, "birthdate_1") + } + if !Updates.Check(ctx, "event_applications") { + UpdateEventApplications(ctx) + Updates.Insert(ctx, "event_applications") + } + if !Updates.Check(ctx, "last_login_date_1") { + UpdateSetLastLoginDate(ctx) + Updates.Insert(ctx, "last_login_date_1") + } + if !Updates.Check(ctx, "create_default_organisation") { + CreateDefaultOrganisation(ctx) + Updates.Insert(ctx, "create_default_organisation") + } + if !Updates.Check(ctx, "update_deposit_units_1") { + UpdateDepositUnitNorms(ctx) + Updates.Insert(ctx, "update_deposit_units_1") + } + if !Updates.Check(ctx, "publish_roles_init") { + PublishRoles() + Updates.Insert(ctx, "publish_roles_init") } } @@ -167,3 +171,116 @@ func UpdateEventCanceledNoIncome(ctx context.Context) { } } } + +func UpdateDateOfTaking1(ctx context.Context) { + eventList := []models.Event{} + if err := EventCollection.Find(ctx, bson.D{{}}, &eventList); err != nil { + log.Print(err) + } + for _, event := range eventList { + update := bson.D{{Key: "date_of_taking", Value: event.EndAt}} + filter := bson.D{{Key: "_id", Value: event.TakingID}} + if err := TakingCollection.UpdateOne(ctx, filter, vmdb.UpdateSet(update), nil); err != nil { + log.Print(err) + } + } +} + +func UpdateProfileBirthdate(ctx context.Context) { + profileList := []models.ProfileUpdate{} + if err := ProfileCollection.Find(ctx, bson.D{{}}, &profileList); err != nil { + log.Print(err) + } + for _, profile := range profileList { + birthdate := time.Unix(profile.Birthdate, 0) + if profile.Birthdate != 0 { + profile.BirthdateDatetime = birthdate.Format("2006-01-02") + } else { + profile.BirthdateDatetime = "" + } + filter := bson.D{{Key: "_id", Value: profile.ID}} + if err := ProfileCollection.UpdateOne(ctx, filter, vmdb.UpdateSet(profile), nil); err != nil { + log.Print(err) + } + } +} + +func UpdateEventApplications(ctx context.Context) { + eventList := []models.Event{} + if err := EventCollection.Aggregate(ctx, models.EventPipeline(&models.AccessToken{ID: ""}).Pipe, &eventList); err != nil { + log.Print(err) + } + for _, event := range eventList { + confirmed, rejected, requested, withdrawn, total := 0, 0, 0, 0, 0 + + for _, p := range event.Participation { + switch p.Status { + case "confirmed": + confirmed++ + case "rejected": + rejected++ + case "requested": + requested++ + case "withdrawn": + withdrawn++ + } + total++ + } + update := bson.D{{Key: "applications", Value: models.EventApplications{ + Confirmed: confirmed, Rejected: rejected, Requested: requested, Withdrawn: withdrawn, Total: total, + }}} + filter := bson.D{{Key: "_id", Value: event.ID}} + if err := EventCollection.UpdateOne(ctx, filter, vmdb.UpdateSet(update), nil); err != nil { + log.Print(err) + } + } +} +func UpdateSetLastLoginDate(ctx context.Context) { + update := bson.D{{Key: "last_login_date", Value: time.Now().Unix()}} + if err := UserCollection.UpdateMany(ctx, bson.D{{}}, vmdb.UpdateSet(update)); err != nil { + log.Print(err) + } +} + +func CreateDefaultOrganisation(ctx context.Context) { + i := models.OrganisationCreate{ + Name: "Viva con Agua de Sankt Pauli e.V.", + Abbreviation: "VcA DE", + Email: "pool@vivaconagua.org", + } + result := new(models.Organisation) + result = i.Organisation() + if err := OrganisationCollection.InsertOne(ctx, result); err != nil { + log.Print(err) + } + update := bson.D{{Key: "organisation_id", Value: result.ID}} + if err := CrewsCollection.UpdateMany(ctx, bson.D{}, vmdb.UpdateSet(update)); err != nil { + log.Print(err) + } + if err := UserCrewCollection.UpdateMany(ctx, bson.D{}, vmdb.UpdateSet(update)); err != nil { + log.Print(err) + } + if err := EventCollection.UpdateMany(ctx, bson.D{}, vmdb.UpdateSet(update)); err != nil { + log.Print(err) + } + filter := vmdb.NewFilter() + filter.ElemMatchList("system_roles", "name", []string{"employee", "pool_employee", "pool_finance"}) + if err := UserCollection.UpdateMany(ctx, filter.Bson(), vmdb.UpdateSet(update)); err != nil { + log.Print(err) + } +} + +func UpdateDepositUnitNorms(ctx context.Context) { + filterDonation := vmdb.NewFilter() + filterDonation.EqualStringList("value", []string{"unknown", "can", "box", "gl", "other"}) + filterEco := vmdb.NewFilter() + filterEco.EqualStringList("value", []string{"merch", "other_ec"}) + updateDonation := bson.D{{Key: "$set", Value: bson.D{{Key: "norms", Value: "donation"}}}} + updateEco := bson.D{{Key: "$set", Value: bson.D{{Key: "norms", Value: "economic"}}}} + if err := SourceCollection.UpdateMany(ctx, filterDonation.Bson(), updateDonation); err != nil { + log.Print(err) + } + if err := SourceCollection.UpdateMany(ctx, filterEco.Bson(), updateEco); err != nil { + log.Print(err) + } +} diff --git a/dao/user_active.go b/dao/user_active.go index 9597e3b..3d9fa44 100644 --- a/dao/user_active.go +++ b/dao/user_active.go @@ -6,11 +6,10 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func ActiveWithdraw(ctx context.Context, token *vcapool.AccessToken) (result *models.Active, err error) { +func ActiveWithdraw(ctx context.Context, token *models.AccessToken) (result *models.Active, err error) { if err = ActiveCollection.UpdateOne( ctx, bson.D{{Key: "user_id", Value: token.ID}}, @@ -37,7 +36,7 @@ func ActiveWithdraw(ctx context.Context, token *vcapool.AccessToken) (result *mo return } -func ActiveReject(ctx context.Context, i *models.ActiveParam, token *vcapool.AccessToken) (result *models.Active, err error) { +func ActiveReject(ctx context.Context, i *models.ActiveParam, token *models.AccessToken) (result *models.Active, err error) { //check permissions for update an other users active model. if err = models.ActivePermission(token); err != nil { return @@ -69,7 +68,7 @@ func ActiveReject(ctx context.Context, i *models.ActiveParam, token *vcapool.Acc return } -func ActiveConfirm(ctx context.Context, i *models.ActiveParam, token *vcapool.AccessToken) (result *models.Active, err error) { +func ActiveConfirm(ctx context.Context, i *models.ActiveParam, token *models.AccessToken) (result *models.Active, err error) { //check permissions for update an other users active model. if err = models.ActivePermission(token); err != nil { return @@ -86,7 +85,7 @@ func ActiveConfirm(ctx context.Context, i *models.ActiveParam, token *vcapool.Ac return } -func ActiveRequest(ctx context.Context, token *vcapool.AccessToken) (result *models.Active, err error) { +func ActiveRequest(ctx context.Context, token *models.AccessToken) (result *models.Active, err error) { //check permissions for active request if err = models.ActiveRequestPermission(token); err != nil { return diff --git a/dao/user_crew.go b/dao/user_crew.go index abeb062..132262d 100644 --- a/dao/user_crew.go +++ b/dao/user_crew.go @@ -6,11 +6,10 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func UsersUserCrewInsert(ctx context.Context, i *models.UsersCrewCreate, token *vcapool.AccessToken) (result *models.UserCrew, err error) { +func UsersUserCrewInsert(ctx context.Context, i *models.UsersCrewCreate, token *models.AccessToken) (result *models.UserCrew, err error) { if err = i.UsersCrewCreatePermission(token); err != nil { return } @@ -18,7 +17,7 @@ func UsersUserCrewInsert(ctx context.Context, i *models.UsersCrewCreate, token * if err = CrewsCollection.FindOne(ctx, i.CrewFilter(), crew); err != nil { return } - result = models.NewUserCrew(i.UserID, crew.ID, crew.Name, crew.Email, crew.MailboxID) + result = models.NewUserCrew(i.UserID, crew) if err = UserCrewCollection.InsertOne(ctx, result); err != nil { return } @@ -31,12 +30,12 @@ func UsersUserCrewInsert(ctx context.Context, i *models.UsersCrewCreate, token * return } -func UserCrewInsert(ctx context.Context, i *models.UserCrewCreate, token *vcapool.AccessToken) (result *models.UserCrew, err error) { +func UserCrewInsert(ctx context.Context, i *models.UserCrewCreate, token *models.AccessToken) (result *models.UserCrew, err error) { crew := new(models.Crew) if err = CrewsCollection.FindOne(ctx, i.CrewFilter(), crew); err != nil { return } - result = models.NewUserCrew(token.ID, crew.ID, crew.Name, crew.Email, crew.MailboxID) + result = models.NewUserCrew(token.ID, crew) if err = UserCrewCollection.InsertOne(ctx, result); err != nil { return } @@ -49,11 +48,15 @@ func UserCrewInsert(ctx context.Context, i *models.UserCrewCreate, token *vcapoo return } -func UserCrewUpdate(ctx context.Context, i *models.UserCrewUpdate, token *vcapool.AccessToken) (result *models.UserCrew, err error) { +func UserCrewUpdate(ctx context.Context, i *models.UserCrewUpdate, token *models.AccessToken) (result *models.UserCrew, err error) { if err = i.UserCrewUpdatePermission(token); err != nil { return } - + crew := new(models.Crew) + if err = CrewsCollection.FindOne(ctx, i.CrewFilter(), crew); err != nil { + return + } + i.OrganisationID = crew.OrganisationID if err = UserCrewCollection.UpdateOne(ctx, i.PermittedFilter(token), vmdb.UpdateSet(i), &result); err != nil { return } @@ -79,11 +82,16 @@ func UserCrewUpdate(ctx context.Context, i *models.UserCrewUpdate, token *vcapoo return } -func UsersCrewUpdate(ctx context.Context, i *models.UserCrewUpdate, token *vcapool.AccessToken) (result *models.UserCrew, err error) { +func UsersCrewUpdate(ctx context.Context, i *models.UserCrewUpdate, token *models.AccessToken) (result *models.UserCrew, err error) { if err = i.UsersCrewUpdatePermission(token); err != nil { return } + crew := new(models.Crew) + if err = CrewsCollection.FindOne(ctx, i.CrewFilter(), crew); err != nil { + return + } + i.OrganisationID = crew.OrganisationID if err = UserCrewCollection.UpdateOne(ctx, i.Match(), vmdb.UpdateSet(i), &result); err != nil { return } @@ -155,7 +163,7 @@ func UserCrewImport(ctx context.Context, imp *models.UserCrewImport) (result *mo if crew.Status != "active" { return nil, vcago.NewBadRequest(models.CrewCollection, "crew_is_dissolved", nil) } - result = models.NewUserCrew(user.ID, crew.ID, crew.Name, crew.Email, crew.MailboxID) + result = models.NewUserCrew(user.ID, crew) if err = UserCrewCollection.InsertOne(ctx, result); err != nil { return } diff --git a/dao/user_nvm.go b/dao/user_nvm.go index 792e8d4..bd29a43 100644 --- a/dao/user_nvm.go +++ b/dao/user_nvm.go @@ -5,11 +5,10 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "go.mongodb.org/mongo-driver/bson" ) -func NVMConfirm(ctx context.Context, token *vcapool.AccessToken) (result *models.NVM, err error) { +func NVMConfirm(ctx context.Context, token *models.AccessToken) (result *models.NVM, err error) { if err = models.NVMConfirmedPermission(token); err != nil { return } @@ -25,7 +24,7 @@ func NVMConfirm(ctx context.Context, token *vcapool.AccessToken) (result *models return } -func NVMConfirmUser(ctx context.Context, i *models.NVMIDParam, token *vcapool.AccessToken) (result *models.NVM, err error) { +func NVMConfirmUser(ctx context.Context, i *models.NVMIDParam, token *models.AccessToken) (result *models.NVM, err error) { if err = models.NVMPermission(token); err != nil { return } @@ -41,7 +40,7 @@ func NVMConfirmUser(ctx context.Context, i *models.NVMIDParam, token *vcapool.Ac return } -func NVMRejectUser(ctx context.Context, i *models.NVMIDParam, token *vcapool.AccessToken) (result *models.NVM, err error) { +func NVMRejectUser(ctx context.Context, i *models.NVMIDParam, token *models.AccessToken) (result *models.NVM, err error) { if err = models.NVMPermission(token); err != nil { return } @@ -63,7 +62,7 @@ func NVMRejectUser(ctx context.Context, i *models.NVMIDParam, token *vcapool.Acc return } -func NVMWithdraw(ctx context.Context, token *vcapool.AccessToken) (result *models.NVM, err error) { +func NVMWithdraw(ctx context.Context, token *models.AccessToken) (result *models.NVM, err error) { if err = NVMCollection.UpdateOne( ctx, bson.D{{Key: "user_id", Value: token.ID}}, diff --git a/dao/users.go b/dao/users.go index 7d33a12..a988369 100644 --- a/dao/users.go +++ b/dao/users.go @@ -6,10 +6,10 @@ import ( "pool-backend/models" "time" - "github.com/Viva-con-Agua/vcapool" + "github.com/Viva-con-Agua/vcago/vmdb" + "github.com/Viva-con-Agua/vcago/vmod" "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo/options" ) func UserInsert(ctx context.Context, i *models.UserDatabase) (result *models.User, err error) { @@ -35,7 +35,7 @@ func UserInsert(ctx context.Context, i *models.UserDatabase) (result *models.Use return } -func UsersGet(i *models.UserQuery, token *vcapool.AccessToken) (result *[]models.ListUser, list_size int64, err error) { +func UsersGet(i *models.UserQuery, token *models.AccessToken) (result *[]models.ListUser, list_size int64, err error) { if err = models.UsersPermission(token); err != nil { return } @@ -48,22 +48,19 @@ func UsersGet(i *models.UserQuery, token *vcapool.AccessToken) (result *[]models if err = UserCollection.Aggregate(ctx, pipeline, result); err != nil { return } - ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - opts := options.Count().SetHint("_id_") - if i.FullCount != "true" { - opts.SetSkip(i.Skip).SetLimit(i.Limit) - } - if cursor, cErr := UserViewCollection.Collection.CountDocuments(ctx, filter, opts); cErr != nil { + + count := vmod.Count{} + var cErr error + if cErr = UserViewCollection.AggregateOne(ctx, models.UserPermittedPipeline(token).Match(filter).Count().Pipe, &count); cErr != nil { print(cErr) - list_size = 0 + list_size = 1 } else { - list_size = cursor + list_size = int64(count.Total) } return } -func UsersGetByCrew(ctx context.Context, i *models.UserQuery, token *vcapool.AccessToken) (result *[]models.UserBasic, err error) { +func UsersGetByCrew(ctx context.Context, i *models.UserQuery, token *models.AccessToken) (result *[]models.UserBasic, err error) { if err = i.CrewUsersPermission(token); err != nil { return } @@ -75,7 +72,7 @@ func UsersGetByCrew(ctx context.Context, i *models.UserQuery, token *vcapool.Acc return } -func UsersUserGetByID(ctx context.Context, i *models.UserParam, token *vcapool.AccessToken) (result *models.User, err error) { +func UsersUserGetByID(ctx context.Context, i *models.UserParam, token *models.AccessToken) (result *models.User, err error) { if err = models.UsersPermission(token); err != nil { return } @@ -92,7 +89,7 @@ func UsersGetByID(ctx context.Context, i *models.UserParam) (result *models.User return } -func UsersMinimalGet(ctx context.Context, i *models.UserQuery, token *vcapool.AccessToken) (result *[]models.UserMinimal, err error) { +func UsersMinimalGet(ctx context.Context, i *models.UserQuery, token *models.AccessToken) (result *[]models.UserMinimal, err error) { filter := i.PermittedFilter(token) result = new([]models.UserMinimal) if err = UserCollection.Aggregate(ctx, models.UserPipelinePublic().Match(filter).Pipe, result); err != nil { @@ -101,7 +98,7 @@ func UsersMinimalGet(ctx context.Context, i *models.UserQuery, token *vcapool.Ac return } -func UsersDeleteUser(ctx context.Context, i *models.UserParam, token *vcapool.AccessToken) (err error) { +func UsersDeleteUser(ctx context.Context, i *models.UserParam, token *models.AccessToken) (err error) { if err = i.UsersDeletePermission(token); err != nil { return } @@ -150,7 +147,7 @@ func UserDelete(ctx context.Context, id string) (err error) { return } -func UserSync(ctx context.Context, i *models.ProfileParam, token *vcapool.AccessToken) (result *models.User, err error) { +func UserSync(ctx context.Context, i *models.ProfileParam, token *models.AccessToken) (result *models.User, err error) { profile := new(models.Profile) if err = ProfileCollection.FindOne(ctx, i.Match(), profile); err != nil { return @@ -164,3 +161,18 @@ func UserSync(ctx context.Context, i *models.ProfileParam, token *vcapool.Access } return } + +func UserOrganisationUpdate(ctx context.Context, i *models.UserOrganisationUpdate, token *models.AccessToken) (result *models.User, err error) { + if err = token.AccessPermission(); err != nil { + return + } + if err = UserCollection.UpdateOne( + ctx, + bson.D{{Key: "_id", Value: i.ID}}, + vmdb.UpdateSet(i), + &result, + ); err != nil { + return + } + return +} diff --git a/go.mod b/go.mod index f81ea76..6e081d5 100644 --- a/go.mod +++ b/go.mod @@ -1,49 +1,54 @@ module pool-backend -go 1.17 +go 1.21 require ( - github.com/Viva-con-Agua/vcago v1.5.5 + github.com/Viva-con-Agua/vcago v1.5.7 github.com/Viva-con-Agua/vcapool v0.3.4 - github.com/google/uuid v1.3.0 - github.com/labstack/echo/v4 v4.9.0 - go.mongodb.org/mongo-driver v1.9.1 + github.com/google/uuid v1.6.0 + github.com/labstack/echo/v4 v4.12.0 + go.mongodb.org/mongo-driver v1.17.0 ) require ( - github.com/coreos/go-oidc/v3 v3.1.0 // indirect - github.com/go-playground/locales v0.14.0 // indirect - github.com/go-playground/universal-translator v0.18.0 // indirect + github.com/go-jose/go-jose/v4 v4.0.2 // indirect + github.com/montanaflynn/stats v0.7.1 // indirect +) + +require ( + github.com/coreos/go-oidc/v3 v3.11.0 // indirect + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator v9.31.0+incompatible // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible - github.com/golang/protobuf v1.5.2 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/joho/godotenv v1.4.0 // indirect - github.com/klauspost/compress v1.15.1 // indirect - github.com/labstack/gommon v0.3.1 - github.com/leodido/go-urn v1.2.1 // indirect - github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect - github.com/nats-io/nats.go v1.13.1-0.20220308171302-2f2f6968e98d // indirect - github.com/nats-io/nkeys v0.3.0 // indirect + github.com/joho/godotenv v1.5.1 // indirect + github.com/klauspost/compress v1.17.10 // indirect + github.com/labstack/gommon v0.4.2 + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/nats-io/nats.go v1.37.0 // indirect + github.com/nats-io/nkeys v0.4.7 // indirect github.com/nats-io/nuid v1.0.1 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasttemplate v1.2.1 // indirect + github.com/valyala/fasttemplate v1.2.2 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect - github.com/xdg-go/scram v1.1.1 // indirect - github.com/xdg-go/stringprep v1.0.3 // indirect - github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect - golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 // indirect; indirecta - golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect - golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect - golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 // indirect - golang.org/x/text v0.3.7 // indirect - golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 // indirect - google.golang.org/appengine v1.6.7 // indirect - google.golang.org/protobuf v1.28.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect + golang.org/x/crypto v0.27.0 // indirect; indirecta + golang.org/x/net v0.29.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect + golang.org/x/time v0.6.0 // indirect + google.golang.org/appengine v1.6.8 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect ) diff --git a/go.sum b/go.sum index ce118d4..cda787c 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Viva-con-Agua/vcago v1.4.16/go.mod h1:kxaxW9VYWIaCdWoM+PLHNwXmtPj4FPYHPxmPK6JsA1U= -github.com/Viva-con-Agua/vcago v1.5.5 h1:bnxyyVpuLoLHwmWOdJEqwF+3x4PEek3do8j0BSUFQ9I= -github.com/Viva-con-Agua/vcago v1.5.5/go.mod h1:uJ7sBZk8IOEJbHgZ97uY+WE6TLMGkhiPvey3CxFOs4A= +github.com/Viva-con-Agua/vcago v1.5.7 h1:QYcyqn+q0qq3dhj0xSfy4Ajgn/6x0kzne/2M+4aru0o= +github.com/Viva-con-Agua/vcago v1.5.7/go.mod h1:uJ7sBZk8IOEJbHgZ97uY+WE6TLMGkhiPvey3CxFOs4A= github.com/Viva-con-Agua/vcapool v0.3.4 h1:I1IGg7BTfXihMkTwLu+qYygcvfX9zZVMZw9+0B9ZJMs= github.com/Viva-con-Agua/vcapool v0.3.4/go.mod h1:yTwmyj5DbsDduM23aEbK48BW0ONg9092hbmm1HhMso4= github.com/acobaugh/osrelease v0.0.0-20181218015638-a93a0a55a249/go.mod h1:iU1PxQMQwoHZZWmMKrMkrNlY+3+p9vxIjpZOVyxWa0g= @@ -55,6 +55,8 @@ github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnht github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/coreos/go-oidc/v3 v3.1.0 h1:6avEvcdvTa1qYsOZ6I5PRkSYHzpTNWgKYmaJfaYbrRw= github.com/coreos/go-oidc/v3 v3.1.0/go.mod h1:rEJ/idjfUyfkBit1eI1fvyr+64/g9dcKpAm8MJMesvo= +github.com/coreos/go-oidc/v3 v3.11.0 h1:Ia3MxdwpSw702YW0xgfmP1GVCMA9aEFWu12XUZ3/OtI= +github.com/coreos/go-oidc/v3 v3.11.0/go.mod h1:gE3LgjOgFoHi9a4ce4/tJczr0Ai2/BoDhf0r5lltWI0= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -67,10 +69,16 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +github.com/go-jose/go-jose/v4 v4.0.2 h1:R3l3kkBds16bO7ZFAEEcofK0MkrAJt3jlJznWZG0nvk= +github.com/go-jose/go-jose/v4 v4.0.2/go.mod h1:WVf9LFMHh/QVrmqrOfqun0C45tMe3RoiKJMPvgWwLfY= github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU= github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho= github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator v9.31.0+incompatible h1:UA72EPEogEnq76ehGdEDp4Mit+3FDh548oRqwVgNsHA= github.com/go-playground/validator v9.31.0+incompatible/go.mod h1:yrEkQXlcI+PugkyDjY2bRrL/UBU4f3rvrgkN3V8JEig= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= @@ -107,6 +115,8 @@ github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -140,6 +150,8 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4 github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= @@ -149,6 +161,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg= github.com/joho/godotenv v1.4.0/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -156,6 +170,8 @@ github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e github.com/klauspost/compress v1.14.4/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.15.1 h1:y9FcTHGyrebwfP0ZZqFiaxTaiDnUrGkJkI+f583BL1A= github.com/klauspost/compress v1.15.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0= +github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -163,26 +179,43 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/labstack/echo/v4 v4.7.2/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks= github.com/labstack/echo/v4 v4.9.0 h1:wPOF1CE6gvt/kmbMR4dGzWvHMPT+sAEUJOwOTtvITVY= github.com/labstack/echo/v4 v4.9.0/go.mod h1:xkCDAdFCIf8jsFQ5NnbK7oqaF/yU1A1X20Ltm0OvSks= +github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= +github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM= github.com/labstack/gommon v0.3.1 h1:OomWaJXm7xR6L1HmEtGyQf26TEn7V6X88mktX9kee9o= github.com/labstack/gommon v0.3.1/go.mod h1:uW6kP17uPlLJsD3ijUYn3/M5bAxtlZhMI6m3MFxTMTM= +github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= +github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g= github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= +github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/nats-io/jwt/v2 v2.2.1-0.20220113022732-58e87895b296 h1:vU9tpM3apjYlLLeY23zRWJ9Zktr5jp+mloR942LEOpY= github.com/nats-io/jwt/v2 v2.2.1-0.20220113022732-58e87895b296/go.mod h1:0tqz9Hlu6bCBFLWAASKhE5vUA4c24L9KPUUgvwumE/k= github.com/nats-io/nats-server/v2 v2.7.4 h1:c+BZJ3rGzUKCBIM4IXO8uNT2u1vajGbD1kPA6wqCEaM= github.com/nats-io/nats-server/v2 v2.7.4/go.mod h1:1vZ2Nijh8tcyNe8BDVyTviCd9NYzRbubQYiEHsvOQWc= github.com/nats-io/nats.go v1.13.1-0.20220308171302-2f2f6968e98d h1:zJf4l8Kp67RIZhoVeniSLZs69SHNgjLHz0aNsqPPlx8= github.com/nats-io/nats.go v1.13.1-0.20220308171302-2f2f6968e98d/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= +github.com/nats-io/nats.go v1.37.0 h1:07rauXbVnnJvv1gfIyghFEo6lUcYRY0WXc3x7x0vUxE= +github.com/nats-io/nats.go v1.37.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8= github.com/nats-io/nkeys v0.3.0 h1:cgM5tL53EvYRU+2YLXIK0G2mJtK12Ft9oeooSZMA2G8= github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4= +github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI= +github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc= github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw= github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -209,24 +242,35 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= +github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= +github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mongodb.org/mongo-driver v1.9.1 h1:m078y9v7sBItkt1aaoe2YlvWEXcD263e1a4E1fBrJ1c= go.mongodb.org/mongo-driver v1.9.1/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY= +go.mongodb.org/mongo-driver v1.17.0 h1:Hp4q2MCjvY19ViwimTs00wHi7G4yzxh4/2+nTx8r40k= +go.mongodb.org/mongo-driver v1.17.0/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -244,11 +288,14 @@ golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWP golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 h1:S25/rfnfsMVgORT4/J61MJ7rdyseOZOyvLIrZEZ7s6s= golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -283,6 +330,7 @@ golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -321,6 +369,9 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -332,6 +383,8 @@ golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a h1:qfl7ob3DIEs3Ml9oLuPwY2N04gymzAW04WsUQHIClgM= golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -344,6 +397,9 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190130150945-aca44879d564/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -391,6 +447,12 @@ golang.org/x/sys v0.0.0-20220111092808-5a964db01320/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -404,6 +466,9 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -411,6 +476,8 @@ golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 h1:M73Iuj3xbbb9Uk1DYhzydthsj6oOd6l9bpuFcNoUvTs= golang.org/x/time v0.0.0-20220224211638-0e9765cccd65/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= +golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -460,6 +527,7 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -492,6 +560,8 @@ google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCID google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -559,6 +629,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= diff --git a/handlers/token/address.go b/handlers/token/address.go index ce0bca0..7eeb741 100644 --- a/handlers/token/address.go +++ b/handlers/token/address.go @@ -6,7 +6,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -34,7 +33,7 @@ func (i *AddressHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -56,7 +55,7 @@ func (i *AddressHandler) UsersCreate(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -78,7 +77,7 @@ func (i *AddressHandler) Get(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -95,7 +94,7 @@ func (i *AddressHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -112,7 +111,7 @@ func (i *AddressHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -134,7 +133,7 @@ func (i *AddressHandler) UsersUpdate(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -156,7 +155,7 @@ func (i *AddressHandler) Delete(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -181,7 +180,7 @@ func (i *AddressHandler) UsersDelete(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/artist.go b/handlers/token/artist.go index 8017cec..fd05513 100644 --- a/handlers/token/artist.go +++ b/handlers/token/artist.go @@ -5,7 +5,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -30,7 +29,7 @@ func (i *ArtistHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return c.ErrorResponse(err) } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -73,7 +72,7 @@ func (i *ArtistHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return c.ErrorResponse(err) } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -87,10 +86,10 @@ func (i *ArtistHandler) Update(cc echo.Context) (err error) { func (i *ArtistHandler) Delete(cc echo.Context) (err error) { c := cc.(vcago.Context) body := new(models.ArtistParam) - if c.BindAndValidate(body); err != nil { + if err = c.BindAndValidate(body); err != nil { return c.ErrorResponse(err) } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/assets.go b/handlers/token/assets.go index 58cf04e..197a5e8 100644 --- a/handlers/token/assets.go +++ b/handlers/token/assets.go @@ -4,7 +4,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -25,7 +24,7 @@ func (i *AssetsHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/avatar.go b/handlers/token/avatar.go index 3f6ae0e..707dd3d 100644 --- a/handlers/token/avatar.go +++ b/handlers/token/avatar.go @@ -8,7 +8,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" "go.mongodb.org/mongo-driver/mongo/gridfs" ) @@ -29,7 +28,7 @@ func (i *AvatarHandler) Routes(group *echo.Group) { func (i *AvatarHandler) Upload(cc echo.Context) (err error) { c := cc.(vcago.Context) - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -81,7 +80,7 @@ func (i *AvatarHandler) Delete(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/crew.go b/handlers/token/crew.go index ef464ef..37d4c4a 100644 --- a/handlers/token/crew.go +++ b/handlers/token/crew.go @@ -6,7 +6,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -33,7 +32,7 @@ func (i *CrewHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -55,7 +54,7 @@ func (i *CrewHandler) Get(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -85,7 +84,7 @@ func (i *CrewHandler) GetAsMember(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -102,7 +101,7 @@ func (i *CrewHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -119,7 +118,7 @@ func (i *CrewHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -141,7 +140,7 @@ func (i *CrewHandler) Delete(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/default.go b/handlers/token/default.go index ef3159d..3235816 100644 --- a/handlers/token/default.go +++ b/handlers/token/default.go @@ -1,9 +1,10 @@ package token import ( + "pool-backend/models" + "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" ) var refreshCookie = vcago.RefreshCookieMiddleware() -var accessCookie = vcago.AccessCookieMiddleware(&vcapool.AccessToken{}) +var accessCookie = vcago.AccessCookieMiddleware(&models.AccessToken{}) diff --git a/handlers/token/deposit.go b/handlers/token/deposit.go index 4d5b4a3..37ad2ca 100644 --- a/handlers/token/deposit.go +++ b/handlers/token/deposit.go @@ -6,7 +6,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -31,7 +30,7 @@ func (i *DepositHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -49,7 +48,7 @@ func (i *DepositHandler) Get(cc echo.Context) (err error) { return } result := new([]models.Deposit) - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -65,7 +64,7 @@ func (i *DepositHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -82,7 +81,7 @@ func (i *DepositHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -98,7 +97,7 @@ func (i *DepositHandler) Sync(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/events.go b/handlers/token/events.go index 4c782d8..0a0c347 100644 --- a/handlers/token/events.go +++ b/handlers/token/events.go @@ -7,7 +7,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -39,7 +38,7 @@ func (i *EventHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -62,15 +61,17 @@ func (i *EventHandler) Get(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } + result := new([]models.ListEvent) - if result, err = dao.EventGet(c.Ctx(), body, token); err != nil { + var listSize int64 + if result, listSize, err = dao.EventGet(body, token); err != nil { return } - return c.Selected(result) + return c.Listed(result, listSize) } func (i *EventHandler) GetByID(cc echo.Context) (err error) { @@ -79,7 +80,7 @@ func (i *EventHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -109,7 +110,7 @@ func (i *EventHandler) GetPrivateDetails(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -127,10 +128,11 @@ func (i *EventHandler) GetPublic(cc echo.Context) (err error) { return } result := new([]models.EventPublic) - if result, err = dao.EventGetPublic(c.Ctx(), body); err != nil { + var listSize int64 + if result, listSize, err = dao.EventGetPublic(body); err != nil { return } - return c.Selected(result) + return c.Listed(result, listSize) } func (i *EventHandler) GetByEventAsp(cc echo.Context) (err error) { @@ -139,7 +141,7 @@ func (i *EventHandler) GetByEventAsp(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -156,7 +158,7 @@ func (i *EventHandler) GetEmailEvents(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -173,7 +175,7 @@ func (i *EventHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -196,7 +198,7 @@ func (i *EventHandler) Sync(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -215,7 +217,7 @@ func (i *EventHandler) Delete(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/login.go b/handlers/token/login.go index cf987dd..f64ccf5 100644 --- a/handlers/token/login.go +++ b/handlers/token/login.go @@ -9,7 +9,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -39,7 +38,7 @@ func (i *LoginHandler) Callback(cc echo.Context) (err error) { } tokenUser := new(vmod.User) if tokenUser, err = HydraClient.Callback(c.Ctx(), body); err != nil { - return + return vcago.NewBadRequest("Error in callback. Maybe testlogin and oidc skip is enabeled in .env?", err.Error()) } result := new(models.User) if err = dao.UserCollection.AggregateOne( @@ -50,6 +49,7 @@ func (i *LoginHandler) Callback(cc echo.Context) (err error) { return } if vmdb.ErrNoDocuments(err) { + err = nil userDatabase := models.NewUserDatabase(tokenUser) if result, err = dao.UserInsert(c.Ctx(), userDatabase); err != nil { @@ -75,7 +75,7 @@ func (i *LoginHandler) Callback(cc echo.Context) (err error) { func (i *LoginHandler) LoginAPI(cc echo.Context) (err error) { c := cc.(vcago.Context) body := new(models.UserEmail) - if c.BindAndValidate(body); err != nil { + if err = c.BindAndValidate(body); err != nil { return } result := new(models.User) @@ -120,7 +120,7 @@ func (i *LoginHandler) Refresh(cc echo.Context) (err error) { func (i *LoginHandler) Logout(cc echo.Context) (err error) { c := cc.(vcago.Context) - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/mailbox.go b/handlers/token/mailbox.go index 85d31b6..36e4af3 100644 --- a/handlers/token/mailbox.go +++ b/handlers/token/mailbox.go @@ -5,7 +5,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -26,7 +25,7 @@ func (i *MailboxHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/message.go b/handlers/token/message.go index d7a4b07..0b80953 100644 --- a/handlers/token/message.go +++ b/handlers/token/message.go @@ -6,7 +6,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -31,7 +30,7 @@ func (i *MessageHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -48,7 +47,7 @@ func (i *MessageHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -65,7 +64,7 @@ func (i *MessageHandler) Update(cc echo.Context) (err error) { if err = vcago.BindAndValidate(c, body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -82,7 +81,7 @@ func (i *MessageHandler) Delete(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -98,7 +97,7 @@ func (i *MessageHandler) SendCycular(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/newsletter.go b/handlers/token/newsletter.go index 0a6a103..3357187 100644 --- a/handlers/token/newsletter.go +++ b/handlers/token/newsletter.go @@ -6,7 +6,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -28,7 +27,7 @@ func (i *NewsletterHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -50,7 +49,7 @@ func (i *NewsletterHandler) Delete(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/organisations.go b/handlers/token/organisations.go new file mode 100644 index 0000000..7873b5f --- /dev/null +++ b/handlers/token/organisations.go @@ -0,0 +1,110 @@ +package token + +import ( + "pool-backend/dao" + "pool-backend/models" + + "github.com/Viva-con-Agua/vcago" + "github.com/labstack/echo/v4" +) + +type OrganisationHandler struct { + vcago.Handler +} + +var Organisation = &OrganisationHandler{*vcago.NewHandler("organisation")} + +func (i *OrganisationHandler) Routes(group *echo.Group) { + group.Use(i.Context) + group.POST("", i.Create, accessCookie) + group.GET("", i.Get) + group.GET("/:id", i.GetByID) + group.PUT("", i.Update, accessCookie) + group.DELETE("/:id", i.Delete, accessCookie) +} + +func (i *OrganisationHandler) Create(cc echo.Context) (err error) { + c := cc.(vcago.Context) + body := new(models.OrganisationCreate) + if err = c.BindAndValidate(body); err != nil { + return + } + token := new(models.AccessToken) + if err = c.AccessToken(token); err != nil { + return + } + result := new(models.Organisation) + if result, err = dao.OrganisationInsert(c.Ctx(), body, token); err != nil { + return + } + //go func() { + // if err = dao.IDjango.Post(result, "/v1/pool/organisation/"); err != nil { + // log.Print(err) + // } + //}() + return c.Created(result) +} + +func (i *OrganisationHandler) Get(cc echo.Context) (err error) { + c := cc.(vcago.Context) + body := new(models.OrganisationQuery) + if err = c.BindAndValidate(body); err != nil { + return + } + result := new([]models.Organisation) + if result, err = dao.OrganisationGet(c.Ctx(), body); err != nil { + return + } + return c.Selected(result) +} + +func (i *OrganisationHandler) GetByID(cc echo.Context) (err error) { + c := cc.(vcago.Context) + body := new(models.OrganisationParam) + if err = c.BindAndValidate(body); err != nil { + return + } + result := new(models.Organisation) + if result, err = dao.OrganisationGetByID(c.Ctx(), body); err != nil { + return + } + return c.Selected(result) +} + +func (i *OrganisationHandler) Update(cc echo.Context) (err error) { + c := cc.(vcago.Context) + body := new(models.OrganisationUpdate) + if err = c.BindAndValidate(body); err != nil { + return + } + token := new(models.AccessToken) + if err = c.AccessToken(token); err != nil { + return + } + result := new(models.Organisation) + if result, err = dao.OrganisationUpdate(c.Ctx(), body, token); err != nil { + return + } + //go func() { + // if err = dao.IDjango.Post(body, "/v1/pool/organisation/"); err != nil { + // log.Print(err) + // } + //}() + return c.Updated(result) +} + +func (i *OrganisationHandler) Delete(cc echo.Context) (err error) { + c := cc.(vcago.Context) + body := new(models.OrganisationParam) + if err = c.BindAndValidate(body); err != nil { + return + } + token := new(models.AccessToken) + if err = c.AccessToken(token); err != nil { + return + } + if err = dao.OrganisationDelete(c.Ctx(), body, token); err != nil { + return + } + return c.Deleted(body.ID) +} diff --git a/handlers/token/organizer.go b/handlers/token/organizer.go index 61ed940..10af508 100644 --- a/handlers/token/organizer.go +++ b/handlers/token/organizer.go @@ -5,7 +5,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -30,7 +29,7 @@ func (i *OrganizerHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return c.ErrorResponse(err) } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -73,7 +72,7 @@ func (i *OrganizerHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return c.ErrorResponse(err) } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -87,10 +86,10 @@ func (i *OrganizerHandler) Update(cc echo.Context) (err error) { func (i *OrganizerHandler) Delete(cc echo.Context) (err error) { c := cc.(vcago.Context) body := new(models.OrganizerParam) - if c.BindAndValidate(body); err != nil { + if err = c.BindAndValidate(body); err != nil { return c.ErrorResponse(err) } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/participation.go b/handlers/token/participation.go index 4a8b3f0..499502b 100644 --- a/handlers/token/participation.go +++ b/handlers/token/participation.go @@ -5,7 +5,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -33,7 +32,7 @@ func (i *ParticipationHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -51,7 +50,7 @@ func (i *ParticipationHandler) Get(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -68,7 +67,7 @@ func (i *ParticipationHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -85,7 +84,7 @@ func (i *ParticipationHandler) GetByUser(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -102,7 +101,7 @@ func (i *ParticipationHandler) GetByEvent(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -119,7 +118,7 @@ func (i *ParticipationHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -136,7 +135,7 @@ func (i *ParticipationHandler) Delete(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/profile.go b/handlers/token/profile.go index 605e447..ff29b23 100644 --- a/handlers/token/profile.go +++ b/handlers/token/profile.go @@ -7,7 +7,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -31,7 +30,7 @@ func (i *ProfileHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -53,7 +52,7 @@ func (i *ProfileHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -75,7 +74,7 @@ func (i *ProfileHandler) UserSync(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -101,7 +100,7 @@ func (i *ProfileHandler) UsersUpdate(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/receipts.go b/handlers/token/receipts.go new file mode 100644 index 0000000..a1dbab4 --- /dev/null +++ b/handlers/token/receipts.go @@ -0,0 +1,99 @@ +package token + +import ( + "bytes" + "net/http" + "pool-backend/dao" + "pool-backend/models" + + "github.com/Viva-con-Agua/vcago" + "github.com/Viva-con-Agua/vcago/vmod" + "github.com/labstack/echo/v4" +) + +type ReceiptFileHandler struct { + vcago.Handler +} + +var ReceiptFile = &ReceiptFileHandler{*vcago.NewHandler("receipt")} + +func (i *ReceiptFileHandler) Routes(group *echo.Group) { + group.Use(i.Context) + group.POST("", i.Upload, accessCookie) + group.GET("/:id", i.GetByID, accessCookie) + group.GET("/zip/:id", i.GetZipByID, accessCookie) + group.DELETE("/:id", i.DeleteByID, accessCookie) + +} + +func (i *ReceiptFileHandler) Upload(cc echo.Context) (err error) { + c := cc.(vcago.Context) + token := new(models.AccessToken) + if err = c.AccessToken(token); err != nil { + return + } + body := new(models.ReceiptFileCreate) + if err = c.BindFormDataAndValidate("body", body); err != nil { + return + } + file := new(vmod.File) + if file, err = c.BindFormDataFile("image"); err != nil { + return + } + var result *models.ReceiptFile + if result, err = dao.ReceiptFileCreate(c.Ctx(), body, file, token); err != nil { + return + } + return c.Created(result) +} + +func (i *ReceiptFileHandler) GetByID(cc echo.Context) (err error) { + c := cc.(vcago.Context) + token := new(models.AccessToken) + if err = c.AccessToken(token); err != nil { + return + } + body := new(vmod.IDParam) + if err = c.BindAndValidate(body); err != nil { + return + } + var result []byte + if result, err = dao.ReceiptFileGetByID(c.Ctx(), body, token); err != nil { + return + } + return c.Stream(http.StatusOK, "image/png", bytes.NewReader(result)) +} + +func (i *ReceiptFileHandler) GetZipByID(cc echo.Context) (err error) { + c := cc.(vcago.Context) + token := new(models.AccessToken) + if err = c.AccessToken(token); err != nil { + return + } + body := new(vmod.IDParam) + if err = c.BindAndValidate(body); err != nil { + return + } + var result []byte + if result, err = dao.ReceiptFileZipGetByID(c.Ctx(), body, token); err != nil { + return + } + return c.Stream(http.StatusOK, "application/zip", bytes.NewReader(result)) +} + +func (i *ReceiptFileHandler) DeleteByID(cc echo.Context) (err error) { + c := cc.(vcago.Context) + token := new(models.AccessToken) + if err = c.AccessToken(token); err != nil { + return + } + body := new(vmod.IDParam) + if err = c.BindAndValidate(body); err != nil { + return + } + var result *vmod.DeletedResponse + if result, err = dao.ReceiptFileDeleteByID(c.Ctx(), body, token); err != nil { + return + } + return c.Deleted(result) +} diff --git a/handlers/token/role_history.go b/handlers/token/role_history.go index 037f782..62ab49a 100644 --- a/handlers/token/role_history.go +++ b/handlers/token/role_history.go @@ -6,7 +6,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -31,7 +30,7 @@ func (i *RoleHistoryHandler) Create(cc echo.Context) (err error) { if c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -48,7 +47,7 @@ func (i *RoleHistoryHandler) CreateBulk(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -69,7 +68,7 @@ func (i *RoleHistoryHandler) ConfirmSelection(cc echo.Context) (err error) { if c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -103,7 +102,7 @@ func (i *RoleHistoryHandler) Get(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -121,7 +120,7 @@ func (i *RoleHistoryHandler) Delete(cc echo.Context) (err error) { if c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/roles.go b/handlers/token/roles.go index eedfd10..292d165 100644 --- a/handlers/token/roles.go +++ b/handlers/token/roles.go @@ -7,7 +7,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -30,7 +29,7 @@ func (i *RoleHandler) Create(cc echo.Context) (err error) { if c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -52,7 +51,7 @@ func (i *RoleHandler) CreateBulk(cc echo.Context) (err error) { if c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -69,7 +68,7 @@ func (i *RoleHandler) CreateBulk(cc echo.Context) (err error) { if err = dao.RoleNotification(c.Ctx(), userRolesMap); err != nil { return } - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { dao.RoleAdminNotification(c.Ctx(), &models.CrewParam{ID: body.CrewID}) } return c.Created(result) @@ -81,7 +80,7 @@ func (i *RoleHandler) Delete(cc echo.Context) (err error) { if c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/source.go b/handlers/token/source.go index 3bf279b..1c37c88 100644 --- a/handlers/token/source.go +++ b/handlers/token/source.go @@ -6,7 +6,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -31,7 +30,7 @@ func (i *SourceHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -49,7 +48,7 @@ func (i *SourceHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/taking.go b/handlers/token/taking.go index f988f85..64e3785 100644 --- a/handlers/token/taking.go +++ b/handlers/token/taking.go @@ -6,7 +6,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -32,7 +31,7 @@ func (i *TakingHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -49,7 +48,7 @@ func (i TakingHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -66,11 +65,11 @@ func (i TakingHandler) Get(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } - result := new([]models.Taking) + var result []models.Taking var listSize int64 if result, listSize, err = dao.TakingGet(c.Ctx(), body, token); err != nil { return @@ -84,7 +83,7 @@ func (i TakingHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -101,7 +100,7 @@ func (i TakingHandler) DeleteByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/user_active.go b/handlers/token/user_active.go index 06c1593..b24a153 100644 --- a/handlers/token/user_active.go +++ b/handlers/token/user_active.go @@ -6,7 +6,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -31,7 +30,7 @@ func (i *ActiveHandler) Request(cc echo.Context) (err error) { //load context c := cc.(vcago.Context) //get access token - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -52,7 +51,7 @@ func (i *ActiveHandler) Confirm(cc echo.Context) (err error) { return } //get requested user from token - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -71,7 +70,7 @@ func (i *ActiveHandler) Reject(cc echo.Context) (err error) { return } //get requested user from token - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -85,7 +84,7 @@ func (i *ActiveHandler) Reject(cc echo.Context) (err error) { func (i *ActiveHandler) Withdraw(cc echo.Context) (err error) { c := cc.(vcago.Context) - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/user_crew.go b/handlers/token/user_crew.go index 71b4649..f318f43 100644 --- a/handlers/token/user_crew.go +++ b/handlers/token/user_crew.go @@ -6,7 +6,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -32,7 +31,7 @@ func (i *UserCrewHandler) Create(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -54,7 +53,7 @@ func (i *UserCrewHandler) UsersCreate(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -76,7 +75,7 @@ func (i *UserCrewHandler) Update(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -93,7 +92,7 @@ func (i *UserCrewHandler) UsersUpdate(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -110,7 +109,7 @@ func (i *UserCrewHandler) UsersDelete(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -131,7 +130,7 @@ func (i *UserCrewHandler) UsersDelete(cc echo.Context) (err error) { func (i *UserCrewHandler) Delete(cc echo.Context) (err error) { c := cc.(vcago.Context) - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/user_nvm.go b/handlers/token/user_nvm.go index fa5e4c5..63a9b96 100644 --- a/handlers/token/user_nvm.go +++ b/handlers/token/user_nvm.go @@ -7,7 +7,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -27,7 +26,7 @@ func (i *NVMHandler) Routes(group *echo.Group) { func (i *NVMHandler) Confirm(cc echo.Context) (err error) { c := cc.(vcago.Context) - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -50,7 +49,7 @@ func (i *NVMHandler) ConfirmUser(cc echo.Context) (err error) { return } //get requested user from token - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -72,7 +71,7 @@ func (i *NVMHandler) RejectUser(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -90,7 +89,7 @@ func (i *NVMHandler) RejectUser(cc echo.Context) (err error) { func (i *NVMHandler) Withdraw(cc echo.Context) (err error) { c := cc.(vcago.Context) - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/handlers/token/users.go b/handlers/token/users.go index e08e1dc..2446a77 100644 --- a/handlers/token/users.go +++ b/handlers/token/users.go @@ -6,7 +6,6 @@ import ( "pool-backend/models" "github.com/Viva-con-Agua/vcago" - "github.com/Viva-con-Agua/vcapool" "github.com/labstack/echo/v4" ) @@ -20,6 +19,7 @@ func (i *UserHandler) Routes(group *echo.Group) { group.Use(i.Context) group.GET("", i.Get, accessCookie) group.GET("/:id", i.GetByID, accessCookie) + group.PUT("/organisation", i.UpdateOrganisation, accessCookie) group.GET("/crew", i.GetUsersByCrew, accessCookie) group.GET("/crew/public", i.GetMinimal, accessCookie) group.DELETE("/:id", i.Delete, accessCookie) @@ -31,7 +31,7 @@ func (i *UserHandler) Get(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -49,7 +49,7 @@ func (i *UserHandler) GetByID(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -66,7 +66,7 @@ func (i *UserHandler) GetUsersByCrew(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -83,7 +83,7 @@ func (i *UserHandler) GetMinimal(cc echo.Context) (err error) { if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } @@ -94,13 +94,30 @@ func (i *UserHandler) GetMinimal(cc echo.Context) (err error) { return c.Selected(result) } +func (i *UserHandler) UpdateOrganisation(cc echo.Context) (err error) { + c := cc.(vcago.Context) + body := new(models.UserOrganisationUpdate) + if err = c.BindAndValidate(body); err != nil { + return + } + token := new(models.AccessToken) + if err = c.AccessToken(token); err != nil { + return + } + result := new(models.User) + if result, err = dao.UserOrganisationUpdate(c.Ctx(), body, token); err != nil { + return + } + return c.Updated(result) +} + func (i *UserHandler) Delete(cc echo.Context) (err error) { c := cc.(vcago.Context) body := new(models.UserParam) if err = c.BindAndValidate(body); err != nil { return } - token := new(vcapool.AccessToken) + token := new(models.AccessToken) if err = c.AccessToken(token); err != nil { return } diff --git a/models/access_token.go b/models/access_token.go new file mode 100644 index 0000000..5c8208d --- /dev/null +++ b/models/access_token.go @@ -0,0 +1,43 @@ +package models + +import ( + "github.com/Viva-con-Agua/vcago" + "github.com/Viva-con-Agua/vcago/vmod" + "github.com/golang-jwt/jwt" +) + +type AccessToken struct { + ID string `json:"id,omitempty" bson:"_id"` + Email string `json:"email" bson:"email" validate:"required,email"` + FirstName string `bson:"first_name" json:"first_name" validate:"required"` + LastName string `bson:"last_name" json:"last_name" validate:"required"` + FullName string `bson:"full_name" json:"full_name"` + DisplayName string `bson:"display_name" json:"display_name"` + Roles vmod.RoleListCookie `json:"system_roles" bson:"system_roles"` + Country string `bson:"country" json:"country"` + PrivacyPolicy bool `bson:"privacy_policy" json:"privacy_policy"` + Confirmd bool `bson:"confirmed" json:"confirmed"` + LastUpdate string `bson:"last_update" json:"last_update"` + Phone string `json:"phone"` + Gender string `json:"gender"` + Birthdate int64 `json:"birthdate"` + CrewName string `json:"crew_name"` + CrewID string `json:"crew_id"` + OrganisationID string `json:"organisation_id"` + CrewEmail string `json:"crew_email"` + AddressID string `json:"address_id"` + PoolRoles vmod.RoleListCookie `json:"pool_roles"` + ActiveState string `json:"active_state"` + NVMState string `json:"nvm_state"` + AvatarID string `json:"avatar_id"` + MailboxID string `json:"mailbox_id"` + Modified vmod.Modified `json:"modified"` + jwt.StandardClaims +} + +func (token *AccessToken) AccessPermission() (err error) { + if !token.Roles.Validate("admin") { + return vcago.NewPermissionDenied(OrganisationCollection) + } + return +} diff --git a/models/active.go b/models/active.go index 7d880ed..86b90ce 100644 --- a/models/active.go +++ b/models/active.go @@ -6,7 +6,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -70,24 +69,24 @@ func ActiveRequest() *ActiveUpdate { } } -func ActiveRequestPermission(token *vcapool.AccessToken) (err error) { +func ActiveRequestPermission(token *AccessToken) (err error) { if token.CrewID == "" { return vcago.NewBadRequest(ActiveCollection, "not an crew member") } return } -func ActivePermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") && !token.PoolRoles.Validate("network;operation") { +func ActivePermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") && !token.PoolRoles.Validate("network;operation") { return vcago.NewBadRequest(ActiveCollection, "permission denied") } return } -func (i *ActiveParam) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *ActiveParam) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("user_id", i.UserID) - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } return filter.Bson() diff --git a/models/address.go b/models/address.go index 4a5bfcd..b595513 100644 --- a/models/address.go +++ b/models/address.go @@ -4,7 +4,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -122,16 +121,16 @@ func (i *AddressImport) Address(userID string) (r *Address) { } } -func AddressPermission(token *vcapool.AccessToken) (err error) { +func AddressPermission(token *AccessToken) (err error) { if !token.Roles.Validate("admin") { return vcago.NewPermissionDenied(CrewCollection) } return } -func (i *AddressQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *AddressQuery) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if token.Roles.Validate("employee;admin") { + if token.Roles.Validate("admin;employee;pool_employee") { filter.EqualStringList("_id", i.ID) filter.EqualStringList("crew_id", i.CrewID) filter.EqualStringList("user_id", i.UserID) @@ -145,7 +144,7 @@ func (i *AddressQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { return filter.Bson() } -func (i *AddressUpdate) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *AddressUpdate) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) filter.EqualString("user_id", token.ID) @@ -158,7 +157,7 @@ func (i *AddressUpdate) Match() bson.D { return filter.Bson() } -func (i *AddressParam) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *AddressParam) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) filter.EqualString("user_id", token.ID) diff --git a/models/artist.go b/models/artist.go index b27b59f..a29685d 100644 --- a/models/artist.go +++ b/models/artist.go @@ -1,10 +1,11 @@ package models import ( + "strings" + "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -37,20 +38,30 @@ type ( var ArtistCollection = "artists" -func ArtistPermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { +func ArtistPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { return vcago.NewPermissionDenied(ArtistCollection) } return } -func ArtistDeletePermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") { +func ArtistDeletePermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") { return vcago.NewPermissionDenied(ArtistCollection) } return } +func ToArtistList(artists []Artist) string { + names := make([]string, len(artists)) + for i, artist := range artists { + names[i] = artist.Name + } + + result := strings.Join(names, ", ") + return result +} + func (i *ArtistCreate) Artist() *Artist { return &Artist{ ID: uuid.NewString(), diff --git a/models/avatar.go b/models/avatar.go index 8cb5e35..85d613a 100644 --- a/models/avatar.go +++ b/models/avatar.go @@ -5,7 +5,6 @@ import ( "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -36,7 +35,7 @@ var AvatarCollection = "avatar" var FSChunkCollection = "fs.chunks" var FSFilesCollection = "fs.files" -func NewAvatar(token *vcapool.AccessToken) *Avatar { +func NewAvatar(token *AccessToken) *Avatar { id := uuid.NewString() return &Avatar{ ID: id, @@ -46,14 +45,14 @@ func NewAvatar(token *vcapool.AccessToken) *Avatar { } } -func (i *AvatarUpdate) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *AvatarUpdate) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) filter.EqualString("user_id", token.ID) return filter.Bson() } -func (i *AvatarParam) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *AvatarParam) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) filter.EqualString("user_id", token.ID) diff --git a/models/crew.go b/models/crew.go index 7e71892..781066d 100644 --- a/models/crew.go +++ b/models/crew.go @@ -4,32 +4,33 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) type ( CrewCreate struct { - Name string `json:"name" bson:"name"` - Email string `json:"email" bson:"email"` - Abbreviation string `json:"abbreviation" bson:"abbreviation"` - Mattermost string `bson:"mattermost_username" json:"mattermost_username"` - Additional string `json:"additional" bson:"additional"` - Cities []City `json:"cities" bson:"cities"` - Status string `json:"status" bson:"status"` - AspSelection string `json:"asp_selection" bson:"asp_selection"` + Name string `json:"name" bson:"name"` + Email string `json:"email" bson:"email"` + Abbreviation string `json:"abbreviation" bson:"abbreviation"` + Mattermost string `bson:"mattermost_username" json:"mattermost_username"` + Additional string `json:"additional" bson:"additional"` + Cities []City `json:"cities" bson:"cities"` + OrganisationID string `json:"organisation_id" bson:"organisation_id"` + Status string `json:"status" bson:"status"` + AspSelection string `json:"asp_selection" bson:"asp_selection"` } CrewUpdate struct { - ID string `json:"id,omitempty" bson:"_id"` - Name string `json:"name" bson:"name"` - Email string `json:"email" bson:"email"` - Abbreviation string `json:"abbreviation" bson:"abbreviation"` - Mattermost string `bson:"mattermost_username" json:"mattermost_username"` - Additional string `json:"additional" bson:"additional"` - Status string `json:"status" bson:"status"` - AspSelection string `json:"asp_selection" bson:"asp_selection"` - Cities []City `json:"cities" bson:"cities"` + ID string `json:"id,omitempty" bson:"_id"` + Name string `json:"name" bson:"name"` + Email string `json:"email" bson:"email"` + Abbreviation string `json:"abbreviation" bson:"abbreviation"` + Mattermost string `bson:"mattermost_username" json:"mattermost_username"` + OrganisationID string `json:"organisation_id" bson:"organisation_id"` + Additional string `json:"additional" bson:"additional"` + Status string `json:"status" bson:"status"` + AspSelection string `json:"asp_selection" bson:"asp_selection"` + Cities []City `json:"cities" bson:"cities"` } CrewUpdateASP struct { ID string `json:"id,omitempty" bson:"_id"` @@ -37,23 +38,27 @@ type ( Additional string `json:"additional" bson:"additional"` } Crew struct { - ID string `json:"id,omitempty" bson:"_id"` - Name string `json:"name" bson:"name"` - Email string `json:"email" bson:"email"` - Abbreviation string `json:"abbreviation" bson:"abbreviation"` - Mattermost string `bson:"mattermost_username" json:"mattermost_username"` - Additional string `json:"additional" bson:"additional"` - MailboxID string `json:"mailbox_id" bson:"mailbox_id"` - Cities []City `json:"cities" bson:"cities"` - Status string `json:"status" bson:"status"` - AspSelection string `json:"asp_selection" bson:"asp_selection"` - Modified vmod.Modified `json:"modified" bson:"modified"` + ID string `json:"id,omitempty" bson:"_id"` + Name string `json:"name" bson:"name"` + Email string `json:"email" bson:"email"` + Abbreviation string `json:"abbreviation" bson:"abbreviation"` + Mattermost string `bson:"mattermost_username" json:"mattermost_username"` + Additional string `json:"additional" bson:"additional"` + OrganisationID string `json:"organisation_id" bson:"organisation_id"` + Organisation Organisation `json:"organisation" bson:"organisation"` + MailboxID string `json:"mailbox_id" bson:"mailbox_id"` + Cities []City `json:"cities" bson:"cities"` + Status string `json:"status" bson:"status"` + AspSelection string `json:"asp_selection" bson:"asp_selection"` + Modified vmod.Modified `json:"modified" bson:"modified"` } CrewPublic struct { - ID string `json:"id,omitempty" bson:"_id"` - Name string `json:"name" bson:"name"` - Cities []City `json:"cities" bson:"cities"` - Mattermost string `bson:"mattermost_username" json:"mattermost_username"` + ID string `json:"id,omitempty" bson:"_id"` + Name string `json:"name" bson:"name"` + Cities []City `json:"cities" bson:"cities"` + Organisation Organisation `json:"organisation" bson:"organisation"` + OrganisationID string `json:"organisation_id" bson:"organisation_id"` + Mattermost string `bson:"mattermost_username" json:"mattermost_username"` } CrewName struct { ID string `json:"id,omitempty" bson:"_id"` @@ -68,15 +73,18 @@ type ( } CrewList []Crew CrewQuery struct { - ID []string `query:"id,omitempty" qs:"id"` - Name string `query:"name" qs:"name"` - Status string `json:"status" bson:"status"` - Email string `query:"email" qs:"email"` + ID []string `query:"id,omitempty" qs:"id"` + Name string `query:"name" qs:"name"` + Status string `json:"status" qs:"status"` + Organisation string `json:"organisation_name" qs:"organisation_name"` + OrganisationID []string `json:"organisation_id" qs:"organisation_id"` + Email string `query:"email" qs:"email"` } CrewSimple struct { - ID string `json:"id" bson:"id"` - Name string `json:"name" bson:"name"` - Email string `json:"email" bson:"email"` + ID string `json:"id" bson:"id"` + Name string `json:"name" bson:"name"` + Email string `json:"email" bson:"email"` + Organisation Organisation `json:"organisation" bson:"organisation"` } CrewParam struct { ID string `param:"id"` @@ -85,15 +93,20 @@ type ( var CrewCollection = "crews" -func CrewPermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") { +func CrewPermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") { return vcago.NewPermissionDenied(CrewCollection) } return } +func CrewPipeline() *vmdb.Pipeline { + pipe := vmdb.NewPipeline() + pipe.LookupUnwind(OrganisationCollection, "organisation_id", "_id", "organisation") + return pipe +} -func CrewUpdatePermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPRole)) { +func CrewUpdatePermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPRole)) { return vcago.NewPermissionDenied(CrewCollection) } return @@ -101,15 +114,16 @@ func CrewUpdatePermission(token *vcapool.AccessToken) (err error) { func (i *CrewCreate) Crew() *Crew { return &Crew{ - ID: uuid.NewString(), - Name: i.Name, - Email: i.Email, - Mattermost: i.Mattermost, - Abbreviation: i.Abbreviation, - Additional: i.Additional, - Cities: i.Cities, - Status: i.Status, - Modified: vmod.NewModified(), + ID: uuid.NewString(), + Name: i.Name, + Email: i.Email, + Mattermost: i.Mattermost, + Abbreviation: i.Abbreviation, + Additional: i.Additional, + OrganisationID: i.OrganisationID, + Cities: i.Cities, + Status: i.Status, + Modified: vmod.NewModified(), } } @@ -124,6 +138,7 @@ func (i *CrewUpdate) ToCrewUpdateASP() *CrewUpdateASP { func (i *CrewQuery) Filter() bson.D { filter := vmdb.NewFilter() filter.EqualStringList("_id", i.ID) + filter.EqualStringList("organisation_id", i.OrganisationID) filter.LikeString("email", i.Email) filter.LikeString("status", i.Status) filter.LikeString("name", i.Name) @@ -139,16 +154,16 @@ func (i *CrewQuery) ActiveFilter() bson.D { return filter.Bson() } -func (i *CrewQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *CrewQuery) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", token.CrewID) filter.LikeString("status", "active") return filter.Bson() } -func (i *CrewUpdate) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *CrewUpdate) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("_id", token.CrewID) } else { filter.EqualString("_id", i.ID) @@ -156,9 +171,9 @@ func (i *CrewUpdate) PermittedFilter(token *vcapool.AccessToken) bson.D { return filter.Bson() } -func (i *CrewParam) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *CrewParam) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("_id", token.CrewID) } else { filter.EqualString("_id", i.ID) diff --git a/models/deposit.go b/models/deposit.go index edbb12b..2870457 100644 --- a/models/deposit.go +++ b/models/deposit.go @@ -4,7 +4,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -21,18 +20,18 @@ type ( Money vmod.Money `json:"money" bson:"money"` } DepositUnit struct { - ID string `json:"id" bson:"_id"` - TakingID string `json:"taking_id" bson:"taking_id"` - Taking TakingDatabase `json:"taking" bson:"taking"` - Money vmod.Money `json:"money" bson:"money"` - DepositID string `json:"deposit_id" bson:"deposit_id"` - Status string `json:"status" bson:"status"` - Modified vmod.Modified `json:"modified" bson:"modified"` + ID string `json:"id" bson:"_id"` + TakingID string `json:"taking_id" bson:"taking_id"` + Taking Taking `json:"taking" bson:"taking"` + Money vmod.Money `json:"money" bson:"money"` + DepositID string `json:"deposit_id" bson:"deposit_id"` + Status string `json:"status" bson:"status"` + Modified vmod.Modified `json:"modified" bson:"modified"` } DepositUnitTaking struct { ID string `json:"id" bson:"_id"` TakingID string `json:"taking_id" bson:"taking_id"` - Taking TakingDatabase `json:"taking" bson:"taking"` + Taking Taking `json:"taking" bson:"taking"` Money vmod.Money `json:"money" bson:"money"` DepositID string `json:"deposit_id" bson:"deposit_id"` Deposit DepositDatabase `json:"deposit" bson:"deposit"` @@ -80,13 +79,13 @@ type ( Creator User `json:"creator" bson:"creator"` Confirmer User `json:"confirmer" bson:"confirmer"` HasExternal bool `json:"has_external" bson:"has_external"` + Receipts []ReceiptFile `json:"receipts" bson:"receipts"` External External `json:"external" bson:"external"` Modified vmod.Modified `json:"modified" bson:"modified"` } DepositQuery struct { ID []string `query:"id"` Name string `query:"deposit_unit_name"` - Search string `query:"search"` ReasonForPayment string `query:"reason_for_payment"` CrewID []string `query:"crew_id"` Status []string `query:"deposit_status"` @@ -97,8 +96,7 @@ type ( UpdatedFrom string `query:"updated_from" qs:"updated_from"` CreatedTo string `query:"created_to" qs:"created_to"` CreatedFrom string `query:"created_from" qs:"created_from"` - SortField string `query:"sort"` - SortDirection string `query:"sort_dir"` + vmdb.Query } DepositParam struct { ID string `param:"id"` @@ -110,14 +108,14 @@ var DepositCollection = "deposits" var DepositUnitCollection = "deposit_units" var DepositUnitTakingView = "deposit_unit_taking" -func DepositPermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("admin;employee") || token.PoolRoles.Validate("finance")) { +func DepositPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate("finance")) { return vcago.NewPermissionDenied(DepositCollection) } return } -func (i *DepositParam) DepositSyncPermission(token *vcapool.AccessToken) (err error) { +func (i *DepositParam) DepositSyncPermission(token *AccessToken) (err error) { if !token.Roles.Validate("admin") { return vcago.NewPermissionDenied(DepositCollection) } @@ -127,7 +125,7 @@ func (i *DepositParam) DepositSyncPermission(token *vcapool.AccessToken) (err er func DepositPipeline() *vmdb.Pipeline { pipe := vmdb.NewPipeline() pipe.LookupUnwind(DepositUnitCollection, "_id", "deposit_id", "deposit_units") - pipe.LookupUnwind(TakingCollection, "deposit_units.taking_id", "_id", "deposit_units.taking") + pipe.LookupUnwind(TakingDepositView, "deposit_units.taking_id", "_id", "deposit_units.taking") pipe.Append(bson.D{ {Key: "$group", Value: bson.D{ {Key: "_id", Value: "$_id"}, {Key: "deposit_units", Value: bson.D{ @@ -139,6 +137,7 @@ func DepositPipeline() *vmdb.Pipeline { pipe.Append(bson.D{{Key: "$addFields", Value: bson.D{{Key: "deposits.deposit_units", Value: "$deposit_units"}}}}) pipe.Append(bson.D{{Key: "$replaceRoot", Value: bson.D{{Key: "newRoot", Value: "$deposits"}}}}) pipe.LookupUnwind(CrewCollection, "crew_id", "_id", "crew") + pipe.Lookup(ReceiptFileCollection, "_id", "deposit_id", "receipts") return pipe } @@ -155,7 +154,7 @@ func UpdateWaitTaking(amount int64) bson.D { } */ -func (i *DepositCreate) DepositDatabase(token *vcapool.AccessToken) (r *DepositDatabase, d []DepositUnit) { +func (i *DepositCreate) DepositDatabase(token *AccessToken) (r *DepositDatabase, d []DepositUnit) { d = []DepositUnit{} var amount int64 = 0 id := uuid.NewString() @@ -233,11 +232,11 @@ func (i *DepositUpdate) DepositDatabase(current *Deposit) (r *DepositUpdate, cre return } -func (i *DepositQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *DepositQuery) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualStringList("_id", i.ID) filter.SearchString([]string{"deposit_units.taking.name", "reason_for_payment"}, i.Search) - if !token.Roles.Validate("admin;employee") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } else { filter.EqualStringList("crew_id", i.CrewID) @@ -249,10 +248,10 @@ func (i *DepositQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { return filter.Bson() } -func (i *DepositParam) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *DepositParam) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !token.Roles.Validate("admin;employee") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } return filter.Bson() diff --git a/models/event.go b/models/event.go index d69847a..8d73025 100644 --- a/models/event.go +++ b/models/event.go @@ -1,10 +1,13 @@ package models import ( + "fmt" + "strconv" + "time" + "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -24,6 +27,7 @@ type ( StartAt int64 `json:"start_at" bson:"start_at"` EndAt int64 `json:"end_at" bson:"end_at"` CrewID string `json:"crew_id" bson:"crew_id"` + OrganisationID string `json:"organisation_id" bson:"organisation_id"` EventASPID string `json:"event_asp_id" bson:"event_asp_id"` InternalASPID string `json:"internal_asp_id" bson:"internal_asp_id"` ExternalASP UserExternal `json:"external_asp" bson:"external_asp"` @@ -32,28 +36,30 @@ type ( EventState EventState `json:"event_state" bson:"event_state"` } EventDatabase struct { - ID string `json:"id" bson:"_id"` - Name string `json:"name" bson:"name"` - TypeOfEvent string `json:"type_of_event" bson:"type_of_event"` - AdditionalInformation string `json:"additional_information" bson:"additional_information"` - Website string `json:"website" bson:"website"` - TourID string `json:"tour_id" bson:"tour_id"` - Location Location `json:"location" bson:"location"` - MeetingURL string `json:"meeting_url" bson:"meeting_url"` - ArtistIDs []string `json:"artist_ids" bson:"artist_ids"` - OrganizerID string `json:"organizer_id" bson:"organizer_id"` - StartAt int64 `json:"start_at" bson:"start_at"` - EndAt int64 `json:"end_at" bson:"end_at"` - CrewID string `json:"crew_id" bson:"crew_id"` - TakingID string `json:"taking_id" bson:"taking_id"` - EventASPID string `json:"event_asp_id" bson:"event_asp_id"` - InternalASPID string `json:"internal_asp_id" bson:"internal_asp_id"` - ExternalASP UserExternal `json:"external_asp" bson:"external_asp"` - Application EventApplication `json:"application" bson:"application"` - EventTools EventTools `json:"event_tools" bson:"event_tools"` - CreatorID string `json:"creator_id" bson:"creator_id"` - EventState EventState `json:"event_state" bson:"event_state"` - Modified vmod.Modified `json:"modified" bson:"modified"` + ID string `json:"id" bson:"_id"` + Name string `json:"name" bson:"name"` + TypeOfEvent string `json:"type_of_event" bson:"type_of_event"` + AdditionalInformation string `json:"additional_information" bson:"additional_information"` + Website string `json:"website" bson:"website"` + TourID string `json:"tour_id" bson:"tour_id"` + Location Location `json:"location" bson:"location"` + MeetingURL string `json:"meeting_url" bson:"meeting_url"` + ArtistIDs []string `json:"artist_ids" bson:"artist_ids"` + OrganizerID string `json:"organizer_id" bson:"organizer_id"` + StartAt int64 `json:"start_at" bson:"start_at"` + EndAt int64 `json:"end_at" bson:"end_at"` + CrewID string `json:"crew_id" bson:"crew_id"` + OrganisationID string `json:"organisation_id" bson:"organisation_id"` + TakingID string `json:"taking_id" bson:"taking_id"` + EventASPID string `json:"event_asp_id" bson:"event_asp_id"` + InternalASPID string `json:"internal_asp_id" bson:"internal_asp_id"` + ExternalASP UserExternal `json:"external_asp" bson:"external_asp"` + Application EventApplication `json:"application" bson:"application"` + Applications EventApplications `json:"applications" bson:"applications"` + EventTools EventTools `json:"event_tools" bson:"event_tools"` + CreatorID string `json:"creator_id" bson:"creator_id"` + EventState EventState `json:"event_state" bson:"event_state"` + Modified vmod.Modified `json:"modified" bson:"modified"` } EventTools struct { Tools []string `json:"tools" bson:"tools"` @@ -65,6 +71,13 @@ type ( EndDate int64 `json:"end_date" bson:"end_date"` SupporterCount int `json:"supporter_count" bson:"supporter_count"` } + EventApplications struct { + Total int `json:"total" bson:"total"` + Confirmed int `json:"confirmed" bson:"confirmed"` + Rejected int `json:"rejected" bson:"rejected"` + Requested int `json:"requested" bson:"requested"` + Withdrawn int `json:"withdrawn" bson:"withdrawn"` + } //EventState represents the state of an event. EventState struct { State string `json:"state" bson:"state"` @@ -100,6 +113,7 @@ type ( Artists []Artist `json:"artists" bson:"artists"` OrganizerID string `json:"organizer_id" bson:"organizer_id"` Organizer Organizer `json:"organizer" bson:"organizer"` + Organisation Organisation `json:"organisation" bson:"organisation"` StartAt int64 `json:"start_at" bson:"start_at"` EndAt int64 `json:"end_at" bson:"end_at"` CrewID string `json:"crew_id" bson:"crew_id"` @@ -121,13 +135,15 @@ type ( Artists []Artist `json:"artists" bson:"artists"` OrganizerID string `json:"organizer_id" bson:"organizer_id"` Organizer Organizer `json:"organizer" bson:"organizer"` + Organisation Organisation `json:"organisation" bson:"organisation"` StartAt int64 `json:"start_at" bson:"start_at"` EndAt int64 `json:"end_at" bson:"end_at"` CrewID string `json:"crew_id" bson:"crew_id"` - Crew Crew `json:"crew" bson:"crew"` + Crew CrewPublic `json:"crew" bson:"crew"` EventASPID string `json:"event_asp_id" bson:"event_asp_id"` InternalASPID string `json:"internal_asp_id" bson:"internal_asp_id"` Application EventApplication `json:"application" bson:"application"` + Applications EventApplications `json:"applications" bson:"applications"` Participation []ParticipationMinimal `json:"participations" bson:"participations"` EventTools EventTools `json:"event_tools" bson:"event_tools"` EventState EventState `json:"event_state" bson:"event_state"` @@ -154,42 +170,45 @@ type ( EventASP EventASPPublic `json:"event_asp" bson:"event_asp"` InternalASPID string `json:"internal_asp_id" bson:"internal_asp_id"` Application EventApplication `json:"application" bson:"application"` + Applications EventApplications `json:"applications" bson:"applications"` Participation []ParticipationMinimal `json:"participations" bson:"participations"` EventTools EventTools `json:"event_tools" bson:"event_tools"` EventState EventState `json:"event_state" bson:"event_state"` Modified vmod.Modified `json:"modified" bson:"modified"` } Event struct { - ID string `json:"id" bson:"_id"` - Name string `json:"name" bson:"name"` - TypeOfEvent string `json:"type_of_event" bson:"type_of_event"` - AdditionalInformation string `json:"additional_information" bson:"additional_information"` - Website string `json:"website" bson:"website"` - TourID string `json:"tour_id" bson:"tour_id"` - Location Location `json:"location" bson:"location"` - MeetingURL string `json:"meeting_url" bson:"meeting_url"` - ArtistIDs []string `json:"artist_ids" bson:"artist_ids"` - Artists []Artist `json:"artists" bson:"artists"` - OrganizerID string `json:"organizer_id" bson:"organizer_id"` - Organizer Organizer `json:"organizer" bson:"organizer"` - StartAt int64 `json:"start_at" bson:"start_at"` - EndAt int64 `json:"end_at" bson:"end_at"` - CrewID string `json:"crew_id" bson:"crew_id"` - Crew Crew `json:"crew" bson:"crew"` - EventASPID string `json:"event_asp_id" bson:"event_asp_id"` - InternalASPID string `json:"internal_asp_id" bson:"internal_asp_id"` - EventASP User `json:"event_asp" bson:"event_asp"` - InteralASP User `json:"internal_asp" bson:"internal_asp"` - ExternalASP UserExternal `json:"external_asp" bson:"external_asp"` - TakingID string `json:"taking_id" bson:"taking_id"` - DepositID string `json:"deposit_id" bson:"deposit_id"` - Application EventApplication `json:"application" bson:"application"` - Participation []Participation `json:"participations" bson:"participations"` - EventTools EventTools `json:"event_tools" bson:"event_tools"` - Creator User `json:"creator" bson:"creator"` - EventState EventState `json:"event_state" bson:"event_state"` - EditorID string `json:"editor_id" bson:"editor_id"` - Modified vmod.Modified `json:"modified" bson:"modified"` + ID string `json:"id" bson:"_id"` + Name string `json:"name" bson:"name"` + TypeOfEvent string `json:"type_of_event" bson:"type_of_event"` + AdditionalInformation string `json:"additional_information" bson:"additional_information"` + Website string `json:"website" bson:"website"` + TourID string `json:"tour_id" bson:"tour_id"` + Location Location `json:"location" bson:"location"` + MeetingURL string `json:"meeting_url" bson:"meeting_url"` + ArtistIDs []string `json:"artist_ids" bson:"artist_ids"` + Artists []Artist `json:"artists" bson:"artists"` + OrganizerID string `json:"organizer_id" bson:"organizer_id"` + Organizer Organizer `json:"organizer" bson:"organizer"` + StartAt int64 `json:"start_at" bson:"start_at"` + EndAt int64 `json:"end_at" bson:"end_at"` + CrewID string `json:"crew_id" bson:"crew_id"` + Crew Crew `json:"crew" bson:"crew"` + EventASPID string `json:"event_asp_id" bson:"event_asp_id"` + InternalASPID string `json:"internal_asp_id" bson:"internal_asp_id"` + EventASP User `json:"event_asp" bson:"event_asp"` + InteralASP User `json:"internal_asp" bson:"internal_asp"` + OrganisationID string `json:"organisation_id" bson:"organisation_id"` + ExternalASP UserExternal `json:"external_asp" bson:"external_asp"` + TakingID string `json:"taking_id" bson:"taking_id"` + DepositID string `json:"deposit_id" bson:"deposit_id"` + Application EventApplication `json:"application" bson:"application"` + Applications EventApplications `json:"applications" bson:"applications"` + Participation []Participation `json:"participations" bson:"participations"` + EventTools EventTools `json:"event_tools" bson:"event_tools"` + Creator User `json:"creator" bson:"creator"` + EventState EventState `json:"event_state" bson:"event_state"` + EditorID string `json:"editor_id" bson:"editor_id"` + Modified vmod.Modified `json:"modified" bson:"modified"` } EventUpdate struct { ID string `json:"id" bson:"_id"` @@ -205,6 +224,7 @@ type ( StartAt int64 `json:"start_at" bson:"start_at"` EndAt int64 `json:"end_at" bson:"end_at"` CrewID string `json:"crew_id" bson:"crew_id"` + OrganisationID string `json:"organisation_id" bson:"organisation_id"` Crew Crew `json:"crew" bson:"crew"` EventASPID string `json:"event_asp_id" bson:"event_asp_id"` InternalASPID string `json:"internal_asp_id" bson:"internal_asp_id"` @@ -213,21 +233,33 @@ type ( EventTools EventTools `json:"event_tools" bson:"event_tools"` EventState EventState `json:"event_state" bson:"event_state"` } + EventApplicationsUpdate struct { + ID string `json:"id" bson:"_id"` + Applications EventApplications `json:"applications" bson:"applications"` + } EventParam struct { ID string `param:"id"` } EventQuery struct { - ID []string `query:"id" qs:"id"` - Name string `query:"name" qs:"name"` - CrewID string `query:"crew_id" qs:"crew_id"` - EventASPID string `query:"event_asp_id" qs:"event_asp_id"` - EventState []string `query:"event_state" qs:"event_state"` - InternalASPID string `query:"internal_asp_id" qs:"internal_asp_id"` - UpdatedTo string `query:"updated_to" qs:"updated_to"` - UpdatedFrom string `query:"updated_from" qs:"updated_from"` - CreatedTo string `query:"created_to" qs:"created_to"` - CreatedFrom string `query:"created_from" qs:"created_from"` + ID []string `query:"id" qs:"id"` + Name string `query:"name" qs:"name"` + CrewID string `query:"crew_id" qs:"crew_id"` + EventASPID string `query:"event_asp_id" qs:"event_asp_id"` + Type []string `query:"type" qs:"type"` + EventState []string `query:"event_state" qs:"event_state"` + InternalASPID string `query:"internal_asp_id" qs:"internal_asp_id"` + StartAt string `query:"start_at" qs:"start_at"` + EndAt string `query:"end_at" qs:"end_at"` + UpdatedTo string `query:"updated_to" qs:"updated_to"` + UpdatedFrom string `query:"updated_from" qs:"updated_from"` + MissingApplications bool `query:"missing_applications" qs:"missing_applications"` + OnlyApply bool `query:"only_apply" qs:"only_apply"` + CreatedTo string `query:"created_to" qs:"created_to"` + OrganisationId []string `query:"organisation_id" qs:"organisation_id"` + CreatedFrom string `query:"created_from" qs:"created_from"` + FullCount string `query:"full_count"` + vmdb.Query } UserExternal struct { FullName string `json:"full_name" bson:"full_name"` @@ -238,6 +270,7 @@ type ( Location struct { Name string `json:"name" bson:"name"` Street string `json:"street" bson:"street"` + Zip string `json:"zip" bson:"zip"` City string `json:"city" bson:"city"` Country string `json:"country" bson:"country"` CountryCode string `json:"country_code" bson:"country_code"` @@ -303,17 +336,20 @@ type ( ) var EventCollection = "events" +var EventView = "events_view" +var PublicEventView = "events_public_view" func (i *EventDatabase) TakingDatabase() *TakingDatabase { return &TakingDatabase{ - ID: uuid.NewString(), - Name: i.Name, - CrewID: i.CrewID, - Type: "automatically", - Modified: vmod.NewModified(), + ID: uuid.NewString(), + Name: i.Name, + CrewID: i.CrewID, + DateOfTaking: i.EndAt, + Type: "automatically", + Modified: vmod.NewModified(), } } -func (i *EventCreate) EventDatabase(token *vcapool.AccessToken) *EventDatabase { +func (i *EventCreate) EventDatabase(token *AccessToken) *EventDatabase { return &EventDatabase{ ID: uuid.NewString(), Name: i.Name, @@ -331,6 +367,7 @@ func (i *EventCreate) EventDatabase(token *vcapool.AccessToken) *EventDatabase { InternalASPID: i.InternalASPID, ExternalASP: i.ExternalASP, Application: i.Application, + Applications: EventApplications{Confirmed: 0, Rejected: 0, Requested: 0, Withdrawn: 0, Total: 0}, EventTools: i.EventTools, EventState: i.EventState, CreatorID: token.ID, @@ -372,7 +409,7 @@ func (i *EventImport) EventDatabase() *EventDatabase { } } -func EventPipeline(token *vcapool.AccessToken) (pipe *vmdb.Pipeline) { +func EventPipeline(token *AccessToken) (pipe *vmdb.Pipeline) { pipe = vmdb.NewPipeline() pipe.LookupUnwind(UserCollection, "event_asp_id", "_id", "event_asp") pipe.LookupUnwind(ProfileCollection, "event_asp_id", "user_id", "event_asp.profile") @@ -381,7 +418,8 @@ func EventPipeline(token *vcapool.AccessToken) (pipe *vmdb.Pipeline) { pipe.LookupUnwind(UserCollection, "creator_id", "_id", "creator") pipe.LookupUnwind(ProfileCollection, "creator_id", "user_id", "creator.profile") pipe.LookupUnwind(OrganizerCollection, "organizer_id", "_id", "organizer") - if token.Roles.Validate("employee;admin") { + pipe.LookupUnwind(OrganisationCollection, "organisation_id", "_id", "organisation") + if token.Roles.Validate("admin;employee;pool_employee") { pipe.Lookup(ParticipationCollection, "_id", "event_id", "participations") } else if token.PoolRoles.Validate(ASPEventRole) { pipe.LookupMatch(ParticipationEventView, "_id", "event_id", "participations", bson.D{{Key: "event.crew_id", Value: token.CrewID}}) @@ -412,6 +450,7 @@ func EventPipelinePublic() (pipe *vmdb.Pipeline) { pipe.LookupUnwind(OrganizerCollection, "organizer_id", "_id", "organizer") pipe.LookupList(ArtistCollection, "artist_ids", "_id", "artists") pipe.LookupUnwind(CrewCollection, "crew_id", "_id", "crew") + pipe.LookupUnwind(OrganisationCollection, "organisation_id", "_id", "organisation") return } @@ -421,21 +460,21 @@ func EventRolePipeline() *vmdb.Pipeline { return pipe } -func EventPermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { +func EventPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { return vcago.NewPermissionDenied(EventCollection) } return } -func EventDeletePermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { +func EventDeletePermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { return vcago.NewPermissionDenied(EventCollection) } return } -func (i *EventParam) EventSyncPermission(token *vcapool.AccessToken) (err error) { +func (i *EventParam) EventSyncPermission(token *AccessToken) (err error) { if !token.Roles.Validate("admin") { return vcago.NewPermissionDenied(EventCollection) } @@ -454,10 +493,10 @@ func (i *EventDatabase) Match() bson.D { return filter.Bson() } -func (i *EventParam) PermittedDeleteFilter(token *vcapool.AccessToken) bson.D { +func (i *EventParam) PermittedDeleteFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) filter.EqualStringList("event_state.state", []string{"created", "requested"}) } @@ -469,13 +508,13 @@ func (i *EventUpdate) Match() bson.D { return filter.Bson() } -func (i *EventUpdate) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *EventUpdate) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { filter.EqualString("event_asp_id", token.ID) filter.EqualString("crew_id", token.CrewID) - } else if !token.Roles.Validate("employee;admin") { + } else if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } return filter.Bson() @@ -489,30 +528,52 @@ func (i *Event) FilterCrew() bson.D { return filter.Bson() } -func (i *EventParam) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *EventParam) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { filter.EqualString("event_asp_id", token.ID) - } else if !token.Roles.Validate("employee;admin") { + } else if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } return filter.Bson() } +func (i *EventParam) FilterID() bson.D { + filter := vmdb.NewFilter() + filter.EqualString("_id", i.ID) + return filter.Bson() +} + func (i *EventQuery) PublicFilter() bson.D { filter := vmdb.NewFilter() filter.EqualStringList("_id", i.ID) filter.LikeString("name", i.Name) filter.EqualStringList("event_state.state", []string{"published", "finished", "closed"}) + filter.EqualStringList("type_of_event", i.Type) + filter.EqualStringList("organisation_id", i.OrganisationId) filter.EqualString("crew_id", i.CrewID) + filter.GteInt64("start_at", i.StartAt) + filter.LteInt64("end_at", i.EndAt) + if i.OnlyApply { + filter.GteInt64("application.start_date", strconv.FormatInt(time.Now().Unix(), 10)) + filter.LteInt64("application.end_date", strconv.FormatInt(time.Now().Unix(), 10)) + } filter.GteInt64("modified.updated", i.UpdatedFrom) filter.GteInt64("modified.created", i.CreatedFrom) filter.LteInt64("modified.updated", i.UpdatedTo) filter.LteInt64("modified.created", i.CreatedTo) + filter.SearchString([]string{"_id", "name", "crew.name"}, i.Search) + return filter.Bson() } +func (i EventQuery) Sort() bson.D { + sort := vmdb.NewSort() + sort.Add(i.SortField, i.SortDirection) + return sort.Bson() +} + func (i *EventParam) PublicFilter() bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) @@ -520,46 +581,58 @@ func (i *EventParam) PublicFilter() bson.D { return filter.Bson() } -func (i *EventQuery) FilterAsp(token *vcapool.AccessToken) bson.D { +func (i *EventQuery) FilterAsp(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { - filter.EqualString("event_asp_id", token.ID) - } else if !token.Roles.Validate("employee;admin") { + if token.PoolRoles.Validate(ASPEventRole) { filter.EqualString("crew_id", token.CrewID) + } else { + filter.EqualString("event_asp_id", token.ID) } return filter.Bson() } -func (i *EventQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *EventQuery) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { filter.EqualStringList("event_state.state", []string{"published", "finished", "closed"}) - } else if !token.Roles.Validate("employee;admin") { + } else if !token.Roles.Validate("admin;employee;pool_employee") { noCrewMatch := vmdb.NewFilter() crewMatch := vmdb.NewFilter() crewMatch.EqualString("crew_id", token.CrewID) noCrewMatch.EqualStringList("event_state.state", []string{"published", "finished", "closed"}) filter.Append(bson.E{Key: "$or", Value: bson.A{noCrewMatch.Bson(), crewMatch.Bson()}}) } + if i.OnlyApply { + filter.GteInt64("application.start_date", strconv.FormatInt(time.Now().Unix(), 10)) + filter.LteInt64("application.end_date", strconv.FormatInt(time.Now().Unix(), 10)) + } + if i.MissingApplications { + filter.Append(bson.E{Key: "$expr", Value: bson.D{{Key: "$gt", Value: bson.A{"$application.supporter_count", "$applications.confirmed"}}}}) + } + filter.GteInt64("start_at", i.StartAt) + filter.LteInt64("end_at", i.EndAt) filter.EqualStringList("_id", i.ID) filter.LikeString("name", i.Name) + filter.EqualStringList("type_of_event", i.Type) filter.EqualString("internal_asp_id", i.InternalASPID) filter.EqualString("event_asp_id", i.EventASPID) filter.EqualStringList("event_state.state", i.EventState) filter.EqualString("crew_id", i.CrewID) + filter.EqualStringList("organisation_id", i.OrganisationId) filter.GteInt64("modified.updated", i.UpdatedFrom) filter.GteInt64("modified.created", i.CreatedFrom) filter.LteInt64("modified.updated", i.UpdatedTo) filter.LteInt64("modified.created", i.CreatedTo) + filter.SearchString([]string{"_id", "name", "crew.name"}, i.Search) return filter.Bson() } -func (i *EventQuery) FilterEmailEvents(token *vcapool.AccessToken) bson.D { +func (i *EventQuery) FilterEmailEvents(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { filter.EqualString("event_asp_id", token.ID) filter.EqualString("crew_id", token.CrewID) - } else if !token.Roles.Validate("employee;admin") { + } else if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } @@ -574,11 +647,11 @@ func (i *Event) ToContent() *vmod.Content { return content } -func (i *EventUpdate) EventStateValidation(token *vcapool.AccessToken, event *EventValidate) (err error) { +func (i *EventUpdate) EventStateValidation(token *AccessToken, event *EventValidate) (err error) { if i.EventState.State == "canceled" && (event.EventState.State == "finished" || event.EventState.State == "closed") { return vcago.NewBadRequest(EventCollection, "event can not be canceled, it is already "+event.EventState.State, i) } - if !token.Roles.Validate("employee;admin") && (event.EventState.State == "finished" || event.EventState.State == "closed") { + if !token.Roles.Validate("admin;employee;pool_employee") && (event.EventState.State == "finished" || event.EventState.State == "closed") { return vcago.NewBadRequest(EventCollection, "event can not be updated, it is already "+event.EventState.State, i) } if event.Taking.Money.Amount != 0 { @@ -586,3 +659,17 @@ func (i *EventUpdate) EventStateValidation(token *vcapool.AccessToken, event *Ev } return } + +func (i *Event) GetLocation() string { + if i.Location.PlaceID != "" { + return fmt.Sprintf("%v, %v %v", i.Location.Name, i.Location.Zip, i.Location.City) + } + return fmt.Sprintf("Online: %v", i.MeetingURL) +} + +func (i *EventPublic) GetLocation() string { + if i.Location.PlaceID != "" { + return fmt.Sprintf("%v, %v %v", i.Location.Name, i.Location.Zip, i.Location.City) + } + return "Online" +} diff --git a/models/event_history.go b/models/event_history.go new file mode 100644 index 0000000..fbc0f38 --- /dev/null +++ b/models/event_history.go @@ -0,0 +1,128 @@ +package models + +import ( + "fmt" + "time" + + "github.com/Viva-con-Agua/vcago" + "github.com/Viva-con-Agua/vcago/vmdb" + "github.com/Viva-con-Agua/vcago/vmod" + "github.com/google/uuid" + "go.mongodb.org/mongo-driver/bson" +) + +type EventStateHistoryCreate struct { + ID string `bson:"_id" json:"id"` + UserID string `json:"user_id" bson:"user_id"` + CrewID string `json:"crew_id" bson:"crew_id"` + EventID string `json:"event_id" bson:"event_id"` + Date int64 `json:"date" bson:"date"` + OldState string `json:"old_state" bson:"old_state"` + NewState string `json:"new_state" bson:"new_state"` +} + +type EventStateHistoryQuery struct { + ID []string `query:"id" qs:"id"` + UserID string `query:"user_id" qs:"user_id"` + CrewID string `query:"crew_id" qs:"crew_id"` + EventID string `query:"event_id" qs:"event_id"` + DateTo string `query:"date_to" qs:"date_to"` + DateFrom string `query:"date_from" qs:"date_from"` + OldState string `query:"old_state" qs:"old_state"` + NewState string `query:"new_state" qs:"new_state"` + Search string `query:"search"` + SortField string `query:"sort"` + SortDirection string `query:"sort_dir"` + Limit int64 `query:"limit"` + Skip int64 `query:"skip"` + FullCount string `query:"full_count"` +} + +type EventStateHistory struct { + ID string `bson:"_id" json:"id"` + UserID string `json:"user_id" bson:"user_id"` + User UserMinimal `json:"user" bson:"user"` + CrewID string `json:"crew_id" bson:"crew_id"` + Crew CrewSimple `json:"crew" bson:"crew"` + EventID string `json:"event_id" bson:"event_id"` + Event EventPublic `json:"event" bson:"event"` + Date int64 `json:"date" bson:"date"` + OldState string `json:"old_state" bson:"old_state"` + NewState string `json:"new_state" bson:"new_state"` +} + +type EventStateHistoryNotification struct { + EventID string `json:"event_id" bson:"event_id"` + EventName string `json:"event_name" bson:"event_name"` + EventStart string `json:"event_start" bson:"event_start"` + EventCrew string `json:"event_crew" bson:"event_crew"` + EventArtist string `json:"event_artist" bson:"event_artist"` + EventLocation string `json:"event_location" bson:"event_location"` + PublishedDate string `json:"published_date" bson:"published_date"` +} + +var EventStateHistoryCollection = "eventstate_history" + +func EventStatePipeline() (pipe *vmdb.Pipeline) { + pipe = vmdb.NewPipeline() + pipe.LookupUnwind(EventCollection, "event_id", "_id", "event") + pipe.Lookup(ArtistCollection, "event.artist_ids", "_id", "event.artists") + pipe.LookupUnwind(UserCollection, "user_id", "_id", "user") + pipe.LookupUnwind(CrewCollection, "crew_id", "_id", "crew") + return +} + +func EventStateHistoryPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPRole)) { + return vcago.NewPermissionDenied(PoolRoleHistoryCollection) + } + return +} + +func (i *Event) NewEventStateHistory(old string, new string, token *AccessToken) *EventStateHistoryCreate { + return &EventStateHistoryCreate{ + ID: uuid.NewString(), + UserID: token.ID, + CrewID: i.CrewID, + EventID: i.ID, + OldState: old, + NewState: new, + Date: time.Now().Unix(), + } +} + +func (i *EventStateHistoryQuery) Filter() bson.D { + filter := vmdb.NewFilter() + filter.EqualStringList("_id", i.ID) + filter.EqualString("user_id", i.UserID) + filter.EqualString("event_id", i.EventID) + filter.EqualString("crew_id", i.CrewID) + filter.EqualString("old_state", i.OldState) + filter.EqualString("new_state", i.NewState) + filter.GteInt64("date", i.DateFrom) + filter.LteInt64("date", i.DateTo) + filter.SearchString([]string{"_id", "name", "crew.name"}, i.Search) + + return filter.Bson() +} + +func EventPublishedLastWeek() bson.D { + filter := vmdb.NewFilter() + + week := 7 * 24 + // if we had fix number of units to subtract, we can use following line instead fo above 2 lines. It does type convertion automatically. + // then := now.Add(-10 * time.Minute) + fmt.Printf("7 week ago: %v\n ", time.Now().Add(time.Duration(-week)*time.Hour)) + + filter.GteInt64("date", fmt.Sprint(time.Now().Add(time.Duration(-week)*time.Hour).Unix())) + filter.LteInt64("date", fmt.Sprint(time.Now().Unix())) + return filter.Bson() +} + +func EventHistoryAdminContent(data []EventStateHistoryNotification) *vmod.Content { + content := &vmod.Content{ + Fields: make(map[string]interface{}), + } + content.Fields["Events"] = data + return content +} diff --git a/models/mailbox.go b/models/mailbox.go index efb2eba..ca49efa 100644 --- a/models/mailbox.go +++ b/models/mailbox.go @@ -3,7 +3,6 @@ package models import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -34,11 +33,11 @@ func NewMailboxDatabase(t string) *MailboxDatabase { } } -func MailboxPipeline(token *vcapool.AccessToken) *vmdb.Pipeline { +func MailboxPipeline(token *AccessToken) *vmdb.Pipeline { pipe := vmdb.NewPipeline() pipe.LookupUnwind(UserCollection, "_id", "mailbox_id", "user") pipe.LookupUnwind(CrewCollection, "_id", "mailbox_id", "crew") - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPRole)) { inboxMatch := vmdb.NewFilter() inboxMatch.EqualString("type", "inbox") inboxMatch.EqualString("user_id", token.ID) @@ -65,7 +64,7 @@ func MailboxPipeline(token *vcapool.AccessToken) *vmdb.Pipeline { return pipe } -func (i *MailboxParam) Permission(token *vcapool.AccessToken, mailbox *Mailbox) (err error) { +func (i *MailboxParam) Permission(token *AccessToken, mailbox *Mailbox) (err error) { if token.MailboxID == mailbox.ID { return } else if token.CrewID == mailbox.ID { @@ -74,10 +73,10 @@ func (i *MailboxParam) Permission(token *vcapool.AccessToken, mailbox *Mailbox) return vcago.NewPermissionDenied(MailboxCollection) } -func (i *MailboxParam) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *MailboxParam) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { status := bson.A{} status = append(status, bson.D{{Key: "user._id", Value: token.ID}}) status = append(status, bson.D{{Key: "crew._id", Value: token.CrewID}}) diff --git a/models/message.go b/models/message.go index cbbdf6b..41925d7 100644 --- a/models/message.go +++ b/models/message.go @@ -6,7 +6,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -88,21 +87,21 @@ type ( var MessageCollection = "messages" -func MessageCrewPermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("admin;employee") || token.PoolRoles.Validate(ASPRole)) { +func MessageCrewPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPRole)) { return vcago.NewPermissionDenied(MessageCollection) } return } -func MessageEventPermission(token *vcapool.AccessToken, event *Event) (err error) { - if !token.PoolRoles.Validate(ASPRole) && !token.Roles.Validate("admin;employee") && event.EventASPID != token.ID { +func MessageEventPermission(token *AccessToken, event *Event) (err error) { + if !token.PoolRoles.Validate(ASPRole) && !token.Roles.Validate("admin;employee;pool_employee") && event.EventASPID != token.ID { return vcago.NewPermissionDenied(MessageCollection) } return } -func (i *MessageCreate) MessageSub(token *vcapool.AccessToken) *Message { +func (i *MessageCreate) MessageSub(token *AccessToken) *Message { return &Message{ ID: uuid.NewString(), MessageID: uuid.NewString(), @@ -148,10 +147,10 @@ func (i *Message) MessageUpdate() *MessageUpdate { } } -func (i *MessageParam) PermittedFilter(token *vcapool.AccessToken, crew *Crew) bson.D { +func (i *MessageParam) PermittedFilter(token *AccessToken, crew *Crew) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { filter.EqualStringList("mailbox_id", []string{token.MailboxID, crew.MailboxID}) filter.EqualString("user_id", token.ID) } else { @@ -160,10 +159,10 @@ func (i *MessageParam) PermittedFilter(token *vcapool.AccessToken, crew *Crew) b return filter.Bson() } -func (i *MessageUpdate) PermittedFilter(token *vcapool.AccessToken, crew *Crew) bson.D { +func (i *MessageUpdate) PermittedFilter(token *AccessToken, crew *Crew) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { filter.EqualStringList("mailbox_id", []string{token.MailboxID, crew.MailboxID}) filter.EqualString("user_id", token.ID) } else { @@ -172,9 +171,9 @@ func (i *MessageUpdate) PermittedFilter(token *vcapool.AccessToken, crew *Crew) return filter.Bson() } -func (i *RecipientGroup) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *RecipientGroup) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if !token.Roles.Validate("admin;employee") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew.crew_id", token.CrewID) } else { filter.EqualString("crew.crew_id", i.CrewID) @@ -193,9 +192,9 @@ func (i *RecipientGroup) FilterEvent() bson.D { return filter.Bson() } -func PermittedMessageCreate(token *vcapool.AccessToken, i *Message, crew *Crew, event *Event) (message *Message, err error) { +func PermittedMessageCreate(token *AccessToken, i *Message, crew *Crew, event *Event) (message *Message, err error) { message = i - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { if i.RecipientGroup.Type == "event" && token.ID == event.EventASPID { // IF IS EVENT ASP -> Force Mailbox and From to CrewMailbox and CrewEmail message.MailboxID = crew.MailboxID diff --git a/models/newsletter.go b/models/newsletter.go index fea21f6..90c8f6b 100644 --- a/models/newsletter.go +++ b/models/newsletter.go @@ -4,7 +4,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -35,14 +34,14 @@ type ( var NewsletterCollection = "newsletters" -func NewsletterDeletePermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") { +func NewsletterDeletePermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") { return vcago.NewPermissionDenied(ArtistCollection) } return } -func (i *NewsletterCreate) Newsletter(token *vcapool.AccessToken) *Newsletter { +func (i *NewsletterCreate) Newsletter(token *AccessToken) *Newsletter { return &Newsletter{ ID: uuid.NewString(), Value: i.Value, @@ -75,8 +74,8 @@ func (i *NewsletterParam) Match() bson.D { return filter.Bson() } -func (i *Newsletter) DeletePermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") && token.ID != i.UserID { +func (i *Newsletter) DeletePermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") && token.ID != i.UserID { return vcago.NewPermissionDenied(NewsletterCollection) } return diff --git a/models/nvm.go b/models/nvm.go index 96d994b..552bffc 100644 --- a/models/nvm.go +++ b/models/nvm.go @@ -5,7 +5,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" ) @@ -31,7 +30,7 @@ type ( } ) -func NVMConfirmedPermission(token *vcapool.AccessToken) (err error) { +func NVMConfirmedPermission(token *AccessToken) (err error) { if token.ActiveState != "confirmed" { return vcago.NewBadRequest(NVMCollection, "active required") } @@ -44,8 +43,8 @@ func NVMConfirmedPermission(token *vcapool.AccessToken) (err error) { return } -func NVMPermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") { +func NVMPermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") { return vcago.NewPermissionDenied(NVMCollection) } return diff --git a/models/organisation.go b/models/organisation.go new file mode 100644 index 0000000..ba97322 --- /dev/null +++ b/models/organisation.go @@ -0,0 +1,90 @@ +package models + +import ( + "github.com/Viva-con-Agua/vcago/vmdb" + "github.com/Viva-con-Agua/vcago/vmod" + "github.com/google/uuid" + "go.mongodb.org/mongo-driver/bson" +) + +type ( + OrganisationCreate struct { + Name string `json:"name" bson:"name" validate:"required"` + Abbreviation string `json:"abbreviation" bson:"abbreviation"` + DefaultAspID string `json:"default_asp_id" bson:"default_asp_id"` + Email string `json:"email" bson:"email"` + } + Organisation struct { + ID string `json:"id" bson:"_id"` + Name string `json:"name" bson:"name"` + Abbreviation string `json:"abbreviation" bson:"abbreviation"` + DefaultAspID string `json:"default_asp_id" bson:"default_asp_id"` + DefaultAsp UserContact `json:"default_asp" bson:"default_asp"` + Email string `json:"email" bson:"email"` + Modified vmod.Modified `json:"modified" bson:"modified"` + } + OrganisationUpdate struct { + ID string `json:"id" bson:"_id"` + DefaultAspID string `json:"default_asp_id" bson:"default_asp_id"` + Abbreviation string `json:"abbreviation" bson:"abbreviation"` + Email string `json:"email" bson:"email"` + Name string `json:"name" bson:"name"` + } + OrganisationParam struct { + ID string `param:"id"` + } + OrganisationQuery struct { + ID string `query:"id" qs:"id"` + Name string `query:"name" qs:"name"` + Abbreviation string `query:"abbreviation" qs:"abbreviation"` + DefaultAspID string `json:"default_asp_id" bson:"default_asp_id"` + Email string `query:"email" qs:"email"` + UpdatedTo string `query:"updated_to" qs:"updated_to"` + UpdatedFrom string `query:"updated_from" qs:"updated_from"` + CreatedTo string `query:"created_to" qs:"created_to"` + CreatedFrom string `query:"created_from" qs:"created_from"` + } +) + +var OrganisationCollection = "organisations" + +func OrganisationPipeline() (pipe *vmdb.Pipeline) { + pipe = vmdb.NewPipeline() + pipe.LookupUnwind(UserCollection, "default_asp_id", "_id", "default_asp") + pipe.LookupUnwind(ProfileCollection, "default_asp_id", "user_id", "default_asp.profile") + return +} + +func (i *OrganisationCreate) Organisation() *Organisation { + return &Organisation{ + ID: uuid.NewString(), + Name: i.Name, + Email: i.Email, + DefaultAspID: i.DefaultAspID, + Abbreviation: i.Abbreviation, + Modified: vmod.NewModified(), + } +} + +func (i *OrganisationParam) Match() bson.D { + filter := vmdb.NewFilter() + filter.EqualString("_id", i.ID) + return filter.Bson() +} + +func (i *OrganisationUpdate) Match() bson.D { + filter := vmdb.NewFilter() + filter.EqualString("_id", i.ID) + return filter.Bson() +} + +func (i *OrganisationQuery) Filter() bson.D { + filter := vmdb.NewFilter() + filter.EqualString("_id", i.ID) + filter.LikeString("name", i.Name) + filter.GteInt64("modified.updated", i.UpdatedFrom) + filter.GteInt64("modified.created", i.CreatedFrom) + filter.LteInt64("modified.updated", i.UpdatedTo) + filter.LteInt64("modified.created", i.CreatedTo) + return filter.Bson() +} diff --git a/models/organizer.go b/models/organizer.go index ccde8c4..6a9d370 100644 --- a/models/organizer.go +++ b/models/organizer.go @@ -4,7 +4,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -37,15 +36,15 @@ type ( var OrganizerCollection = "organizers" -func OrganizerPermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { +func OrganizerPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { return vcago.NewPermissionDenied(OrganizerCollection) } return } -func OrganizerDeletePermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") { +func OrganizerDeletePermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") { return vcago.NewPermissionDenied(OrganizerCollection) } return diff --git a/models/participation.go b/models/participation.go index a92bfc5..677aa3b 100644 --- a/models/participation.go +++ b/models/participation.go @@ -4,7 +4,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -79,13 +78,14 @@ type ( } ParticipationQuery struct { - ID []string `query:"id" qs:"id"` - EventID []string `query:"event_id" qs:"event_id"` - Comment []string `query:"comment" bson:"comment"` - Status []string `query:"status" bson:"status"` - UserId []string `query:"user_id" bson:"user_id"` - CrewName []string `query:"crew_name" bson:"crew_name"` - CrewId []string `query:"crew_id" qs:"crew_id"` + ID []string `query:"id" qs:"id"` + EventID []string `query:"event_id" qs:"event_id"` + Comment []string `query:"comment" bson:"comment"` + Status []string `query:"status" bson:"status"` + UserId []string `query:"user_id" bson:"user_id"` + CrewName []string `query:"crew_name" bson:"crew_name"` + CrewId []string `query:"crew_id" qs:"crew_id"` + OrganisationId []string `query:"organisation_id" qs:"organisation_id"` } ParticipationStateRequest struct { ID string `json:"id"` @@ -100,28 +100,28 @@ type ( var ParticipationCollection = "participations" var ParticipationEventView = "participations_event" -func ParticipationPermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { +func ParticipationPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { return vcago.NewPermissionDenied(ParticipationCollection) } return } -func ParticipationDeletePermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") { +func ParticipationDeletePermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") { return vcago.NewPermissionDenied(ParticipationCollection) } return } -func (i *ParticipationUpdate) ParticipationUpdatePermission(token *vcapool.AccessToken, participation *Participation) (err error) { +func (i *ParticipationUpdate) ParticipationUpdatePermission(token *AccessToken, participation *Participation) (err error) { switch i.Status { case "requested", "withdrawn": - if !token.Roles.Validate("employee;admin") && token.ID != participation.UserID { + if !token.Roles.Validate("admin;employee;pool_employee") && token.ID != participation.UserID { return vcago.NewPermissionDenied(ParticipationCollection) } case "confirmed", "rejected": - if !token.Roles.Validate("employee;admin") && !token.PoolRoles.Validate(ASPEventRole) && token.ID != participation.Event.EventASPID { + if !token.Roles.Validate("admin;employee;pool_employee") && !token.PoolRoles.Validate(ASPEventRole) && token.ID != participation.Event.EventASPID { return vcago.NewPermissionDenied(ParticipationCollection) } } @@ -164,13 +164,32 @@ func (i *Participation) ToContent() *vmod.Content { return content } -func (i *ParticipationCreate) ParticipationDatabase(token *vcapool.AccessToken) *ParticipationDatabase { +func (i *Participation) UpdateEventApplicationsUpdate(value int, applications *EventApplications) *EventApplicationsUpdate { + switch i.Status { + case "confirmed": + applications.Confirmed = i.Event.Applications.Confirmed + value + case "rejected": + applications.Rejected = i.Event.Applications.Rejected + value + case "requested": + applications.Requested = i.Event.Applications.Requested + value + case "withdrawn": + applications.Withdrawn = i.Event.Applications.Withdrawn + value + } + applications.Total = i.Event.Applications.Total + value + return &EventApplicationsUpdate{ID: i.EventID, Applications: *applications} +} + +func (i *ParticipationCreate) ParticipationDatabase(token *AccessToken, event *Event) *ParticipationDatabase { + eventStatus := "requested" + if event.TypeOfEvent == "crew_meeting" { + eventStatus = "confirmed" + } return &ParticipationDatabase{ ID: uuid.NewString(), UserID: token.ID, EventID: i.EventID, Comment: i.Comment, - Status: "requested", + Status: eventStatus, CrewID: token.CrewID, Modified: vmod.NewModified(), } @@ -185,31 +204,19 @@ func (i *ParticipationImport) ParticipationDatabase() *ParticipationDatabase { } } func (i *ParticipationStateRequest) IsRequested() bool { - if i.Status == "requested" { - return true - } - return false + return i.Status == "requested" } func (i *ParticipationStateRequest) IsConfirmed() bool { - if i.Status == "confirmed" { - return true - } - return false + return i.Status == "confirmed" } func (i *ParticipationStateRequest) IsWithdrawn() bool { - if i.Status == "withdrawn" { - return true - } - return false + return i.Status == "withdrawn" } func (i *ParticipationStateRequest) IsRejected() bool { - if i.Status == "rejected" { - return true - } - return false + return i.Status == "rejected" } -func (i *ParticipationQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *ParticipationQuery) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualStringList("_id", i.ID) filter.EqualStringList("event_id", i.EventID) @@ -217,13 +224,14 @@ func (i *ParticipationQuery) PermittedFilter(token *vcapool.AccessToken) bson.D filter.EqualStringList("comment", i.Comment) filter.EqualStringList("user_id", i.UserId) filter.EqualStringList("crew.name", i.CrewName) - if token.Roles.Validate("employee;admin") { + filter.EqualStringList("crew.organisation_id", i.OrganisationId) + if token.Roles.Validate("admin;employee;pool_employee") { filter.EqualStringList("crew_id", i.CrewId) } return filter.Bson() } -func (i *ParticipationQuery) FilterUser(token *vcapool.AccessToken) bson.D { +func (i *ParticipationQuery) FilterUser(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualStringList("_id", i.ID) filter.EqualStringList("event_id", i.EventID) @@ -231,6 +239,7 @@ func (i *ParticipationQuery) FilterUser(token *vcapool.AccessToken) bson.D { filter.EqualStringList("comment", i.Comment) filter.EqualStringList("crew.name", i.CrewName) filter.EqualStringList("crew_id", i.CrewId) + filter.EqualStringList("crew.organisation_id", i.OrganisationId) filter.EqualString("user_id", token.ID) return filter.Bson() } @@ -242,22 +251,22 @@ func (i *Event) FilterParticipants() bson.D { return filter.Bson() } -func (i *ParticipationQuery) FilterAspInformation(token *vcapool.AccessToken) bson.D { +func (i *ParticipationQuery) FilterAspInformation(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualStringList("event_id", i.EventID) - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("status", "confirmed") filter.EqualString("user_id", token.ID) } return filter.Bson() } -func (i *EventParam) FilterEvent(token *vcapool.AccessToken) bson.D { +func (i *EventParam) FilterEvent(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("event_id", i.ID) - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { filter.EqualString("event.event_asp_id", token.ID) - } else if !token.Roles.Validate("employee;admin") { + } else if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("event.crew_id", token.CrewID) } return filter.Bson() @@ -281,33 +290,33 @@ func (i *ParticipationStateRequest) Match() bson.D { return filter.Bson() } -func (i *ParticipationUpdate) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *ParticipationUpdate) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !token.PoolRoles.Validate("admin;employee") { + if !token.PoolRoles.Validate("admin;employee;pool_employee") { filter.EqualString("event.crew_id", token.CrewID) } return filter.Bson() } -func (i *ParticipationParam) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *ParticipationParam) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPEventRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPEventRole)) { filter.EqualString("user_id", token.ID) - } else if !token.Roles.Validate("employee;admin") { + } else if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } return filter.Bson() } -func (i *ParticipationStateRequest) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *ParticipationStateRequest) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) if i.IsWithdrawn() { filter.EqualString("user_id", token.ID) } else if i.IsConfirmed() || i.IsRejected() { - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } } else { diff --git a/models/profile.go b/models/profile.go index 6e48e79..b0d78e8 100644 --- a/models/profile.go +++ b/models/profile.go @@ -1,45 +1,49 @@ package models import ( + "time" + "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) type ( ProfileCreate struct { - Gender string `bson:"gender" json:"gender"` - Phone string `bson:"phone" json:"phone"` - Mattermost string `bson:"mattermost_username" json:"mattermost_username"` - Birthdate int64 `bson:"birthdate" json:"birthdate"` + Gender string `bson:"gender" json:"gender"` + Phone string `bson:"phone" json:"phone"` + Mattermost string `bson:"mattermost_username" json:"mattermost_username"` + Birthdate int64 `bson:"birthdate" json:"birthdate"` + BirthdateDatetime string `bson:"birthdate_datetime" json:"birthdate_datetime"` } ProfileUpdate struct { - ID string `bson:"_id" json:"id"` - Gender string `bson:"gender" json:"gender"` - Phone string `bson:"phone" json:"phone"` - Mattermost string `bson:"mattermost_username" json:"mattermost_username"` - Birthdate int64 `bson:"birthdate" json:"birthdate"` + ID string `bson:"_id" json:"id"` + Gender string `bson:"gender" json:"gender"` + Phone string `bson:"phone" json:"phone"` + Mattermost string `bson:"mattermost_username" json:"mattermost_username"` + Birthdate int64 `bson:"birthdate" json:"birthdate"` + BirthdateDatetime string `bson:"birthdate_datetime" json:"birthdate_datetime"` } Profile struct { - ID string `bson:"_id" json:"id"` - Gender string `bson:"gender" json:"gender"` - Phone string `bson:"phone" json:"phone"` - Mattermost string `bson:"mattermost_username" json:"mattermost_username"` - Birthdate int64 `bson:"birthdate" json:"birthdate"` - - UserID string `bson:"user_id" json:"user_id"` - Modified vmod.Modified `bson:"modified" json:"modified"` + ID string `bson:"_id" json:"id"` + Gender string `bson:"gender" json:"gender"` + Phone string `bson:"phone" json:"phone"` + Mattermost string `bson:"mattermost_username" json:"mattermost_username"` + Birthdate int64 `bson:"birthdate" json:"birthdate"` + BirthdateDatetime string `bson:"birthdate_datetime" json:"birthdate_datetime"` + UserID string `bson:"user_id" json:"user_id"` + Modified vmod.Modified `bson:"modified" json:"modified"` } ProfileParam struct { ID string `param:"id"` } ProfileMinimal struct { - Mattermost string `bson:"mattermost_username" json:"mattermost_username"` - Birthdate int64 `bson:"birthdate" json:"birthdate"` - UserID string `bson:"user_id" json:"user_id"` + Mattermost string `bson:"mattermost_username" json:"mattermost_username"` + Birthdate int64 `bson:"birthdate" json:"birthdate"` + BirthdateDatetime string `bson:"birthdate_datetime" json:"birthdate_datetime"` + UserID string `bson:"user_id" json:"user_id"` } ProfileImport struct { Gender string `bson:"gender" json:"gender"` @@ -52,7 +56,7 @@ type ( var ProfileCollection = "profiles" -func (i *ProfileParam) ProfileSyncPermission(token *vcapool.AccessToken) (err error) { +func (i *ProfileParam) ProfileSyncPermission(token *AccessToken) (err error) { if !token.Roles.Validate("admin") { return vcago.NewPermissionDenied(ProfileCollection) } @@ -60,14 +64,21 @@ func (i *ProfileParam) ProfileSyncPermission(token *vcapool.AccessToken) (err er } func (i *ProfileCreate) Profile(userID string) *Profile { + birthdate := time.Unix(i.Birthdate, 0) + birthdateDatetime := "" + if i.Birthdate != 0 { + birthdateDatetime = birthdate.Format("2006-01-02") + } + return &Profile{ - ID: uuid.NewString(), - Gender: i.Gender, - Phone: i.Phone, - Mattermost: i.Mattermost, - Birthdate: i.Birthdate, - UserID: userID, - Modified: vmod.NewModified(), + ID: uuid.NewString(), + Gender: i.Gender, + Phone: i.Phone, + Mattermost: i.Mattermost, + Birthdate: i.Birthdate, + BirthdateDatetime: birthdateDatetime, + UserID: userID, + Modified: vmod.NewModified(), } } @@ -83,7 +94,7 @@ func (i *ProfileImport) Profile(userID string) *Profile { } } -func (i *ProfileUpdate) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *ProfileUpdate) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) filter.EqualString("user_id", token.ID) diff --git a/models/receipts.go b/models/receipts.go new file mode 100644 index 0000000..10439c6 --- /dev/null +++ b/models/receipts.go @@ -0,0 +1,30 @@ +package models + +import ( + "github.com/Viva-con-Agua/vcago/vmod" + "github.com/google/uuid" +) + +type ( + ReceiptFileCreate struct { + DepositID string `bson:"deposit_id" json:"deposit_id"` + } + + ReceiptFile struct { + ID string `bson:"_id" json:"id"` + DepositID string `bson:"deposit_id" json:"deposit_id"` + Modified vmod.Modified `bson:"modified" json:"modified"` + } +) + +var ( + ReceiptFileCollection = "receipts_files" +) + +func (i *ReceiptFileCreate) ReceiptFile() *ReceiptFile { + return &ReceiptFile{ + ID: uuid.NewString(), + DepositID: i.DepositID, + Modified: vmod.NewModified(), + } +} diff --git a/models/role.go b/models/role.go index 54252c7..5d24aaa 100644 --- a/models/role.go +++ b/models/role.go @@ -6,7 +6,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -122,32 +121,32 @@ func NewRoleRequestHistory(i *RoleRequest, user *User) (r *RoleHistoryDatabase) var ASPRole = "other;asp;finance;operation;education;network;socialmedia;awareness" var ASPEventRole = "network;operation;education" -func RolesPermission(role string, user *User, token *vcapool.AccessToken) (err error) { +func RolesPermission(role string, user *User, token *AccessToken) (err error) { if user.NVM.Status != "confirmed" { return vcago.NewBadRequest(PoolRoleCollection, "nvm required", nil) } - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(role)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(role)) { return vcago.NewPermissionDenied(PoolRoleCollection) } return } -func RolesBulkPermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPRole)) { +func RolesBulkPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPRole)) { return vcago.NewPermissionDenied(PoolRoleCollection) } return } -func RolesDeletePermission(role string, token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(role)) { +func RolesDeletePermission(role string, token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(role)) { return vcago.NewPermissionDenied(PoolRoleCollection) } return } -func RolesAdminPermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") { +func RolesAdminPermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") { return vcago.NewPermissionDenied(PoolRoleCollection) } return @@ -157,8 +156,7 @@ func RoleASP(userID string) *vmod.Role { return &vmod.Role{ ID: uuid.NewString(), Name: "asp", - Label: "ASP", - Root: "employee;admin", + Root: "admin;employee;pool_employee", UserID: userID, } } @@ -167,7 +165,6 @@ func RoleSupporter(userID string) *vmod.Role { return &vmod.Role{ ID: uuid.NewString(), Name: "supporter", - Label: "Supporter", Root: "system", UserID: userID, } @@ -177,8 +174,7 @@ func RoleFinance(userID string) *vmod.Role { return &vmod.Role{ ID: uuid.NewString(), Name: "finance", - Label: "Finanzen", - Root: "finance;employee;admin", + Root: "finance;admin;employee;pool_employee", UserID: userID, } } @@ -187,8 +183,7 @@ func RoleAction(userID string) *vmod.Role { return &vmod.Role{ ID: uuid.NewString(), Name: "operation", - Label: "Aktion", - Root: "operation;employee;admin", + Root: "operation;admin;employee;pool_employee", UserID: userID, } } @@ -196,8 +191,7 @@ func RoleEducation(userID string) *vmod.Role { return &vmod.Role{ ID: uuid.NewString(), Name: "education", - Label: "Bildung", - Root: "education;employee;admin", + Root: "education;admin;employee;pool_employee", UserID: userID, } } @@ -205,8 +199,7 @@ func RoleNetwork(userID string) *vmod.Role { return &vmod.Role{ ID: uuid.NewString(), Name: "network", - Label: "Netzwerk", - Root: "network;employee;admin", + Root: "network;admin;employee;pool_employee", UserID: userID, } } @@ -214,8 +207,7 @@ func RoleSocialMedia(userID string) *vmod.Role { return &vmod.Role{ ID: uuid.NewString(), Name: "socialmedia", - Label: "Social Media", - Root: "socialmedia;employee;admin", + Root: "socialmedia;admin;employee;pool_employee", UserID: userID, } } @@ -223,8 +215,7 @@ func RoleAwareness(userID string) *vmod.Role { return &vmod.Role{ ID: uuid.NewString(), Name: "awareness", - Label: "Awareness", - Root: "awareness;employee;admin", + Root: "awareness;admin;employee;pool_employee", UserID: userID, } } @@ -233,8 +224,7 @@ func RoleOther(userID string) *vmod.Role { return &vmod.Role{ ID: uuid.NewString(), Name: "other", - Label: "Other", - Root: "other;employee;admin", + Root: "other;admin;employee;pool_employee", UserID: userID, } } @@ -258,9 +248,9 @@ func (i *RoleRequest) FilterHistory() bson.D { return filter.Bson() } -func (i *RoleBulkRequest) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *RoleBulkRequest) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew.crew_id", token.CrewID) filter.ElemMatchList("pool_roles", "name", token.PoolRoles) } else { diff --git a/models/role_history.go b/models/role_history.go index 33f3d6e..1b99765 100644 --- a/models/role_history.go +++ b/models/role_history.go @@ -6,7 +6,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -80,18 +79,18 @@ func RolesHistoryPermittedPipeline() (pipe *vmdb.Pipeline) { return } -func RolesHistoryPermission(user *User, token *vcapool.AccessToken) (err error) { +func RolesHistoryPermission(user *User, token *AccessToken) (err error) { if user.NVM.Status != "confirmed" { return vcago.NewBadRequest(PoolRoleHistoryCollection, "nvm required", nil) } - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPRole)) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPRole)) { return vcago.NewPermissionDenied(PoolRoleHistoryCollection) } return } -func RolesHistoryAdminPermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") { +func RolesHistoryAdminPermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") { return vcago.NewPermissionDenied(PoolRoleHistoryCollection) } return @@ -169,9 +168,9 @@ func (i *RoleHistoryDatabase) Filter() bson.D { return filter.Bson() } -func (i *RoleHistoryBulkRequest) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *RoleHistoryBulkRequest) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew.crew_id", token.CrewID) } else { filter.EqualString("crew.crew_id", i.CrewID) @@ -180,9 +179,9 @@ func (i *RoleHistoryBulkRequest) PermittedFilter(token *vcapool.AccessToken) bso return filter.Bson() } -func (i *RoleHistoryRequest) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *RoleHistoryRequest) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } else { filter.EqualString("crew_id", i.CrewID) diff --git a/models/source.go b/models/source.go index c640786..acedc63 100644 --- a/models/source.go +++ b/models/source.go @@ -3,7 +3,6 @@ package models import ( "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -113,8 +112,8 @@ func (i *SourceQuery) Filter() bson.D { return filter.Bson() } -func SourceDeletePermission(taking *Taking, token *vcapool.AccessToken) bool { - if !token.Roles.Validate("admin;employee") { +func SourceDeletePermission(taking *Taking, token *AccessToken) bool { + if !token.Roles.Validate("admin;employee;pool_employee") { if taking.State.Confirmed.Amount != 0 { return false } diff --git a/models/taking.go b/models/taking.go index af01ec2..2a24a34 100644 --- a/models/taking.go +++ b/models/taking.go @@ -6,7 +6,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -56,6 +55,7 @@ type ( Activities []Activity `json:"activities" bson:"activities"` Money vmod.Money `json:"money" bson:"money"` Creator UserDatabase `json:"creator" bson:"creator"` + Modified vmod.Modified `json:"modified" bson:"modified"` } TakingState struct { Open vmod.Money `json:"open" bson:"open"` @@ -73,7 +73,6 @@ type ( TakingQuery struct { ID []string `query:"id"` Name string `query:"name"` - Search string `query:"search"` CrewID []string `query:"crew_id"` EventName string `query:"event_name"` TypeOfEvent []string `query:"type_of_event"` @@ -87,18 +86,16 @@ type ( StatusNone bool `query:"status_none"` StatusWait bool `query:"status_wait"` StatusNoIncome bool `query:"status_no_income"` - SortField string `query:"sort"` - SortDirection string `query:"sort_dir"` - Limit int64 `query:"limit"` - Skip int64 `query:"skip"` FullCount string `query:"full_count"` + vmdb.Query } ) var TakingCollection = "takings" +var TakingDepositView = "taking_deposit_view" -func TakingPermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("admin;employee") || token.PoolRoles.Validate("finance")) { +func TakingPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate("finance")) { return vcago.NewPermissionDenied(DepositCollection) } return @@ -112,7 +109,7 @@ func TakingPipeline() *vmdb.Pipeline { pipe.Lookup(SourceCollection, "_id", "taking_id", "sources") pipe.LookupUnwind(CrewCollection, "crew_id", "_id", "crew") pipe.LookupUnwind(EventCollection, "_id", "taking_id", "event") - //pipe.LookupList(ArtistCollection, "event.artist_ids", "_id", "event.artists") + pipe.Lookup(ArtistCollection, "event.artist_ids", "_id", "event.artists") pipe.Append(bson.D{{Key: "$addFields", Value: bson.D{ {Key: "state.wait.amount", Value: bson.D{{Key: "$sum", Value: "$wait.money.amount"}}}, }}}) @@ -137,19 +134,44 @@ func TakingPipeline() *vmdb.Pipeline { return pipe } +func TakingCountPipeline(filter bson.D) *vmdb.Pipeline { + pipe := TakingPipeline() + pipe.Match(filter) + pipe.Append(bson.D{ + {Key: "$group", Value: bson.D{ + {Key: "_id", Value: nil}, {Key: "list_size", Value: bson.D{ + {Key: "$sum", Value: 1}, + }}, + }}, + }) + pipe.Append(bson.D{{Key: "$project", Value: bson.D{{Key: "_id", Value: 0}}}}) + return pipe +} + func TakingPipelineTicker() *vmdb.Pipeline { pipe := vmdb.NewPipeline() pipe.LookupUnwind(EventCollection, "_id", "taking_id", "event") return pipe } +func TakingPipelineDeposit() *vmdb.Pipeline { + pipe := vmdb.NewPipeline() + pipe.LookupUnwind(EventCollection, "_id", "taking_id", "event") + pipe.Lookup(SourceCollection, "_id", "taking_id", "sources") + return pipe +} + func (i *TakingCreate) TakingDatabase() *TakingDatabase { + currency := "EUR" + if len(i.NewSource) > 0 { + currency = i.NewSource[0].Money.Currency + } return &TakingDatabase{ ID: uuid.NewString(), Name: i.Name, CrewID: i.CrewID, Type: "manually", - Currency: i.NewSource[0].Money.Currency, + Currency: currency, DateOfTaking: i.DateOfTaking, Comment: i.Comment, Modified: vmod.NewModified(), @@ -186,10 +208,10 @@ func (i *TakingUpdate) Match() bson.D { } */ -func (i *TakingQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *TakingQuery) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualStringList("_id", i.ID) - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualStringList("crew_id", []string{token.CrewID}) } else { filter.EqualStringList("crew_id", i.CrewID) @@ -229,27 +251,27 @@ func (i *TakingQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { return filter.Bson() } -func (i *TakingUpdate) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *TakingUpdate) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } return filter.Bson() } -func TakingPermittedFilter(i *vmod.IDParam, token *vcapool.AccessToken) bson.D { +func TakingPermittedFilter(i *vmod.IDParam, token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew_id", token.CrewID) } return filter.Bson() } -func (i *Taking) UpdatePermission(token *vcapool.AccessToken) error { +func (i *Taking) UpdatePermission(token *AccessToken) error { if i.Event.ID != "" { - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { if !token.PoolRoles.Validate("finance") { return vcago.NewPermissionDenied(TakingCollection) } diff --git a/models/user.go b/models/user.go index a05824f..f86944b 100644 --- a/models/user.go +++ b/models/user.go @@ -7,7 +7,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/golang-jwt/jwt" "go.mongodb.org/mongo-driver/bson" ) @@ -17,20 +16,22 @@ type ( Email string `json:"email"` } UserDatabase struct { - ID string `json:"id,omitempty" bson:"_id"` - Email string `json:"email" bson:"email" validate:"required,email"` - FirstName string `bson:"first_name" json:"first_name" validate:"required"` - LastName string `bson:"last_name" json:"last_name" validate:"required"` - FullName string `bson:"full_name" json:"full_name"` - DisplayName string `bson:"display_name" json:"display_name"` - Roles vmod.RoleList `json:"system_roles" bson:"system_roles"` - Country string `bson:"country" json:"country"` - PrivacyPolicy bool `bson:"privacy_policy" json:"privacy_policy"` - Confirmed bool `bson:"confirmed" json:"confirmed"` - DropsID string `bson:"drops_id" json:"drops_id"` - LastUpdate string `bson:"last_update" json:"last_update"` - MailboxID string `bson:"mailbox_id" json:"mailbox_id"` - Modified vmod.Modified `json:"modified" bson:"modified"` + ID string `json:"id,omitempty" bson:"_id"` + Email string `json:"email" bson:"email" validate:"required,email"` + FirstName string `bson:"first_name" json:"first_name" validate:"required"` + LastName string `bson:"last_name" json:"last_name" validate:"required"` + FullName string `bson:"full_name" json:"full_name"` + DisplayName string `bson:"display_name" json:"display_name"` + Roles vmod.RoleList `json:"system_roles" bson:"system_roles"` + Country string `bson:"country" json:"country"` + PrivacyPolicy bool `bson:"privacy_policy" json:"privacy_policy"` + Confirmed bool `bson:"confirmed" json:"confirmed"` + DropsID string `bson:"drops_id" json:"drops_id"` + LastUpdate string `bson:"last_update" json:"last_update"` + OrganisationID string `bson:"organisation_id" json:"organisation_id"` + MailboxID string `bson:"mailbox_id" json:"mailbox_id"` + LastLoginDate int64 `bson:"last_login_date" json:"last_login_date"` + Modified vmod.Modified `json:"modified" bson:"modified"` } UserUpdate struct { ID string `json:"id,omitempty" bson:"_id"` @@ -44,13 +45,18 @@ type ( PrivacyPolicy bool `bson:"privacy_policy" json:"privacy_policy"` Confirmed bool `bson:"confirmed" json:"confirmed"` DropsID string `bson:"drops_id" json:"drops_id"` + LastLoginDate int64 `bson:"last_login_date" json:"last_login_date"` LastUpdate string `bson:"last_update" json:"last_update"` } + UserOrganisationUpdate struct { + ID string `json:"id,omitempty" bson:"_id"` + OrganisationID string `bson:"organisation_id" json:"organisation_id"` + } User struct { ID string `json:"id,omitempty" bson:"_id"` - Email string `json:"email" bson:"email" validate:"required,email"` - FirstName string `bson:"first_name" json:"first_name" validate:"required"` - LastName string `bson:"last_name" json:"last_name" validate:"required"` + Email string `json:"email" bson:"email" ` + FirstName string `bson:"first_name" json:"first_name" ` + LastName string `bson:"last_name" json:"last_name" ` FullName string `bson:"full_name" json:"full_name"` DisplayName string `bson:"display_name" json:"display_name"` Roles vmod.RoleList `json:"system_roles" bson:"system_roles"` @@ -59,24 +65,27 @@ type ( Confirmed bool `bson:"confirmed" json:"confirmed"` LastUpdate string `bson:"last_update" json:"last_update"` MailboxID string `bson:"mailbox_id" json:"mailbox_id"` + LastLoginDate int64 `bson:"last_login_date" json:"last_login_date"` //extends the vcago.User - DropsID string `bson:"drops_id" json:"drops_id"` - Profile Profile `json:"profile" bson:"profile,truncate"` - Crew UserCrew `json:"crew" bson:"crew,omitempty"` - Avatar Avatar `bson:"avatar,omitempty" json:"avatar"` - Address Address `json:"address" bson:"address,omitempty"` - AddressID string `json:"address_id" bson:"address_id"` - PoolRoles vmod.RoleList `json:"pool_roles" bson:"pool_roles,omitempty"` - Active Active `json:"active" bson:"active,omitempty"` - NVM NVM `json:"nvm" bson:"nvm,omitempty"` - Newsletter []Newsletter `json:"newsletter" bson:"newsletter"` - Modified vmod.Modified `json:"modified" bson:"modified"` + DropsID string `bson:"drops_id" json:"drops_id"` + Profile Profile `json:"profile" bson:"profile,truncate"` + Crew UserCrew `json:"crew" bson:"crew,omitempty"` + OrganisationID string `bson:"organisation_id" json:"organisation_id"` + Organisation string `bson:"organisation" json:"organisation,omitempty"` + Avatar Avatar `bson:"avatar,omitempty" json:"avatar"` + Address Address `json:"address" bson:"address,omitempty"` + AddressID string `json:"address_id" bson:"address_id"` + PoolRoles vmod.RoleList `json:"pool_roles" bson:"pool_roles,omitempty"` + Active Active `json:"active" bson:"active,omitempty"` + NVM NVM `json:"nvm" bson:"nvm,omitempty"` + Newsletter []Newsletter `json:"newsletter" bson:"newsletter"` + Modified vmod.Modified `json:"modified" bson:"modified"` } ListUser struct { ID string `json:"id,omitempty" bson:"_id"` - Email string `json:"email" bson:"email" validate:"required,email"` - FirstName string `bson:"first_name" json:"first_name" validate:"required"` - LastName string `bson:"last_name" json:"last_name" validate:"required"` + Email string `json:"email" bson:"email" ` + FirstName string `bson:"first_name" json:"first_name" ` + LastName string `bson:"last_name" json:"last_name" ` FullName string `bson:"full_name" json:"full_name"` DisplayName string `bson:"display_name" json:"display_name"` Roles vmod.RoleList `json:"system_roles" bson:"system_roles"` @@ -94,9 +103,9 @@ type ( } UserParticipant struct { ID string `json:"id,omitempty" bson:"_id"` - Email string `json:"email" bson:"email" validate:"required,email"` - FirstName string `bson:"first_name" json:"first_name" validate:"required"` - LastName string `bson:"last_name" json:"last_name" validate:"required"` + Email string `json:"email" bson:"email" ` + FirstName string `bson:"first_name" json:"first_name" ` + LastName string `bson:"last_name" json:"last_name" ` FullName string `bson:"full_name" json:"full_name"` DisplayName string `bson:"display_name" json:"display_name"` Country string `bson:"country" json:"country"` @@ -106,15 +115,17 @@ type ( Active Active `json:"active" bson:"active,omitempty"` } UserPublic struct { - ID string `json:"id,omitempty" bson:"_id"` - FirstName string `bson:"first_name" json:"first_name" validate:"required"` - LastName string `bson:"last_name" json:"last_name" validate:"required"` - FullName string `bson:"full_name" json:"full_name"` - DisplayName string `bson:"display_name" json:"display_name"` - Roles vmod.RoleList `json:"system_roles" bson:"system_roles"` - Country string `bson:"country" json:"country"` - Confirmed bool `bson:"confirmed" json:"confirmed"` - LastUpdate string `bson:"last_update" json:"last_update"` + ID string `json:"id,omitempty" bson:"_id"` + FirstName string `bson:"first_name" json:"first_name" ` + LastName string `bson:"last_name" json:"last_name" ` + FullName string `bson:"full_name" json:"full_name"` + DisplayName string `bson:"display_name" json:"display_name"` + Roles vmod.RoleList `json:"system_roles" bson:"system_roles"` + Country string `bson:"country" json:"country"` + Confirmed bool `bson:"confirmed" json:"confirmed"` + LastUpdate string `bson:"last_update" json:"last_update"` + OrganisationID string `bson:"organisation_id" json:"organisation_id"` + Organisation string `bson:"organisation" json:"organisation"` //extends the vcago.User DropsID string `bson:"drops_id" json:"drops_id"` Profile Profile `json:"profile" bson:"profile,truncate"` @@ -125,15 +136,15 @@ type ( } UserMinimal struct { ID string `json:"id,omitempty" bson:"_id"` - FirstName string `bson:"first_name" json:"first_name" validate:"required"` - LastName string `bson:"last_name" json:"last_name" validate:"required"` + FirstName string `bson:"first_name" json:"first_name" ` + LastName string `bson:"last_name" json:"last_name" ` FullName string `bson:"full_name" json:"full_name"` DisplayName string `bson:"display_name" json:"display_name"` } UserBasic struct { ID string `json:"id,omitempty" bson:"_id"` - FirstName string `bson:"first_name" json:"first_name" validate:"required"` - LastName string `bson:"last_name" json:"last_name" validate:"required"` + FirstName string `bson:"first_name" json:"first_name" ` + LastName string `bson:"last_name" json:"last_name" ` FullName string `bson:"full_name" json:"full_name"` Profile ProfileMinimal `bson:"profile" json:"profile"` DisplayName string `bson:"display_name" json:"display_name"` @@ -142,27 +153,33 @@ type ( PoolRoles vmod.RoleList `json:"pool_roles" bson:"pool_roles,omitempty"` NVM NVM `json:"nvm" bson:"nvm,omitempty"` } + UserContact struct { + ID string `json:"id,omitempty" bson:"_id"` + Email string `json:"email" bson:"email" ` + FirstName string `bson:"first_name" json:"first_name" ` + LastName string `bson:"last_name" json:"last_name" ` + FullName string `bson:"full_name" json:"full_name"` + Profile ProfileMinimal `bson:"profile" json:"profile"` + } UserParam struct { ID string `param:"id"` } UserQuery struct { - ID []string `query:"id"` - Search string `query:"search"` - Email string `query:"email"` - FirstName string `query:"first_name"` - LastName string `query:"last_name"` - FullName string `query:"full_name"` - DisplayName string `query:"display_name" qs:"display_name"` - ActiveState []string `query:"active_state" qs:"active_state"` - NVMState []string `query:"nvm_state" qs:"nvm_state"` - SystemRoles []string `query:"system_roles"` - PoolRoles []string `query:"pool_roles"` - CrewID string `query:"crew_id" qs:"crew_id"` - SortField string `query:"sort"` - SortDirection string `query:"sort_dir"` - Limit int64 `query:"limit"` - Skip int64 `query:"skip"` - FullCount string `query:"full_count"` + ID []string `query:"id"` + Email string `query:"email"` + FirstName string `query:"first_name"` + LastName string `query:"last_name"` + FullName string `query:"full_name"` + DisplayName string `query:"display_name" qs:"display_name"` + OrganisationID []string `query:"organisation_id" qs:"organisation_id"` + Abbreviation []string `query:"organisation_abbreviation" qs:"organisation_abbreviation"` + ActiveState []string `query:"active_state" qs:"active_state"` + NVMState []string `query:"nvm_state" qs:"nvm_state"` + SystemRoles []string `query:"system_roles"` + PoolRoles []string `query:"pool_roles"` + CrewID string `query:"crew_id" qs:"crew_id"` + FullCount string `query:"full_count"` + vmdb.Query } ) @@ -221,7 +238,7 @@ func NewUserUpdate(user *vmod.User) *UserUpdate { func UserPipeline(user bool) (pipe *vmdb.Pipeline) { pipe = vmdb.NewPipeline() - if user == true { + if user { pipe.LookupUnwind(AddressesCollection, "_id", "user_id", "address") } else { pipe.LookupUnwind(AddressesCollection, "_id", "user_id", "address_data") @@ -238,7 +255,7 @@ func UserPipeline(user bool) (pipe *vmdb.Pipeline) { return } -func SortedUserPermittedPipeline(token *vcapool.AccessToken) (pipe *vmdb.Pipeline) { +func SortedUserPermittedPipeline(token *AccessToken) (pipe *vmdb.Pipeline) { pipe = vmdb.NewPipeline() pipe.LookupUnwind(ProfileCollection, "_id", "user_id", "profile") pipe.LookupUnwind(UserCrewCollection, "_id", "user_id", "crew") @@ -248,7 +265,7 @@ func SortedUserPermittedPipeline(token *vcapool.AccessToken) (pipe *vmdb.Pipelin return } -func UserPermittedPipeline(token *vcapool.AccessToken) (pipe *vmdb.Pipeline) { +func UserPermittedPipeline(token *AccessToken) (pipe *vmdb.Pipeline) { pipe = vmdb.NewPipeline() if token.Roles.Validate("admin") { pipe.LookupUnwind(AddressesCollection, "_id", "user_id", "address") @@ -262,7 +279,7 @@ func UserPermittedPipeline(token *vcapool.AccessToken) (pipe *vmdb.Pipeline) { pipe.LookupUnwind(ActiveCollection, "_id", "user_id", "active") pipe.LookupUnwind(NVMCollection, "_id", "user_id", "nvm") pipe.Lookup(PoolRoleCollection, "_id", "user_id", "pool_roles") - if token.Roles.Validate("employee;admin") { + if token.Roles.Validate("admin;employee;pool_employee") { pipe.Lookup(NewsletterCollection, "_id", "user_id", "newsletter") } pipe.LookupUnwind(AvatarCollection, "_id", "user_id", "avatar") @@ -292,31 +309,32 @@ func UserMatchEmail(email string) bson.D { } func (i *User) AuthToken() (r *vcago.AuthToken, err error) { - accessToken := &vcapool.AccessToken{ - ID: i.ID, - Email: i.Email, - FirstName: i.FirstName, - LastName: i.LastName, - FullName: i.FullName, - DisplayName: i.DisplayName, - Roles: *i.Roles.Cookie(), - Country: i.Country, - PrivacyPolicy: i.PrivacyPolicy, - Confirmd: i.Confirmed, - LastUpdate: i.LastUpdate, - Phone: i.Profile.Phone, - Gender: i.Profile.Gender, - Birthdate: i.Profile.Birthdate, - CrewName: i.Crew.Name, - CrewID: i.Crew.CrewID, - CrewEmail: i.Crew.Email, - AddressID: i.Address.ID, - PoolRoles: *i.PoolRoles.Cookie(), - ActiveState: i.Active.Status, - NVMState: i.NVM.Status, - AvatarID: i.Avatar.ID, - MailboxID: i.MailboxID, - Modified: i.Modified, + accessToken := &AccessToken{ + ID: i.ID, + Email: i.Email, + FirstName: i.FirstName, + LastName: i.LastName, + FullName: i.FullName, + DisplayName: i.DisplayName, + Roles: *i.Roles.Cookie(), + Country: i.Country, + PrivacyPolicy: i.PrivacyPolicy, + Confirmd: i.Confirmed, + LastUpdate: i.LastUpdate, + Phone: i.Profile.Phone, + Gender: i.Profile.Gender, + Birthdate: i.Profile.Birthdate, + CrewName: i.Crew.Name, + CrewID: i.Crew.CrewID, + CrewEmail: i.Crew.Email, + OrganisationID: i.OrganisationID, + AddressID: i.Address.ID, + PoolRoles: *i.PoolRoles.Cookie(), + ActiveState: i.Active.Status, + NVMState: i.NVM.Status, + AvatarID: i.Avatar.ID, + MailboxID: i.MailboxID, + Modified: i.Modified, StandardClaims: jwt.StandardClaims{ ExpiresAt: time.Now().Add(time.Minute * 15).Unix(), }, @@ -340,35 +358,35 @@ func (i *ProfileUpdate) ToUserUpdate() *ProfileUpdate { } } -func UsersPermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || token.PoolRoles.Validate(ASPRole)) { +func UsersPermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || token.PoolRoles.Validate(ASPRole)) { return vcago.NewPermissionDenied(UserCollection) } return } -func (i *UserParam) UsersDeletePermission(token *vcapool.AccessToken) (err error) { - if !(token.Roles.Validate("employee;admin") || i.ID == token.ID) { +func (i *UserParam) UsersDeletePermission(token *AccessToken) (err error) { + if !(token.Roles.Validate("admin;employee;pool_employee") || i.ID == token.ID) { return vcago.NewPermissionDenied(UserCollection) } return } -func UsersDetailsPermission(token *vcapool.AccessToken) (err error) { - if !token.Roles.Validate("employee;admin") { +func UsersDetailsPermission(token *AccessToken) (err error) { + if !token.Roles.Validate("admin;employee;pool_employee") { return vcago.NewPermissionDenied(UserCollection) } return } -func UsersEditPermission(token *vcapool.AccessToken) (err error) { +func UsersEditPermission(token *AccessToken) (err error) { if !token.Roles.Validate("admin") { return vcago.NewPermissionDenied(UserCollection) } return } -func (i *UserQuery) CrewUsersPermission(token *vcapool.AccessToken) (err error) { +func (i *UserQuery) CrewUsersPermission(token *AccessToken) (err error) { if i.CrewID != "" && i.CrewID != token.CrewID { return vcago.NewPermissionDenied(UserCollection) } @@ -387,7 +405,7 @@ func (i UserQuery) Sort() bson.D { return sort.Bson() } -func (i *UserQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *UserQuery) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualBool("confirmed", "true") filter.LikeString("email", i.Email) @@ -399,16 +417,17 @@ func (i *UserQuery) PermittedFilter(token *vcapool.AccessToken) bson.D { filter.ElemMatchList("pool_roles", "name", i.PoolRoles) filter.EqualStringList("active.status", i.ActiveState) filter.EqualStringList("nvm.status", i.NVMState) - if !token.Roles.Validate("employee;admin") { - filter.EqualString("crew.crew_id", token.CrewID) - } else { + if token.Roles.Validate("admin;employee;pool_employee") { + filter.EqualStringList("crew.organisation_id", i.OrganisationID) filter.EqualString("crew.crew_id", i.CrewID) + } else { + filter.EqualString("crew.crew_id", token.CrewID) } filter.SearchString([]string{"_id", "first_name", "last_name", "email"}, i.Search) return filter.Bson() } -func (i *UserQuery) PermittedUserFilter(token *vcapool.AccessToken) bson.D { +func (i *UserQuery) PermittedUserFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.ElemMatchList("pool_roles", "name", []string{"network", "education", "finance", "operation", "awareness", "socialmedia", "other"}) filter.EqualBool("confirmed", "true") @@ -416,7 +435,7 @@ func (i *UserQuery) PermittedUserFilter(token *vcapool.AccessToken) bson.D { filter.LikeString("last_name", i.LastName) filter.LikeString("full_name", i.FullName) filter.LikeString("display_name", i.DisplayName) - if !token.Roles.Validate("employee;admin") { + if !token.Roles.Validate("admin;employee;pool_employee") { filter.EqualString("crew.crew_id", token.CrewID) } else { filter.EqualString("crew.crew_id", i.CrewID) diff --git a/models/user_crew.go b/models/user_crew.go index ea39f34..1a4e253 100644 --- a/models/user_crew.go +++ b/models/user_crew.go @@ -4,7 +4,6 @@ import ( "github.com/Viva-con-Agua/vcago" "github.com/Viva-con-Agua/vcago/vmdb" "github.com/Viva-con-Agua/vcago/vmod" - "github.com/Viva-con-Agua/vcapool" "github.com/google/uuid" "go.mongodb.org/mongo-driver/bson" ) @@ -16,32 +15,38 @@ type ( CrewID string `json:"crew_id"` } UsersCrewCreate struct { - CrewID string `json:"crew_id"` - UserID string `json:"user_id"` + CrewID string `json:"crew_id"` + UserID string `json:"user_id"` + OrganisationID string `bson:"organisation_id" json:"organisation_id"` } UserCrew struct { - ID string `bson:"_id" json:"id"` - UserID string `bson:"user_id" json:"user_id"` - Name string `bson:"name" json:"name"` - Email string `bson:"email" json:"email"` - Roles []vmod.Role `bson:"roles" json:"roles"` - CrewID string `bson:"crew_id" json:"crew_id"` - MailboxID string `bson:"mailbox_id" json:"mailbox_id"` - Modified vmod.Modified `bson:"modified" json:"modified"` + ID string `bson:"_id" json:"id"` + UserID string `bson:"user_id" json:"user_id"` + Name string `bson:"name" json:"name"` + Email string `bson:"email" json:"email"` + Roles []vmod.Role `bson:"roles" json:"roles"` + CrewID string `bson:"crew_id" json:"crew_id"` + OrganisationID string `bson:"organisation_id" json:"organisation_id"` + Organisation string `bson:"organisation" json:"organisation"` + MailboxID string `bson:"mailbox_id" json:"mailbox_id"` + Modified vmod.Modified `bson:"modified" json:"modified"` } UserCrewMinimal struct { - ID string `bson:"_id" json:"id"` - UserID string `bson:"user_id" json:"user_id"` - Name string `bson:"name" json:"name"` - Email string `bson:"email" json:"email"` - CrewID string `bson:"crew_id" json:"crew_id"` + ID string `bson:"_id" json:"id"` + UserID string `bson:"user_id" json:"user_id"` + Name string `bson:"name" json:"name"` + Email string `bson:"email" json:"email"` + CrewID string `bson:"crew_id" json:"crew_id"` + OrganisationID string `bson:"organisation_id" json:"organisation_id"` + Organisation string `bson:"organisation" json:"organisation"` } UserCrewUpdate struct { - ID string `bson:"_id" json:"id"` - UserID string `bson:"user_id" json:"user_id"` - Name string `bson:"name" json:"name"` - Email string `bson:"email" json:"email"` - CrewID string `bson:"crew_id" json:"crew_id"` + ID string `bson:"_id" json:"id"` + UserID string `bson:"user_id" json:"user_id"` + Name string `bson:"name" json:"name"` + Email string `bson:"email" json:"email"` + CrewID string `bson:"crew_id" json:"crew_id"` + OrganisationID string `bson:"organisation_id" json:"organisation_id"` } UserCrewParam struct { ID string `param:"id"` @@ -56,33 +61,34 @@ type ( } ) -func NewUserCrew(userID string, crewID string, name string, email string, mailboxID string) *UserCrew { +func NewUserCrew(userID string, crew *Crew) *UserCrew { return &UserCrew{ - ID: uuid.NewString(), - UserID: userID, - Name: name, - Email: email, - CrewID: crewID, - MailboxID: mailboxID, - Modified: vmod.NewModified(), + ID: uuid.NewString(), + UserID: userID, + Name: crew.Name, + Email: crew.Email, + CrewID: crew.ID, + OrganisationID: crew.OrganisationID, + MailboxID: crew.MailboxID, + Modified: vmod.NewModified(), } } -func (i *UserCrewUpdate) UserCrewUpdatePermission(token *vcapool.AccessToken) (err error) { +func (i *UserCrewUpdate) UserCrewUpdatePermission(token *AccessToken) (err error) { if token.ID != i.UserID { return vcago.NewPermissionDenied(CrewCollection) } return } -func (i *UserCrewUpdate) UsersCrewUpdatePermission(token *vcapool.AccessToken) (err error) { +func (i *UserCrewUpdate) UsersCrewUpdatePermission(token *AccessToken) (err error) { if !token.Roles.Validate("admin") { return vcago.NewPermissionDenied(CrewCollection) } return } -func (i *UsersCrewCreate) UsersCrewCreatePermission(token *vcapool.AccessToken) (err error) { +func (i *UsersCrewCreate) UsersCrewCreatePermission(token *AccessToken) (err error) { if !token.Roles.Validate("admin") { return vcago.NewPermissionDenied(CrewCollection) } @@ -151,13 +157,19 @@ func (i *UsersCrewCreate) CrewFilter() bson.D { return filter.Bson() } +func (i *UserCrewUpdate) CrewFilter() bson.D { + filter := vmdb.NewFilter() + filter.EqualString("_id", i.CrewID) + return filter.Bson() +} + func (i *UserCrewUpdate) Match() bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) return filter.Bson() } -func (i *UserCrewUpdate) PermittedFilter(token *vcapool.AccessToken) bson.D { +func (i *UserCrewUpdate) PermittedFilter(token *AccessToken) bson.D { filter := vmdb.NewFilter() filter.EqualString("_id", i.ID) filter.EqualString("user_id", token.ID) diff --git a/server.go b/server.go index 81ee64e..7648612 100644 --- a/server.go +++ b/server.go @@ -37,11 +37,16 @@ func main() { token.Address.Routes(tokenUser.Group("/address")) token.Avatar.Routes(tokenUser.Group("/avatar")) token.Newsletter.Routes(tokenUser.Group("/newsletter")) + token.User.Routes(tokenUser) //crew routes crews := api.Group("/crews") token.Crew.Routes(crews) + //crew routes + organisations := api.Group("/organisations") + token.Organisation.Routes(organisations) + mails := api.Group("/mails") token.Mailbox.Routes(mails.Group("/mailbox")) token.Message.Routes(mails.Group("/message")) @@ -56,6 +61,7 @@ func main() { token.Source.Routes(finances.Group("/source")) token.Taking.Routes(finances.Group("/taking")) token.Deposit.Routes(finances.Group("/deposit")) + token.ReceiptFile.Routes(finances.Group("/receipt")) key.Import.Routes(api.Group("/import"))