Commit fecc334c authored by ale's avatar ale

Replace enable/disable_resource with a new set_resource_status API

parent 8466ed04
...@@ -68,24 +68,25 @@ func setResourceStatus(rctx *RequestContext, status string) error { ...@@ -68,24 +68,25 @@ func setResourceStatus(rctx *RequestContext, status string) error {
return nil return nil
} }
// DisableResourceRequest disables a resource belonging to the user. // SetResourceStatusRequest modifies the status of a resource
type DisableResourceRequest struct { // belonging to the user (admin-only).
ResourceRequestBase type SetResourceStatusRequest struct {
} AdminResourceRequestBase
// Serve the request. Status string `json:"status"`
func (r *DisableResourceRequest) Serve(rctx *RequestContext) (interface{}, error) {
return nil, setResourceStatus(rctx, ResourceStatusInactive)
} }
// EnableResourceRequest enables a resource belonging to the user (admin-only). // Validate the request.
type EnableResourceRequest struct { func (r *SetResourceStatusRequest) Validate(rctx *RequestContext) error {
AdminResourceRequestBase if !isValidStatusByResourceType(rctx.Resource.Type, r.Status) {
return errors.New("invalid or unknown status")
}
return nil
} }
// Serve the request. // Serve the request.
func (r *EnableResourceRequest) Serve(rctx *RequestContext) (interface{}, error) { func (r *SetResourceStatusRequest) Serve(rctx *RequestContext) (interface{}, error) {
return nil, setResourceStatus(rctx, ResourceStatusActive) return nil, setResourceStatus(rctx, r.Status)
} }
// ResetResourcePasswordRequest will reset the password associated // ResetResourcePasswordRequest will reset the password associated
......
...@@ -59,8 +59,7 @@ func New(service *as.AccountService, backend as.Backend) *APIServer { ...@@ -59,8 +59,7 @@ func New(service *as.AccountService, backend as.Backend) *APIServer {
s.Register("/api/user/delete_app_specific_password", &as.DeleteApplicationSpecificPasswordRequest{}) s.Register("/api/user/delete_app_specific_password", &as.DeleteApplicationSpecificPasswordRequest{})
s.Register("/api/resource/get", &as.GetResourceRequest{}) s.Register("/api/resource/get", &as.GetResourceRequest{})
s.Register("/api/resource/search", &as.SearchResourceRequest{}) s.Register("/api/resource/search", &as.SearchResourceRequest{})
s.Register("/api/resource/enable", &as.EnableResourceRequest{}) s.Register("/api/resource/set_status", &as.SetResourceStatusRequest{})
s.Register("/api/resource/disable", &as.DisableResourceRequest{})
s.Register("/api/resource/create", &as.CreateResourcesRequest{}) s.Register("/api/resource/create", &as.CreateResourcesRequest{})
s.Register("/api/resource/move", &as.MoveResourceRequest{}) s.Register("/api/resource/move", &as.MoveResourceRequest{})
s.Register("/api/resource/reset_password", &as.ResetPasswordRequest{}) s.Register("/api/resource/reset_password", &as.ResetPasswordRequest{})
......
...@@ -392,6 +392,23 @@ const ( ...@@ -392,6 +392,23 @@ const (
ResourceStatusArchived = "archived" ResourceStatusArchived = "archived"
) )
// Returns true if the given status is valid for the given resource type.
func isValidStatusByResourceType(rtype, rstatus string) bool {
switch rtype {
case ResourceTypeEmail, ResourceTypeMailingList:
switch rstatus {
case ResourceStatusActive, ResourceStatusInactive, ResourceStatusReadonly:
return true
}
case ResourceTypeWebsite, ResourceTypeDomain, ResourceTypeDAV, ResourceTypeDatabase:
switch rstatus {
case ResourceStatusActive, ResourceStatusInactive, ResourceStatusReadonly, ResourceStatusArchived:
return true
}
}
return false
}
// ResourceID is an opaque ID that uniquely identifies a resource in // ResourceID is an opaque ID that uniquely identifies a resource in
// the backend database. These should normally not be visible to users. // the backend database. These should normally not be visible to users.
type ResourceID string type ResourceID string
......
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