Release 5 december 2022 - Agenda and Fleets fixes

This commit is contained in:
Arnaud Delcasse 2022-12-05 20:06:22 +01:00
parent 203aadaee1
commit a3ee210547
18 changed files with 357 additions and 79 deletions

6
go.mod
View File

@ -30,10 +30,10 @@ require (
) )
require ( require (
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9
git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15 git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221101232521-da16c90fc3ba git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544 git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe
github.com/gorilla/securecookie v1.1.1 github.com/gorilla/securecookie v1.1.1
github.com/minio/minio-go/v7 v7.0.43 github.com/minio/minio-go/v7 v7.0.43

8
go.sum
View File

@ -38,12 +38,20 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b h1:7kLW1khfGguZ2aL+QpWFwZmAdEcY1MsUjLdiRufjr2s= git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b h1:7kLW1khfGguZ2aL+QpWFwZmAdEcY1MsUjLdiRufjr2s=
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b/go.mod h1:wqPvfYmzGF2cfXbs8XE1P2j5UYqZwp/La0llkl7dUkc= git.coopgo.io/coopgo-platform/agenda v0.0.0-20221017030035-4a26fc791c5b/go.mod h1:wqPvfYmzGF2cfXbs8XE1P2j5UYqZwp/La0llkl7dUkc=
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9 h1:aP/OxSxOUM7D5PcIs+VSU90Pyy+SSUOOM54FZvPmZ8w=
git.coopgo.io/coopgo-platform/agenda v0.0.0-20221205162112-5feb1b720ef9/go.mod h1:wqPvfYmzGF2cfXbs8XE1P2j5UYqZwp/La0llkl7dUkc=
git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15 h1:+ZI4nGE6mqZ6pc7N/BizheEPRXn6Z84Sj7ikwfP2ZcU= git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15 h1:+ZI4nGE6mqZ6pc7N/BizheEPRXn6Z84Sj7ikwfP2ZcU=
git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15/go.mod h1:rmbqiHVkONcECOoPlsXlxZnD315Tiz2oRnn1M7646Kg= git.coopgo.io/coopgo-platform/emailing v0.0.0-20221017030337-c71888d90c15/go.mod h1:rmbqiHVkONcECOoPlsXlxZnD315Tiz2oRnn1M7646Kg=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221101232521-da16c90fc3ba h1:clfkgihzYa3xWKSY/Sn6VUSydOReh7cpuihvYNkWjNk= git.coopgo.io/coopgo-platform/fleets v0.0.0-20221101232521-da16c90fc3ba h1:clfkgihzYa3xWKSY/Sn6VUSydOReh7cpuihvYNkWjNk=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221101232521-da16c90fc3ba/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY= git.coopgo.io/coopgo-platform/fleets v0.0.0-20221101232521-da16c90fc3ba/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205162030-cecdcb20e1d5 h1:HL/M681G9R1ZN8XPp4LvG9hcF20//R9yQmr5cdXwQaM=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205162030-cecdcb20e1d5/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b h1:wvK1V8fFmHgnzVyleEF6Jq0Jcp5cVpPfW7WjMYiTTrE=
git.coopgo.io/coopgo-platform/fleets v0.0.0-20221205181518-91991789db9b/go.mod h1:s9OIFCNcjBAbBzRNHwoCTYV6kAntPG9CpT3GVweGdTY=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544 h1:rMLP77uIEequVXXZ0X9G1iK2k+xvW/+58ggwxxI6gqY= git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544 h1:rMLP77uIEequVXXZ0X9G1iK2k+xvW/+58ggwxxI6gqY=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA= git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221017025751-671dc9a2c544/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0 h1:CnLKO1kzoGtaqPhDqfOX3WPRFRcJVJZdGzPdBE4X//w=
git.coopgo.io/coopgo-platform/groups-management v0.0.0-20221205161801-9705c8d898f0/go.mod h1:lozSy6qlIIYhvKKXscZzz28HAtS0qBDUTv5nofLRmYA=
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe h1:4OKwfKybR0VsIw2dSM9RtqGWveWPt+JjtiiMIBrg/w0= git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe h1:4OKwfKybR0VsIw2dSM9RtqGWveWPt+JjtiiMIBrg/w0=
git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe/go.mod h1:1typNYtO+PQT6KG77vs/PUv0fO60/nbeSGZL2tt1LLg= git.coopgo.io/coopgo-platform/mobility-accounts v0.0.0-20220906130339-b9a32e41bffe/go.mod h1:1typNYtO+PQT6KG77vs/PUv0fO60/nbeSGZL2tt1LLg=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=

View File

@ -22,6 +22,27 @@ import (
func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) {
accounts, err := h.services.GetAccounts()
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
beneficiaries, err := h.services.GetBeneficiaries()
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
bookings, err := h.services.GetBookings()
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
request := &groupsmanagement.GetGroupsRequest{ request := &groupsmanagement.GetGroupsRequest{
Namespaces: []string{"parcoursmob_organizations"}, Namespaces: []string{"parcoursmob_organizations"},
} }
@ -42,7 +63,7 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque
sort.Sort(sorting.GroupsByName(groups)) sort.Sort(sorting.GroupsByName(groups))
h.Renderer.Administration(w, r, groups) h.Renderer.Administration(w, r, accounts, beneficiaries, groups, bookings)
} }
func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r *http.Request) {
@ -62,6 +83,8 @@ func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r
"vehicles": r.FormValue("modules.vehicles") == "on", "vehicles": r.FormValue("modules.vehicles") == "on",
"vehicles_management": r.FormValue("modules.vehicles_management") == "on", "vehicles_management": r.FormValue("modules.vehicles_management") == "on",
"events": r.FormValue("modules.events") == "on", "events": r.FormValue("modules.events") == "on",
"agenda": r.FormValue("modules.agenda") == "on",
"groups": r.FormValue("modules.groups") == "on",
"administration": r.FormValue("modules.administration") == "on", "administration": r.FormValue("modules.administration") == "on",
} }
@ -130,30 +153,6 @@ func (h *ApplicationHandler) AdministrationGroupDisplay(w http.ResponseWriter, r
return return
} }
// members, err := h.members()
// if err != nil {
// if err != nil {
// fmt.Println(err)
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// }
// groupmembers := []any{}
// admins := []any{}
// for _, m := range members {
// mm := m.ToStorageType()
// for _, g := range mm.Data["groups"].([]any) {
// if g.(string) == groupid {
// groupmembers = append(groupmembers, mm)
// }
// if g.(string) == groupid+":admin" {
// admins = append(admins, mm)
// }
// }
// }
groupmembers, admins, err := h.groupmembers(groupid) groupmembers, admins, err := h.groupmembers(groupid)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)

