Skip to content

Commit

Permalink
Make sure group or collection cannot be removed if used by users or r…
Browse files Browse the repository at this point in the history
…esources
  • Loading branch information
Julien Kassar committed Apr 6, 2018
1 parent 04bd9ab commit f2eacc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions object/collection/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (c *Config) Remove(name string) error {
return fmt.Errorf("collection '%s' does not exist", name)
}

if len(c.Storage.ListResources(map[string]string{"elem": name})) > 0 {
return fmt.Errorf("collection '%s' cannot be removed. It is used by at least one resource", name)
}

if err := c.Storage.RemoveCollection(name); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions object/group/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func (c *Config) Remove(name string) error {
return fmt.Errorf("group '%s' does not exist", name)
}

if len(c.Storage.ListUsers(map[string]string{"elem": name})) > 0 {
return fmt.Errorf("group '%s' cannot be removed. It is used by at least one user", name)
}

if err := c.Storage.RemoveGroup(name); err != nil {
return err
}
Expand Down

0 comments on commit f2eacc8

Please sign in to comment.