You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
792 B
37 lines
792 B
package mutations
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.aiterp.net/rpdata/api/graphql/resolver/types"
|
|
"git.aiterp.net/rpdata/api/internal/auth"
|
|
"git.aiterp.net/rpdata/api/model/file"
|
|
)
|
|
|
|
// RemoveFileArgs is an arg
|
|
type RemoveFileArgs struct {
|
|
ID string
|
|
}
|
|
|
|
// RemoveFile resolves the removeFIle mutation
|
|
func (r *MutationResolver) RemoveFile(ctx context.Context, args *RemoveFileArgs) (*types.FileResolver, error) {
|
|
token := auth.TokenFromContext(ctx)
|
|
if !token.Permitted("member") {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
|
|
file, err := file.FindID(args.ID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if file.Author != token.UserID && !token.Permitted("file.remove") {
|
|
return nil, ErrUnauthorized
|
|
}
|
|
|
|
err = file.Delete()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &types.FileResolver{F: file}, nil
|
|
}
|