View File

@ -205,6 +205,18 @@ func (h *ApplicationHandler) AgendaDisplayEvent(w http.ResponseWriter, r *http.R
} }
func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http.Request) {
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
}
vars := mux.Vars(r) vars := mux.Vars(r)
eventid := vars["eventid"] eventid := vars["eventid"]
@ -215,13 +227,32 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
} }
subscriber := r.FormValue("subscriber") subscriber := r.FormValue("subscriber")
data := map[string]any{
"subscribed_by": map[string]any{
"user": map[string]any{
"id": current_user_token.Subject,
"display_name": current_user_claims["display_name"],
},
"group": map[string]any{
"id": current_group.ID,
"name": current_group.Data["name"],
},
},
}
datapb, err := structpb.NewStruct(data)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
request := &agenda.SubscribeEventRequest{ request := &agenda.SubscribeEventRequest{
Eventid: eventid, Eventid: eventid,
Subscriber: subscriber, Subscriber: subscriber,
Data: datapb,
} }
_, err := h.services.GRPC.Agenda.SubscribeEvent(context.TODO(), request) _, err = h.services.GRPC.Agenda.SubscribeEvent(context.TODO(), request)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)

View File

@ -1,12 +1,16 @@
package application package application
import ( import (
"errors"
"net/http" "net/http"
"git.coopgo.io/coopgo-apps/parcoursmob/renderer" "git.coopgo.io/coopgo-apps/parcoursmob/renderer"
"git.coopgo.io/coopgo-apps/parcoursmob/services" "git.coopgo.io/coopgo-apps/parcoursmob/services"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
"git.coopgo.io/coopgo-platform/emailing" "git.coopgo.io/coopgo-platform/emailing"
"git.coopgo.io/coopgo-platform/groups-management/storage"
"github.com/coreos/go-oidc"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -39,3 +43,31 @@ func (h *ApplicationHandler) NotFound(w http.ResponseWriter, r *http.Request) {
func (h *ApplicationHandler) templateFile(file string) string { func (h *ApplicationHandler) templateFile(file string) string {
return h.config.GetString("templates.root") + file return h.config.GetString("templates.root") + file
} }
func (h *ApplicationHandler) currentGroup(r *http.Request) (current_group storage.Group, err error) {
g := r.Context().Value(identification.GroupKey)
if g == nil {
return storage.Group{}, errors.New("current group not found")
}
current_group = g.(storage.Group)
return current_group, nil
}
func (h *ApplicationHandler) currentUser(r *http.Request) (current_user_token *oidc.IDToken, current_user_claims map[string]any, err error) {
// Get current user ID
u := r.Context().Value(identification.IdtokenKey)
if u == nil {
return nil, nil, errors.New("current user not found")
}
current_user_token = u.(*oidc.IDToken)
// Get current user claims
c := r.Context().Value(identification.ClaimsKey)
if c == nil {
return current_user_token, nil, errors.New("current user claims not found")
}
current_user_claims = c.(map[string]any)
return current_user_token, current_user_claims, nil
}

View File

@ -135,9 +135,6 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
return return
} }
//TODO filter namespaces
//TODO filter groups
bookingsrequest := &fleets.GetDriverBookingsRequest{ bookingsrequest := &fleets.GetDriverBookingsRequest{
Driver: beneficiaryID, Driver: beneficiaryID,
} }
@ -154,10 +151,25 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
bookings = append(bookings, b.ToStorageType()) bookings = append(bookings, b.ToStorageType())
} }
groupsrequest := &groupsmanagement.GetGroupsRequest{
Namespaces: []string{"parcoursmob_organizations"},
Member: beneficiaryID,
}
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroups(context.TODO(), groupsrequest)
if err != nil {
fmt.Println(err)
}
organizations := []any{}
for _, o := range groupsresp.Groups {
organizations = append(organizations, o.ToStorageType())
}
beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types") beneficiaries_file_types := h.config.GetStringSlice("modules.beneficiaries.documents_types")
file_types_map := h.config.GetStringMapString("storage.files.file_types") file_types_map := h.config.GetStringMapString("storage.files.file_types")
h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, beneficiaries_file_types, file_types_map, documents) h.Renderer.BeneficiaryDisplay(w, r, resp.Account.ToStorageType(), bookings, organizations, beneficiaries_file_types, file_types_map, documents)
} }
func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) BeneficiaryUpdate(w http.ResponseWriter, r *http.Request) {

View File

@ -12,6 +12,7 @@ import (
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage" agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
"git.coopgo.io/coopgo-platform/groups-management/storage" "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi" mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
"google.golang.org/protobuf/types/known/timestamppb"
) )
func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) { func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
@ -51,7 +52,7 @@ func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
} }
} }
members, err := h.members() members, _, err := h.groupmembers(group.ID)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
@ -64,6 +65,7 @@ func (h *ApplicationHandler) Dashboard(w http.ResponseWriter, r *http.Request) {
eventsresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{ eventsresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
Namespaces: []string{"parcoursmob_dispositifs"}, Namespaces: []string{"parcoursmob_dispositifs"},
Mindate: timestamppb.Now(),
}) })
for _, e := range eventsresp.Events { for _, e := range eventsresp.Events {

View File

@ -77,7 +77,12 @@ func (h *ApplicationHandler) VehiclesManagementBookingsList(w http.ResponseWrite
if filterVehicle(r, vehicle) { if filterVehicle(r, vehicle) {
v := vehicle.ToStorageType() v := vehicle.ToStorageType()
vehicles_map[v.ID] = v vehicles_map[v.ID] = v
bookings = append(bookings, v.Bookings...) // bookings = append(bookings, v.Bookings...)
for _, b := range v.Bookings {
if v, ok := b.Data["administrator_unavailability"].(bool); !ok || !v {
bookings = append(bookings, b)
}
}
} }
} }
@ -227,22 +232,17 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
vars := mux.Vars(r) vars := mux.Vars(r)
bookingid := vars["bookingid"] bookingid := vars["bookingid"]
request := &fleets.GetBookingRequest{ booking, err := h.services.GetBooking(bookingid)
Bookingid: bookingid,
}
resp, err := h.services.GRPC.Fleets.GetBooking(context.TODO(), request)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
booking := resp.Booking.ToStorageType()
if r.Method == "POST" { if r.Method == "POST" {
r.ParseForm() r.ParseForm()
newbooking := resp.Booking newbooking, _ := fleets.BookingFromStorageType(&booking)
startdate := r.FormValue("startdate") startdate := r.FormValue("startdate")
if startdate != "" { if startdate != "" {
@ -318,10 +318,61 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
return return
} }
alternativerequest := &fleets.GetVehiclesRequest{
Namespaces: []string{"parcoursmob"},
AvailabilityFrom: timestamppb.New(booking.Startdate),
AvailabilityTo: timestamppb.New(booking.Enddate.Add(24 * time.Hour)),
}
alternativeresp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), alternativerequest)
if err != nil {
fmt.Println(err)
}
alternatives := []any{}
for _, a := range alternativeresp.Vehicles {
alternatives = append(alternatives, a.ToStorageType())
}
documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid) documents := h.filestorage.List(filestorage.PREFIX_BOOKINGS + "/" + bookingid)
file_types_map := h.config.GetStringMapString("storage.files.file_types") file_types_map := h.config.GetStringMapString("storage.files.file_types")
h.Renderer.VehicleManagementBookingDisplay(w, r, booking, booking.Vehicle, beneficiary, groupresp.Group.ToStorageType(), documents, file_types_map) h.Renderer.VehicleManagementBookingDisplay(w, r, booking, booking.Vehicle, beneficiary, groupresp.Group.ToStorageType(), documents, file_types_map, alternatives)
}
func (h ApplicationHandler) VehicleManagementBookingChangeVehicle(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
bookingid := vars["bookingid"]
r.ParseForm()
newvehicle := r.FormValue("vehicle")
booking, err := h.services.GetBooking(bookingid)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
booking.Vehicleid = newvehicle
b, _ := fleets.BookingFromStorageType(&booking)
request := &fleets.UpdateBookingRequest{
Booking: b,
}
_, err = h.services.GRPC.Fleets.UpdateBooking(context.TODO(), request)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
http.Redirect(w, r, fmt.Sprintf("/app/vehicles-management/bookings/%s", bookingid), http.StatusFound)
} }
func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter, r *http.Request) { // Get Group func (h ApplicationHandler) VehiclesFleetMakeUnavailable(w http.ResponseWriter, r *http.Request) { // Get Group

View File

@ -13,11 +13,11 @@ import (
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting" "git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi" fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
"git.coopgo.io/coopgo-platform/fleets/storage"
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi" groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
"git.coopgo.io/coopgo-platform/groups-management/storage" groupsmanagementstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi" mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"github.com/coreos/go-oidc"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"google.golang.org/protobuf/types/known/structpb" "google.golang.org/protobuf/types/known/structpb"
@ -137,31 +137,44 @@ func (h ApplicationHandler) VehiclesSearch(w http.ResponseWriter, r *http.Reques
func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) { func (h ApplicationHandler) Book(w http.ResponseWriter, r *http.Request) {
// Get Group // Get Group
g := r.Context().Value(identification.GroupKey) // g := r.Context().Value(identification.GroupKey)
if g == nil { // if g == nil {
fmt.Println("no current group") // fmt.Println("no current group")
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// current_group := g.(storage.Group)
current_group, err := h.currentGroup(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
current_group := g.(storage.Group)
// Get current user ID // Get current user ID
u := r.Context().Value(identification.IdtokenKey) // u := r.Context().Value(identification.IdtokenKey)
if u == nil { // if u == nil {
fmt.Println("no current user") // fmt.Println("no current user")
w.WriteHeader(http.StatusInternalServerError) // w.WriteHeader(http.StatusInternalServerError)
return // return
} // }
current_user_token := u.(*oidc.IDToken) // current_user_token := u.(*oidc.IDToken)
// Get current user claims // // Get current user claims
c := r.Context().Value(identification.ClaimsKey) // c := r.Context().Value(identification.ClaimsKey)
if c == nil { // if c == nil {
fmt.Println("no current user claims") // fmt.Println("no current user claims")
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// current_user_claims := c.(map[string]any)
current_user_token, current_user_claims, err := h.currentUser(r)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
return return
} }
current_user_claims := c.(map[string]any)
vars := mux.Vars(r) vars := mux.Vars(r)
vehicleid := vars["vehicleid"] vehicleid := vars["vehicleid"]
@ -324,6 +337,15 @@ 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)
if g == nil {
w.WriteHeader(http.StatusBadRequest)
return
}
group := g.(groupsmanagementstorage.Group)
request := &fleets.GetBookingsRequest{} request := &fleets.GetBookingsRequest{}
resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), request) resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), request)
if err != nil { if err != nil {
@ -332,11 +354,21 @@ func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.
return return
} }
bookings := []any{} bookings := []storage.Booking{}
for _, b := range resp.Bookings { for _, b := range resp.Bookings {
bookings = append(bookings, b.ToStorageType()) booking := b.ToStorageType()
if b1, ok := booking.Data["booked_by"].(map[string]any); ok {
if b2, ok := b1["group"].(map[string]any); ok {
if b2["id"] == group.ID {
bookings = append(bookings, booking)
} }
}
}
}
sort.Sort(sorting.BookingsByStartdate(bookings))
h.Renderer.VehicleBookingsList(w, r, bookings) h.Renderer.VehicleBookingsList(w, r, bookings)
} }

