Commit ab294a25 authored by ale's avatar ale

Log resource creation

parent 4e34034b
......@@ -11,13 +11,15 @@ import (
// CreateResourcesRequest lets administrators create one or more resources.
type CreateResourcesRequest struct {
AdminRequestBase
// Resources to create. All must either be global resources
// (no user ownership), or belong to the same user.
Resources []*Resource `json:"resources"`
}
// CreateResourcesResponse is the response type for CreateResourcesRequest.
type CreateResourcesResponse struct {
// Resources to create. All must either be global resources
// (no user ownership), or belong to the same user.
// Resources that were created.
Resources []*Resource `json:"resources"`
}
......@@ -60,12 +62,12 @@ func (r *CreateResourcesRequest) Validate(rctx *RequestContext) error {
// Check same-user ownership.
if rsrc.ID.User() != owner {
return errors.New("resources owned by different users")
return errors.New("resources are owned by different users")
}
// Validate the resource.
if err := rctx.resourceValidator.validateResource(rctx.Context, rsrc, tplUser); err != nil {
log.Printf("validation error while creating resource %+v: %v", rsrc, err)
log.Printf("validation error while creating resource %s: %v", rsrc.ID, err)
return err
}
}
......@@ -79,7 +81,7 @@ func (r *CreateResourcesRequest) Serve(rctx *RequestContext) (interface{}, error
if err := rctx.TX.CreateResource(rctx.Context, rsrc); err != nil {
return nil, err
}
//s.audit.Log(ctx, r.ID, "resource created")
rctx.audit.Log(rctx, rsrc.ID, "resource created")
resp.Resources = append(resp.Resources, rsrc)
}
return &resp, nil
......@@ -104,6 +106,8 @@ func mergeResources(a, b []*Resource) []*Resource {
// associated resources.
type CreateUserRequest struct {
AdminRequestBase
// User to create, along with associated resources.
User *User `json:"user"`
}
......@@ -157,7 +161,7 @@ func (r *CreateUserRequest) Validate(rctx *RequestContext) error {
// CreateUserResponse is the response type for CreateUserRequest.
type CreateUserResponse struct {
User *User `json:"user,omitempty"`
User *User `json:"user"`
Password string `json:"password"`
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment