Release 5 december 2022 - Agenda and Fleets fixes

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

View File

@@ -22,6 +22,27 @@ import (
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{
Namespaces: []string{"parcoursmob_organizations"},
}
@@ -42,7 +63,7 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque
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) {
@@ -62,6 +83,8 @@ func (h *ApplicationHandler) AdministrationCreateGroup(w http.ResponseWriter, r
"vehicles": r.FormValue("modules.vehicles") == "on",
"vehicles_management": r.FormValue("modules.vehicles_management") == "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",
}
@@ -130,30 +153,6 @@ func (h *ApplicationHandler) AdministrationGroupDisplay(w http.ResponseWriter, r
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)
if err != nil {
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) {
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)
eventid := vars["eventid"]
@@ -215,13 +227,32 @@ func (h *ApplicationHandler) AgendaSubscribeEvent(w http.ResponseWriter, r *http
}
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{
Eventid: eventid,
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 {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)

View File

@@ -1,12 +1,16 @@
package application
import (
"errors"
"net/http"
"git.coopgo.io/coopgo-apps/parcoursmob/renderer"
"git.coopgo.io/coopgo-apps/parcoursmob/services"
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
cache "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
"git.coopgo.io/coopgo-platform/emailing"
"git.coopgo.io/coopgo-platform/groups-management/storage"
"github.com/coreos/go-oidc"
"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 {
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
}
//TODO filter namespaces
//TODO filter groups
bookingsrequest := &fleets.GetDriverBookingsRequest{
Driver: beneficiaryID,
}
@@ -154,10 +151,25 @@ func (h *ApplicationHandler) BeneficiaryDisplay(w http.ResponseWriter, r *http.R
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")
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) {

View File

@@ -12,6 +12,7 @@ import (
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
"git.coopgo.io/coopgo-platform/groups-management/storage"
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) {
@@ -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 {
fmt.Println(err)
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{
Namespaces: []string{"parcoursmob_dispositifs"},
Mindate: timestamppb.Now(),
})
for _, e := range eventsresp.Events {

View File

@@ -77,7 +77,12 @@ func (h *ApplicationHandler) VehiclesManagementBookingsList(w http.ResponseWrite
if filterVehicle(r, vehicle) {
v := vehicle.ToStorageType()
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)
bookingid := vars["bookingid"]
request := &fleets.GetBookingRequest{
Bookingid: bookingid,
}
resp, err := h.services.GRPC.Fleets.GetBooking(context.TODO(), request)
booking, err := h.services.GetBooking(bookingid)
if err != nil {
fmt.Println(err)
w.WriteHeader(http.StatusInternalServerError)
return
}
booking := resp.Booking.ToStorageType()
if r.Method == "POST" {
r.ParseForm()
newbooking := resp.Booking
newbooking, _ := fleets.BookingFromStorageType(&booking)
startdate := r.FormValue("startdate")
if startdate != "" {
@@ -318,10 +318,61 @@ func (h ApplicationHandler) VehicleManagementBookingDisplay(w http.ResponseWrite
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)
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

View File

@@ -13,11 +13,11 @@ import (
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
filestorage "git.coopgo.io/coopgo-apps/parcoursmob/utils/storage"
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
"git.coopgo.io/coopgo-platform/fleets/storage"
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"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"github.com/coreos/go-oidc"
"github.com/google/uuid"
"github.com/gorilla/mux"
"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) {
// Get Group
g := r.Context().Value(identification.GroupKey)
if g == nil {
fmt.Println("no current group")
// g := r.Context().Value(identification.GroupKey)
// if g == nil {
// 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)
return
}
current_group := g.(storage.Group)
// Get current user ID
u := r.Context().Value(identification.IdtokenKey)
if u == nil {
fmt.Println("no current user")
w.WriteHeader(http.StatusInternalServerError)
return
}
current_user_token := u.(*oidc.IDToken)
// u := r.Context().Value(identification.IdtokenKey)
// if u == nil {
// fmt.Println("no current user")
// w.WriteHeader(http.StatusInternalServerError)
// return
// }
// current_user_token := u.(*oidc.IDToken)
// Get current user claims
c := r.Context().Value(identification.ClaimsKey)
if c == nil {
fmt.Println("no current user claims")
// // Get current user claims
// c := r.Context().Value(identification.ClaimsKey)
// if c == nil {
// 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)
return
}
current_user_claims := c.(map[string]any)
vars := mux.Vars(r)
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) {
g := r.Context().Value(identification.GroupKey)
if g == nil {
w.WriteHeader(http.StatusBadRequest)
return
}
group := g.(groupsmanagementstorage.Group)
request := &fleets.GetBookingsRequest{}
resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), request)
if err != nil {
@@ -332,12 +354,22 @@ func (h ApplicationHandler) VehiclesBookingsList(w http.ResponseWriter, r *http.
return
}
bookings := []any{}
bookings := []storage.Booking{}
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)
}