use hard typed deprovision date

Signed-off-by: jkoberg <jkoberg@owncloud.com>
This commit is contained in:
jkoberg
2023-07-07 11:06:53 +02:00
parent 6ab2f10386
commit d8667bf736
4 changed files with 39 additions and 15 deletions
+1 -1
View File
@@ -305,7 +305,7 @@ func (c *Converter) policiesMessage(eventid string, nt NotificationTemplate, exe
}, nil
}
func (c *Converter) deprovisionMessage(nt NotificationTemplate, deproDate string) (OC10Notification, error) {
func (c *Converter) deprovisionMessage(nt NotificationTemplate, deproDate time.Time) (OC10Notification, error) {
subj, subjraw, msg, msgraw, err := composeMessage(nt, c.locale, c.translationPath, map[string]interface{}{
"date": deproDate,
})
@@ -0,0 +1,15 @@
package service
import "time"
var (
_globalEventsKey = "global-events"
)
// DeprovisionData is the data needed for the deprovision global event
type DeprovisionData struct {
// The deprovision date
DeprovisionDate time.Time `json:"deprovision_date"`
// The user who stored the deprovision message
Deprovisioner string
}
+4 -7
View File
@@ -186,13 +186,10 @@ type DeleteEventsRequest struct {
// PostEventsRequest is the expected body for the post request
type PostEventsRequest struct {
Type string `json:"type"`
Data json.RawMessage `json:"data"`
}
// DeprovisionData is the expected `data` for the PostEventsRequest when deprovisioning
type DeprovisionData struct {
DeprovisionDate string `json:"date"`
// the event type, e.g. "deprovision"
Type string `json:"type"`
// arbitray data for the event
Data map[string]string `json:"data"`
}
// RequireAdmin middleware is used to require the user in context to be an admin / have account management permissions
+19 -7
View File
@@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"reflect"
"time"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
group "github.com/cs3org/go-cs3apis/cs3/identity/group/v1beta1"
@@ -244,19 +245,30 @@ func (ul *UserlogService) DeleteEvents(userid string, evids []string) error {
}
// StoreGlobalEvent will store a global event that will be returned with each `GetEvents` request
func (ul *UserlogService) StoreGlobalEvent(typ string, data json.RawMessage) error {
func (ul *UserlogService) StoreGlobalEvent(typ string, data map[string]string) error {
switch typ {
default:
return fmt.Errorf("unknown event type: %s", typ)
case "deprovision":
var req DeprovisionData
if err := json.Unmarshal(data, &req); err != nil {
return err
dps, ok := data["deprovision_date"]
if !ok {
return errors.New("need 'deprovision_date' in request body")
}
// TODO: check for proper time format
format := data["deprovision_date_format"]
if format == "" {
format = time.RFC3339
}
return ul.storeGlobalEvent(typ, req)
date, err := time.Parse(format, dps)
if err != nil {
fmt.Println("", format, "\n", dps)
return fmt.Errorf("cannot parse time to format. time: '%s' format: '%s'", dps, format)
}
return ul.storeGlobalEvent(typ, DeprovisionData{
DeprovisionDate: date,
})
}
}
@@ -265,7 +277,7 @@ func (ul *UserlogService) StoreGlobalEvent(typ string, data json.RawMessage) err
func (ul *UserlogService) GetGlobalEvents() (map[string]json.RawMessage, error) {
out := make(map[string]json.RawMessage)
recs, err := ul.store.Read("global-events")
recs, err := ul.store.Read(_globalEventsKey)
if err != nil && err != store.ErrNotFound {
return out, err
}