View File

@ -97,6 +97,7 @@ func main() {
application.HandleFunc("/vehicles-management/fleet/{vehicleid}/update", applicationHandler.VehiclesFleetUpdate) application.HandleFunc("/vehicles-management/fleet/{vehicleid}/update", applicationHandler.VehiclesFleetUpdate)
application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList) application.HandleFunc("/vehicles-management/bookings/", applicationHandler.VehiclesManagementBookingsList)
application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay) application.HandleFunc("/vehicles-management/bookings/{bookingid}", applicationHandler.VehicleManagementBookingDisplay)
application.HandleFunc("/vehicles-management/bookings/{bookingid}/change-vehicle", applicationHandler.VehicleManagementBookingChangeVehicle)
application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload) application.HandleFunc("/vehicles-management/bookings/{bookingid}/documents/{document}", applicationHandler.BookingDocumentDownload)
application.HandleFunc("/agenda/", applicationHandler.AgendaHome) application.HandleFunc("/agenda/", applicationHandler.AgendaHome)
application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent) application.HandleFunc("/agenda/create-event", applicationHandler.AgendaCreateEvent)

View File

@ -8,10 +8,13 @@ import (
const administrationMenu = "administration" const administrationMenu = "administration"
func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request, groups any) { func (renderer *Renderer) Administration(w http.ResponseWriter, r *http.Request, accounts any, beneficiaries any, groups any, bookings any) {
files := renderer.ThemeConfig.GetStringSlice("views.administration.home.files") files := renderer.ThemeConfig.GetStringSlice("views.administration.home.files")
state := NewState(r, renderer.ThemeConfig, administrationMenu) state := NewState(r, renderer.ThemeConfig, administrationMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{
"accounts": accounts,
"beneficiaries": beneficiaries,
"bookings": bookings,
"groups": groups, "groups": groups,
} }

View File

@ -52,7 +52,7 @@ type BeneficiariesDisplayState struct {
Beneficiary any Beneficiary any
} }
func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any) { func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Request, beneficiary any, bookings []any, organizations []any, beneficiaries_file_types []string, file_types_map map[string]string, documents any) {
files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files") files := renderer.ThemeConfig.GetStringSlice("views.beneficiaries.display.files")
state := NewState(r, renderer.ThemeConfig, beneficiariesMenu) state := NewState(r, renderer.ThemeConfig, beneficiariesMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{
@ -61,6 +61,7 @@ func (renderer *Renderer) BeneficiaryDisplay(w http.ResponseWriter, r *http.Requ
"beneficiaries_file_types": beneficiaries_file_types, "beneficiaries_file_types": beneficiaries_file_types,
"file_types_map": file_types_map, "file_types_map": file_types_map,
"documents": documents, "documents": documents,
"organizations": organizations,
} }
renderer.Render("beneficiaries_display", w, r, files, state) renderer.Render("beneficiaries_display", w, r, files, state)

View File

@ -23,6 +23,17 @@ func TimeFrom(d any) *time.Time {
return nil return nil
} }
func TimeFormat(d any, f string) string {
date := TimeFrom(d)
if date == nil {
return ""
}
if date.Before(time.Now().Add(-24 * 365 * 30 * time.Hour)) {
return ""
}
return date.Format(f)
}
func GenderISO5218(d any) string { func GenderISO5218(d any) string {
if date, ok := d.(string); ok { if date, ok := d.(string); ok {
switch date { switch date {

View File

@ -9,6 +9,7 @@ import (
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification" "git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
"git.coopgo.io/coopgo-platform/emailing" "git.coopgo.io/coopgo-platform/emailing"
"git.coopgo.io/coopgo-platform/groups-management/storage" "git.coopgo.io/coopgo-platform/groups-management/storage"
"github.com/coreos/go-oidc"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -35,6 +36,7 @@ func NewRenderer(global *viper.Viper, templates_dir string) *Renderer {
} }
func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Request, files []string, state RenderState) { func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Request, files []string, state RenderState) {
genericFiles := renderer.ThemeConfig.GetStringSlice("views.generic.files") genericFiles := renderer.ThemeConfig.GetStringSlice("views.generic.files")
prefixed_files := []string{} prefixed_files := []string{}
@ -49,6 +51,7 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req
t := template.New(name).Funcs( t := template.New(name).Funcs(
template.FuncMap{ template.FuncMap{
"timeFrom": TimeFrom, "timeFrom": TimeFrom,
"timeFormat": TimeFormat,
"genderISO5218": GenderISO5218, "genderISO5218": GenderISO5218,
"dict": Dict, "dict": Dict,
"json": JSON, "json": JSON,
@ -66,6 +69,7 @@ func (renderer *Renderer) Render(name string, w http.ResponseWriter, r *http.Req
} }
func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *http.Request, files []string, state RenderState) { func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *http.Request, files []string, state RenderState) {
prefixed_files := []string{} prefixed_files := []string{}
for _, f := range files { for _, f := range files {
prefixed_files = append(prefixed_files, renderer.templateFile(f)) prefixed_files = append(prefixed_files, renderer.templateFile(f))
@ -75,6 +79,7 @@ func (renderer *Renderer) RenderNoLayout(name string, w http.ResponseWriter, r *
t := template.New(name).Funcs( t := template.New(name).Funcs(
template.FuncMap{ template.FuncMap{
"timeFrom": TimeFrom, "timeFrom": TimeFrom,
"timeFormat": TimeFormat,
"genderISO5218": GenderISO5218, "genderISO5218": GenderISO5218,
"dict": Dict, "dict": Dict,
"json": JSON, "json": JSON,
@ -97,14 +102,34 @@ func (r *Renderer) templateFile(file string) string {
type RenderState struct { type RenderState struct {
icons.IconSet icons.IconSet
LayoutState LayoutState
Group any UserID string
UserClaims map[string]any
Group storage.Group
Roles any Roles any
ViewState any // This is a state specific to a given view ViewState any // This is a state specific to a given view
} }
func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) RenderState { func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) RenderState {
iconset := themeConfig.GetStringMapString("icons.svg") iconset := themeConfig.GetStringMapString("icons.svg")
// Get State elements from Request // Get State elements from Request
var userid string
var claims map[string]any
u := r.Context().Value(identification.IdtokenKey)
if u != nil {
if current_user_token, ok := u.(*oidc.IDToken); ok {
userid = current_user_token.Subject
}
c := r.Context().Value(identification.ClaimsKey)
if c != nil {
if current_user_claims, ok := c.(map[string]any); ok {
claims = current_user_claims
}
}
}
g := r.Context().Value(identification.GroupKey) g := r.Context().Value(identification.GroupKey)
if g == nil { if g == nil {
@ -187,7 +212,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
}) })
} }
/*************************** my code ******************************/
if modules["support"] != nil && modules["support"].(bool) { if modules["support"] != nil && modules["support"].(bool) {
ls.MenuItems = append(ls.MenuItems, MenuItem{ ls.MenuItems = append(ls.MenuItems, MenuItem{
Title: "Support", Title: "Support",
@ -197,7 +221,6 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
}) })
} }
/*************************** my code ******************************/
if modules["directory"] != nil && modules["directory"].(bool) { if modules["directory"] != nil && modules["directory"].(bool) {
ls.MenuItems = append(ls.MenuItems, MenuItem{ ls.MenuItems = append(ls.MenuItems, MenuItem{
@ -212,6 +235,8 @@ func NewState(r *http.Request, themeConfig *viper.Viper, menuState string) Rende
IconSet: icons.NewIconSet(iconset), IconSet: icons.NewIconSet(iconset),
Group: group, Group: group,
Roles: roles, Roles: roles,
UserID: userid,
UserClaims: claims,
LayoutState: ls, LayoutState: ls,
} }
} }

View File

@ -63,7 +63,7 @@ func (renderer *Renderer) VehiclesFleetUpdate(w http.ResponseWriter, r *http.Req
renderer.Render("fleet display vehicle", w, r, files, state) renderer.Render("fleet display vehicle", w, r, files, state)
} }
func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, vehicle any, beneficiary any, group any, documents []filestorage.FileInfo, file_types_map map[string]string) { func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter, r *http.Request, booking any, vehicle any, beneficiary any, group any, documents []filestorage.FileInfo, file_types_map map[string]string, alternative_vehicles []any) {
files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.booking_display.files") files := renderer.ThemeConfig.GetStringSlice("views.vehicles_management.booking_display.files")
state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu) state := NewState(r, renderer.ThemeConfig, vehiclesmanagementMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{
@ -73,6 +73,7 @@ func (renderer *Renderer) VehicleManagementBookingDisplay(w http.ResponseWriter,
"group": group, "group": group,
"documents": documents, "documents": documents,
"file_types_map": file_types_map, "file_types_map": file_types_map,
"alternative_vehicles": alternative_vehicles,
} }
renderer.Render("vehicles search", w, r, files, state) renderer.Render("vehicles search", w, r, files, state)

View File

@ -4,6 +4,7 @@ import (
"net/http" "net/http"
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage" filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
"git.coopgo.io/coopgo-platform/fleets/storage"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage" mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
) )
@ -66,7 +67,7 @@ func (renderer *Renderer) VehicleBookingDisplay(w http.ResponseWriter, r *http.R
renderer.Render("vehicles search", w, r, files, state) renderer.Render("vehicles search", w, r, files, state)
} }
func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Request, bookings []any) { func (renderer *Renderer) VehicleBookingsList(w http.ResponseWriter, r *http.Request, bookings []storage.Booking) {
files := renderer.ThemeConfig.GetStringSlice("views.vehicles.bookings_list.files") files := renderer.ThemeConfig.GetStringSlice("views.vehicles.bookings_list.files")
state := NewState(r, renderer.ThemeConfig, vehiclesMenu) state := NewState(r, renderer.ThemeConfig, vehiclesMenu)
state.ViewState = map[string]any{ state.ViewState = map[string]any{

View File

@ -1,7 +1,12 @@
package services package services
import ( import (
"context"
"sort"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi" fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
"git.coopgo.io/coopgo-platform/fleets/storage"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@ -21,3 +26,29 @@ func NewFleetsService(dial string) (*FleetsService, error) {
FleetsClient: client, FleetsClient: client,
}, nil }, nil
} }
func (s *ServicesHandler) GetBooking(bookingid string) (booking storage.Booking, err error) {
request := &fleets.GetBookingRequest{
Bookingid: bookingid,
}
resp, err := s.GRPC.Fleets.GetBooking(context.TODO(), request)
if err == nil {
booking = resp.Booking.ToStorageType()
}
return
}
func (s *ServicesHandler) GetBookings() (bookings []storage.Booking, err error) {
bookings = []storage.Booking{}
request := &fleets.GetBookingsRequest{}
resp, err := s.GRPC.Fleets.GetBookings(context.TODO(), request)
if err == nil {
for _, booking := range resp.Bookings {
bookings = append(bookings, booking.ToStorageType())
}
sort.Sort(sorting.BookingsByStartdate(bookings))
}
return
}

View File

@ -1,7 +1,10 @@
package services package services
import ( import (
"context"
mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi" mobilityaccounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
"git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@ -21,3 +24,37 @@ func NewMobilityAccountService(mobilityAccountsDial string) (*MobilityAccountSer
MobilityAccountsClient: client, MobilityAccountsClient: client,
}, nil }, nil
} }
func (s *ServicesHandler) GetBeneficiaries() (accounts []storage.Account, err error) {
accounts = []storage.Account{}
request := &mobilityaccounts.GetAccountsRequest{
Namespaces: []string{"parcoursmob_beneficiaries"},
}
resp, err := s.GRPC.MobilityAccounts.GetAccounts(context.TODO(), request)
if err == nil {
for _, v := range resp.Accounts {
a := v.ToStorageType()
accounts = append(accounts, a)
}
}
return
}
func (s *ServicesHandler) GetAccounts() (accounts []storage.Account, err error) {
accounts = []storage.Account{}
request := &mobilityaccounts.GetAccountsRequest{
Namespaces: []string{"parcoursmob"},
}
resp, err := s.GRPC.MobilityAccounts.GetAccounts(context.TODO(), request)
if err == nil {
for _, v := range resp.Accounts {
a := v.ToStorageType()
accounts = append(accounts, a)
}
}
return
}