|
|
|
@@ -233,7 +233,8 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
|
|
|
|
|
"subscribed_by": map[string]any{
|
|
|
|
|
"user": map[string]any{
|
|
|
|
|
"id": current_user_token.Subject,
|
|
|
|
|
"display_name": dis,
|
|
|
|
|
"display_name": current_user_claims["first_name"].(string) + " " + current_user_claims["last_name"].(string),
|
|
|
|
|
"email": current_user_claims["email"].(string),
|
|
|
|
|
},
|
|
|
|
|
"group": map[string]any{
|
|
|
|
|
"id": current_group.ID,
|
|
|
|
@@ -332,6 +333,19 @@ func contains(s []*agenda.Subscription, e string) bool {
|
|
|
|
|
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,
|
|
|
|
|
///////////////////////////////Update Event/////////////////////////////////////////
|
|
|
|
|
func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
adm := strings.Split(r.URL.Path, "/")
|
|
|
|
@@ -346,6 +360,86 @@ func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Re
|
|
|
|
|
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 r.Method == "POST" {
|
|
|
|
|
g := r.Context().Value(identification.GroupKey)
|
|
|
|
|
if g == nil {
|
|
|
|
@@ -393,6 +487,26 @@ func (h *ApplicationHandler) AgendaUpdateEvent(w http.ResponseWriter, r *http.Re
|
|
|
|
|
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,
|
|
|
|
|
http.Redirect(w, r, fmt.Sprintf("/app/agenda/%s", resp.Event.Id), http.StatusFound)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@@ -414,6 +528,74 @@ func (h *ApplicationHandler) AgendaDeleteEvent(w http.ResponseWriter, r *http.Re
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
if r.Method == "POST" {
|
|
|
|
|
|
|
|
|
|
request := &agenda.UpdateEventRequest{
|
|
|
|
@@ -458,3 +640,5 @@ func (h *ApplicationHandler) AgendaDeleteEvent(w http.ResponseWriter, r *http.Re
|
|
|
|
|
// }
|
|
|
|
|
// return false
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
//test
|
|
|
|
|