fix issues in groups members management
Build and Push Docker Image / build_and_push (push) Failing after 1m26s
Details
Build and Push Docker Image / build_and_push (push) Failing after 1m26s
Details
This commit is contained in:
parent
dd30d7959b
commit
d46f62d92a
|
@ -100,7 +100,6 @@ func (h *APIHandler) CalendarOrganizations(w http.ResponseWriter, r *http.Reques
|
|||
|
||||
for _, e := range events {
|
||||
for _, g := range e.Owners {
|
||||
log.Debug().Str("groupid", groupid).Str("g", g).Msg("check identical")
|
||||
if g == groupid {
|
||||
filteredEvents = append(filteredEvents, e)
|
||||
continue
|
||||
|
|
|
@ -224,39 +224,35 @@ func (h *ApplicationHandler) AdministrationGroupInviteAdmin(w http.ResponseWrite
|
|||
accountresp *accounts.GetAccountUsernameResponse
|
||||
err error
|
||||
)
|
||||
go func() {
|
||||
groupresp, err = h.services.GRPC.GroupsManagement.GetGroup(context.TODO(), &groupsmanagement.GetGroupRequest{
|
||||
Id: groupid,
|
||||
Namespace: "parcoursmob_organizations",
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Issue in Groups management service - GetGroup")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}()
|
||||
r.ParseForm()
|
||||
|
||||
go func() {
|
||||
accountresp, err = h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
||||
Username: r.FormValue("username"),
|
||||
Namespace: "parcoursmob",
|
||||
})
|
||||
if err == nil {
|
||||
log.Print("account exists")
|
||||
// Account already exists : adding the existing account to admin list
|
||||
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")
|
||||
|
||||
as, _ := accounts.AccountFromStorageType(&account)
|
||||
|
||||
_, err = h.services.GRPC.MobilityAccounts.UpdateData(
|
||||
context.TODO(),
|
||||
&accounts.UpdateDataRequest{
|
||||
Account: as,
|
||||
},
|
||||
)
|
||||
if _, err = h.services.GRPC.MobilityAccounts.UpdateData(context.TODO(), &accounts.UpdateDataRequest{Account: as}); err != nil {
|
||||
log.Error().Err(err).Msg("could not set groups to user account")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
data := map[string]any{
|
||||
"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")
|
||||
}
|
||||
|
||||
http.Redirect(w, r, fmt.Sprintf("/app/administration/groups/%s", groupid), http.StatusFound)
|
||||
return
|
||||
} else {
|
||||
// Onboard now administrator
|
||||
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)
|
||||
return
|
||||
}()
|
||||
}
|
||||
|
||||
func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
groupid := vars["groupid"]
|
||||
var (
|
||||
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",
|
||||
})
|
||||
|
||||
group, err := h.services.GetGroup(groupid)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Issue in Groups management service - GetGroup")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
group := groupresp.Group.ToStorageType()
|
||||
groupCh <- group
|
||||
}()
|
||||
r.ParseForm()
|
||||
go func() {
|
||||
group = <-groupCh
|
||||
accountresp, err := h.services.GRPC.MobilityAccounts.GetAccountUsername(context.TODO(), &accounts.GetAccountUsernameRequest{
|
||||
Username: r.FormValue("username"),
|
||||
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 {
|
||||
log.Error().Err(err).Msg("error sending email onboarding.existing_member")
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/app/group/settings", http.StatusFound)
|
||||
return
|
||||
// http.Redirect(w, r, "/app/group/settings", http.StatusFound)
|
||||
// return
|
||||
} else {
|
||||
// Onboard now administrator
|
||||
// Onboard new administrator
|
||||
onboarding := map[string]any{
|
||||
"username": r.FormValue("username"),
|
||||
"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 {
|
||||
log.Error().Err(err).Msg("error sending email onboarding.new_member")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
http.Redirect(w, r, "/app/administration/groups/"+group.ID, http.StatusFound)
|
||||
return
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
bookings := []fleetsstorage.Booking{}
|
||||
administrators := []string{}
|
||||
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) {
|
||||
|
||||
vehicles := map[string]fleetsstorage.Vehicle{}
|
||||
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{
|
||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Issue in Agenda service - GetEvents")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
|
|
|
@ -42,7 +42,7 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques
|
|||
|
||||
administrators := []string{}
|
||||
|
||||
if r.FormValue("beneficiaryid") != "" {
|
||||
if r.FormValue("beneficiaryid") != "" && startdate.After(time.Now()) && enddate.After(startdate) {
|
||||
// Handler form
|
||||
searched = true
|
||||
|
||||
|
@ -247,7 +247,7 @@ func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
//NOTIFY GROUP MEMBERS
|
||||
// NOTIFY GROUP MEMBERS
|
||||
members, _, err := h.groupmembers(vehicle.Vehicle.Administrators[0])
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
g := r.Context().Value(identification.GroupKey)
|
||||
if g == nil {
|
||||
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)
|
||||
|
||||
}
|
||||
|
|
5
main.go
5
main.go
|
@ -20,11 +20,12 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
// zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||||
|
||||
cfg, err := ReadConfig()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatal().Err(err).Msg("cannot read config")
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -57,6 +57,20 @@ func (s *ServicesHandler) GetGroupsMemberMap(id string) (groups map[string]any,
|
|||
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
|
||||
|
||||
type GroupsManagementGroup struct {
|
||||
|
|
Loading…
Reference in New Issue