fix issues in groups members management
Build and Push Docker Image / build_and_push (push) Failing after 1m26s Details

This commit is contained in:
Arnaud Delcasse 2024-11-21 23:11:59 +01:00
parent dd30d7959b
commit d46f62d92a
5 changed files with 136 additions and 149 deletions

View File

@ -100,7 +100,6 @@ func (h *APIHandler) CalendarOrganizations(w http.ResponseWriter, r *http.Reques
for _, e := range events { for _, e := range events {
for _, g := range e.Owners { for _, g := range e.Owners {
log.Debug().Str("groupid", groupid).Str("g", g).Msg("check identical")
if g == groupid { if g == groupid {
filteredEvents = append(filteredEvents, e) filteredEvents = append(filteredEvents, e)
continue continue

View File

@ -224,39 +224,35 @@ func (h *ApplicationHandler) AdministrationGroupInviteAdmin(w http.ResponseWrite
accountresp *accounts.GetAccountUsernameResponse accountresp *accounts.GetAccountUsernameResponse
err error err error
) )
go func() {
groupresp, err = h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{ groupresp, err = h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
Id: groupid, Id: groupid,
Namespace: "parcoursmob_organizations", Namespace: "parcoursmob_organizations",
}) })
if err != nil { if err != nil {
log.Error().Err(err).Msg("Issue in Groups management service - GetGroup") log.Error().Err(err).Msg("Issue in Groups management service - GetGroup")
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
}()
r.ParseForm() r.ParseForm()
go func() {
accountresp, err = h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{ accountresp, err = h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
Username: r.FormValue("username"), Username: r.FormValue("username"),
Namespace: "parcoursmob", Namespace: "parcoursmob",
}) })
if err == nil { if err == nil {
log.Print("account exists")
// Account already exists : adding the existing account to admin list // Account already exists : adding the existing account to admin list
account := accountresp.Account.ToStorageType() account := accountresp.Account.ToStorageType()
account.Data["groups"] = append(account.Data["groups"].([]any), groupid, groupid) // account.Data["groups"] = append(account.Data["groups"].([]any), groupid, groupid)
account.Data["groups"] = append(account.Data["groups"].([]any), groupid, groupid+":admin") account.Data["groups"] = append(account.Data["groups"].([]any), groupid, groupid+":admin")
as, _ := accounts.AccountFromStorageType(&account) as, _ := accounts.AccountFromStorageType(&account)
_, err = h.services.GRPC.MobilityAccounts.UpdateData( if _, err = h.services.GRPC.MobilityAccounts.UpdateData(context.TODO(), &accounts.UpdateDataRequest{Account: as}); err != nil {
context.TODO(), log.Error().Err(err).Msg("could not set groups to user account")
&accounts.UpdateDataRequest{ w.WriteHeader(http.StatusInternalServerError)
Account: as, return
}, }
)
data := map[string]any{ data := map[string]any{
"group": groupresp.Group.ToStorageType().Data["name"], "group": groupresp.Group.ToStorageType().Data["name"],
@ -266,8 +262,6 @@ func (h *ApplicationHandler) AdministrationGroupInviteAdmin(w http.ResponseWrite
log.Error().Err(err).Msg("Cannot send email") log.Error().Err(err).Msg("Cannot send email")
} }
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
return
} else { } else {
// Onboard now administrator // Onboard now administrator
onboarding := map[string]any{ onboarding := map[string]any{
@ -299,33 +293,18 @@ func (h *ApplicationHandler) AdministrationGroupInviteAdmin(w http.ResponseWrite
} }
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound) http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
return
}()
} }
func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
groupid := vars["groupid"] groupid := vars["groupid"]
var ( group, err := h.services.GetGroup(groupid)
group storage.Group
)
groupCh := make(chan storage.Group)
go func() {
groupresp, err := h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
Id: groupid,
Namespace: "parcoursmob_organizations",
})
if err != nil { if err != nil {
log.Error().Err(err).Msg("Issue in Groups management service - GetGroup") log.Error().Err(err).Msg("Issue in Groups management service - GetGroup")
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
group := groupresp.Group.ToStorageType()
groupCh <- group
}()
r.ParseForm() r.ParseForm()
go func() {
group = <-groupCh
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{ accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
Username: r.FormValue("username"), Username: r.FormValue("username"),
Namespace: "parcoursmob", Namespace: "parcoursmob",
@ -347,12 +326,13 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
} }
if err := h.emailing.Send("onboarding.existing_member", r.FormValue("username"), data); err != nil { if err := h.emailing.Send("onboarding.existing_member", r.FormValue("username"), data); err != nil {
log.Error().Err(err).Msg("error sending email onboarding.existing_member")
} }
http.Redirect(w, r, "/app/group/settings", http.StatusFound) // http.Redirect(w, r, "/app/group/settings", http.StatusFound)
return // return
} else { } else {
// Onboard now administrator // Onboard new administrator
onboarding := map[string]any{ onboarding := map[string]any{
"username": r.FormValue("username"), "username": r.FormValue("username"),
"group": group.ID, "group": group.ID,
@ -373,13 +353,12 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
} }
if err := h.emailing.Send("onboarding.new_member", r.FormValue("username"), data); err != nil { if err := h.emailing.Send("onboarding.new_member", r.FormValue("username"), data); err != nil {
log.Error().Err(err).Msg("error sending email onboarding.new_member")
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
} }
}()
http.Redirect(w, r, "/app/administration/groups/"+group.ID, http.StatusFound) http.Redirect(w, r, "/app/administration/groups/"+group.ID, http.StatusFound)
return
} }
func filteVehicle(r *http.Request, v *fleets.Vehicle) bool { func filteVehicle(r *http.Request, v *fleets.Vehicle) bool {
@ -400,7 +379,6 @@ func filteVehicle(r *http.Request, v *fleets.Vehicle) bool {
} }
func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Request) { func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Request) {
bookings := []fleetsstorage.Booking{} bookings := []fleetsstorage.Booking{}
administrators := []string{} administrators := []string{}
reequest := &fleets.GetVehiclesRequest{ reequest := &fleets.GetVehiclesRequest{
@ -462,7 +440,6 @@ func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Req
} }
func (h ApplicationHandler) AdminStatBookings(w http.ResponseWriter, r *http.Request) { func (h ApplicationHandler) AdminStatBookings(w http.ResponseWriter, r *http.Request) {
vehicles := map[string]fleetsstorage.Vehicle{} vehicles := map[string]fleetsstorage.Vehicle{}
bookings := []fleetsstorage.Booking{} bookings := []fleetsstorage.Booking{}
@ -578,7 +555,6 @@ func (h ApplicationHandler) AdminStatEvents(w http.ResponseWriter, r *http.Reque
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{ resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
Namespaces: []string{"parcoursmob_dispositifs"}, Namespaces: []string{"parcoursmob_dispositifs"},
}) })
if err != nil { if err != nil {
log.Error().Err(err).Msg("Issue in Agenda service - GetEvents") log.Error().Err(err).Msg("Issue in Agenda service - GetEvents")
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)

View File

@ -42,7 +42,7 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques
administrators := []string{} administrators := []string{}
if r.FormValue("beneficiaryid") != "" { if r.FormValue("beneficiaryid") != "" && startdate.After(time.Now()) && enddate.After(startdate) {
// Handler form // Handler form
searched = true searched = true
@ -247,7 +247,7 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
return return
} }
//NOTIFY GROUP MEMBERS // NOTIFY GROUP MEMBERS
members, _, err := h.groupmembers(vehicle.Vehicle.Administrators[0]) members, _, err := h.groupmembers(vehicle.Vehicle.Administrators[0])
if err != nil { if err != nil {
log.Error().Err(err).Msg("") log.Error().Err(err).Msg("")
@ -262,7 +262,6 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
} }
http.Redirect(w, r, fmt.Sprintf("/app/vehicles/bookings/%s", booking.Id), http.StatusFound) http.Redirect(w, r, fmt.Sprintf("/app/vehicles/bookings/%s", booking.Id), http.StatusFound)
} }
func (h ApplicationHandler) VehicleBookingDisplay(w http.ResponseWriter, r *http.Request) { func (h ApplicationHandler) VehicleBookingDisplay(w http.ResponseWriter, r *http.Request) {
@ -310,7 +309,6 @@ func (h ApplicationHandler) VehicleBookingDisplay(w http.ResponseWriter, r *http
} }
func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.Request) { func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.Request) {
g := r.Context().Value(identification.GroupKey) g := r.Context().Value(identification.GroupKey)
if g == nil { if g == nil {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
@ -371,5 +369,4 @@ func (h *ApplicationHandler) BookingDocumentDownload(w http.ResponseWriter, r *h
} }
http.Redirect(w, r, fmt.Sprintf("/app/vehicles/bookings/%s", bookingid), http.StatusFound) http.Redirect(w, r, fmt.Sprintf("/app/vehicles/bookings/%s", bookingid), http.StatusFound)
} }

View File

@ -20,11 +20,12 @@ import (
) )
func main() { func main() {
// zerolog.TimeFieldFormat = zerolog.TimeFormatUnix zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
cfg, err := ReadConfig() cfg, err := ReadConfig()
if err != nil { if err != nil {
panic(err) log.Fatal().Err(err).Msg("cannot read config")
return
} }
var ( var (

View File

@ -57,6 +57,20 @@ func (s *ServicesHandler) GetGroupsMemberMap(id string) (groups map[string]any,
return return
} }
func (s *ServicesHandler) GetGroup(groupid string) (*storage.Group, error) {
groupresp, err := s.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
Id: groupid,
Namespace: "parcoursmob_organizations",
})
if err != nil {
return nil, err
}
group := groupresp.Group.ToStorageType()
return &group, nil
}
// Enriched types // Enriched types
type GroupsManagementGroup struct { type GroupsManagementGroup struct {