Compare commits
No commits in common. "f698891865b8b63971cd6e105bae6b7ea6fe890b" and "1b847ea21677da0984a30964c91e196dba1f716d" have entirely different histories.
f698891865
...
1b847ea216
2
go.mod
2
go.mod
|
@ -8,7 +8,7 @@ go 1.18
|
||||||
|
|
||||||
// replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
|
// replace git.coopgo.io/coopgo-platform/fleets => ../../coopgo-platform/fleets/
|
||||||
|
|
||||||
replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
|
// replace git.coopgo.io/coopgo-platform/agenda => ../../coopgo-platform/agenda/
|
||||||
|
|
||||||
// replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/
|
// replace git.coopgo.io/coopgo-platform/emailing => ../../coopgo-platform/emailing/
|
||||||
|
|
||||||
|
|
|
@ -231,8 +231,7 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
|
||||||
"subscribed_by": map[string]any{
|
"subscribed_by": map[string]any{
|
||||||
"user": map[string]any{
|
"user": map[string]any{
|
||||||
"id": current_user_token.Subject,
|
"id": current_user_token.Subject,
|
||||||
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
"display_name": current_user_claims["display_name"],
|
||||||
"email": current_user_claims["email"].(string),
|
|
||||||
},
|
},
|
||||||
"group": map[string]any{
|
"group": map[string]any{
|
||||||
"id": current_group.ID,
|
"id": current_group.ID,
|
||||||
|
@ -331,211 +330,6 @@ func contains(s []*agenda.Subscription, e string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////Delete subscriber///////////////////////////////
|
|
||||||
|
|
||||||
func (h *ApplicationHandler) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request) {
|
|
||||||
vars := mux.Vars(r)
|
|
||||||
eventId := vars["eventid"]
|
|
||||||
subscribeid := vars["subscribeid"]
|
|
||||||
s_b_id := ""
|
|
||||||
s_b_name := ""
|
|
||||||
s_b_email := ""
|
|
||||||
s_b_group_id := ""
|
|
||||||
s_b_group_name := ""
|
|
||||||
request := &agenda.GetEventRequest{
|
|
||||||
Id: eventId,
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := range resp.Event.Subscriptions {
|
|
||||||
if resp.Event.Subscriptions[i].Subscriber == subscribeid {
|
|
||||||
subscribed_by_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["id"].GetStringValue()
|
|
||||||
subscribed_by_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["display_name"].GetStringValue()
|
|
||||||
subscribed_by_email := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["user"].GetStructValue().Fields["email"].GetStringValue()
|
|
||||||
subscribed_by_group_id := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["id"].GetStringValue()
|
|
||||||
subscribed_by_group_name := resp.Event.Subscriptions[i].Data.Fields["subscribed_by"].GetStructValue().Fields["group"].GetStructValue().Fields["name"].GetStringValue()
|
|
||||||
s_b_id = subscribed_by_id
|
|
||||||
s_b_name = subscribed_by_name
|
|
||||||
s_b_email = subscribed_by_email
|
|
||||||
s_b_group_id = subscribed_by_group_id
|
|
||||||
s_b_group_name = subscribed_by_group_name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
current_group, err := h.currentGroup(r)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
current_user_token, current_user_claims, err := h.currentUser(r)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data := map[string]any{
|
|
||||||
"subscribed_by": map[string]any{
|
|
||||||
"user": map[string]any{
|
|
||||||
"id": s_b_id,
|
|
||||||
"display_name": s_b_name,
|
|
||||||
"email": s_b_email,
|
|
||||||
},
|
|
||||||
"group": map[string]any{
|
|
||||||
"id": s_b_group_id,
|
|
||||||
"name": s_b_group_name,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"unsubscribed_by": map[string]any{
|
|
||||||
"user": map[string]any{
|
|
||||||
"id": current_user_token.Subject,
|
|
||||||
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
|
||||||
"email": current_user_claims["email"],
|
|
||||||
},
|
|
||||||
"group": map[string]any{
|
|
||||||
"id": current_group.ID,
|
|
||||||
"name": current_group.Data["name"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"motif": r.FormValue("motif"),
|
|
||||||
}
|
|
||||||
|
|
||||||
datapb, err := structpb.NewStruct(data)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if r.Method == "POST" {
|
|
||||||
request := &agenda.DeleteSubscriptionRequest{
|
|
||||||
Subscriber: subscribeid,
|
|
||||||
Eventid: eventId,
|
|
||||||
Data: datapb,
|
|
||||||
}
|
|
||||||
|
|
||||||
data := map[string]any{
|
|
||||||
"key": r.FormValue("motif"),
|
|
||||||
"user": current_user_claims["email"],
|
|
||||||
}
|
|
||||||
|
|
||||||
// récupérer l'adresse mail de l'utilisateur qui a créé l'événement
|
|
||||||
mail := s_b_email;
|
|
||||||
fmt.Println(mail)
|
|
||||||
|
|
||||||
_, err := h.services.GRPC.Agenda.DeleteSubscription(context.TODO(), request)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := h.emailing.Send("delete_subscriber.request", mail, data); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", eventId), http.StatusFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
h.Renderer.AgendaDeleteSubscribeEvent(w, r, eventId)
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// /////////////////////History Event////////////////////////
|
|
||||||
func (h *ApplicationHandler) AgendaHistoryEvent(w http.ResponseWriter, r *http.Request) {
|
|
||||||
vars := mux.Vars(r)
|
|
||||||
eventId := vars["eventid"]
|
|
||||||
request := &agenda.GetEventRequest{
|
|
||||||
Id: eventId,
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := h.services.GRPC.Agenda.GetEvent(context.TODO(), request)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
grouprequest := &groupsmanagement.GetGroupRequest{
|
|
||||||
Id: resp.Event.Owners[0],
|
|
||||||
}
|
|
||||||
|
|
||||||
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), grouprequest)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
subscribers := map[string]any{}
|
|
||||||
|
|
||||||
accids := []string{}
|
|
||||||
for _, v := range resp.Event.DeletedSubscription {
|
|
||||||
accids = append(accids, v.Subscriber)
|
|
||||||
}
|
|
||||||
|
|
||||||
subscriberresp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(
|
|
||||||
context.TODO(),
|
|
||||||
&mobilityaccounts.GetAccountsBatchRequest{
|
|
||||||
Accountids: accids,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
for _, sub := range subscriberresp.Accounts {
|
|
||||||
subscribers[sub.Id] = sub.ToStorageType()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
g := r.Context().Value(identification.GroupKey)
|
|
||||||
if g == nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
group := g.(storage.Group)
|
|
||||||
|
|
||||||
accountids := []string{}
|
|
||||||
for _, m := range group.Members {
|
|
||||||
if !contains(resp.Event.DeletedSubscription, m) {
|
|
||||||
accountids = append(accountids, m)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountsBatch(
|
|
||||||
context.TODO(),
|
|
||||||
&mobilityaccounts.GetAccountsBatchRequest{
|
|
||||||
Accountids: accountids,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
accounts := []any{}
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
for _, acc := range accountresp.Accounts {
|
|
||||||
accounts = append(accounts, acc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
h.Renderer.AgendaHistoryEvent(w, r, resp.Event.ToStorageType(), groupresp.Group.ToStorageType(), subscribers, accounts)
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// func contains[V string](s []V, e V) bool {
|
// func contains[V string](s []V, e V) bool {
|
||||||
// for _, a := range s {
|
// for _, a := range s {
|
||||||
// if a == e {
|
// if a == e {
|
||||||
|
@ -544,5 +338,3 @@ func (h *ApplicationHandler) AgendaHistoryEvent(w http.ResponseWriter, r *http.R
|
||||||
// }
|
// }
|
||||||
// return false
|
// return false
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//test
|
|
||||||
|
|
4
main.go
4
main.go
|
@ -137,10 +137,6 @@ func main() {
|
||||||
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
|
appAdmin.HandleFunc("/groups/{groupid}/invite-member", applicationHandler.AdministrationGroupInviteMember)
|
||||||
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles)
|
appAdmin.HandleFunc("/stats/vehicles", applicationHandler.AdminStatVehicles)
|
||||||
|
|
||||||
/////////////////////////////////////Delete subscriber///////////////////////////////////////////////
|
|
||||||
application.HandleFunc("/agenda/{eventid}/{subscribeid}/delete", applicationHandler.AgendaDeleteSubscribeEvent)
|
|
||||||
application.HandleFunc("/agenda/{eventid}/history", applicationHandler.AgendaHistoryEvent)
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
fmt.Println("-> HTTP server listening on", address)
|
fmt.Println("-> HTTP server listening on", address)
|
||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
|
|
|
@ -38,31 +38,3 @@ func (renderer *Renderer) AgendaDisplayEvent(w http.ResponseWriter, r *http.Requ
|
||||||
|
|
||||||
renderer.Render("agenda create event", w, r, files, state)
|
renderer.Render("agenda create event", w, r, files, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////DElete subscriber//////////////////////////////////
|
|
||||||
func (renderer *Renderer) AgendaDeleteSubscribeEvent(w http.ResponseWriter, r *http.Request, eventid string) {
|
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.delete_subscriber.files")
|
|
||||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
|
||||||
state.ViewState = map[string]any{
|
|
||||||
"eventid": eventid,
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.Render("agenda delete subscriber", w, r, files, state)
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//////////////////////////History Event//////////////////////////////////
|
|
||||||
func (renderer *Renderer) AgendaHistoryEvent(w http.ResponseWriter, r *http.Request, event any, group any, subscribers map[string]any, beneficiaries any) {
|
|
||||||
files := renderer.ThemeConfig.GetStringSlice("views.agenda.history_event.files")
|
|
||||||
state := NewState(r, renderer.ThemeConfig, agendaMenu)
|
|
||||||
state.ViewState = map[string]any{
|
|
||||||
"event": event,
|
|
||||||
"group": group,
|
|
||||||
"subscribers": subscribers,
|
|
||||||
"beneficiaries": beneficiaries,
|
|
||||||
}
|
|
||||||
|
|
||||||
renderer.Render("agenda history event", w, r, files, state)
|
|
||||||
}
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
|
Loading…
Reference in New Issue