Add initial implementation of grants

This commit is contained in:
Tom Wiesing 2023-01-02 15:12:06 +01:00
parent b8f1281f78
commit 69b6579de7
No known key found for this signature in database
15 changed files with 308 additions and 73 deletions

View file

@ -0,0 +1,30 @@
package policy
import (
"context"
"github.com/FAU-CDI/wisski-distillery/internal/models"
)
func (*Policy) Provision(ctx context.Context, instance models.Instance, domain string) error {
// component is purge-only
return nil
}
// Purge purges every policy for the given slug form the database
func (pol *Policy) Purge(ctx context.Context, instance models.Instance, domain string) error {
table, err := pol.table(ctx)
if err != nil {
return err
}
return table.Delete(&models.Grant{}, &models.Grant{Slug: instance.Slug}).Error
}
// OnUserDelete is called when a user is deleted
func (pol *Policy) OnUserDelete(ctx context.Context, user *models.User) error {
table, err := pol.table(ctx)
if err != nil {
return err
}
return table.Delete(&models.Grant{}, &models.Grant{User: user.User}).Error
}