1721/feature/drag and drop favorites (#2097)
* prisma schema updated: added index in favorite * update abilitiy added for favorite * update one favorite resolver added * update on favorite mutation added * updateFavoriteOrder added * Draglist added in favorite * nav item convert to div from button: because it was not working dragable with button * changed index to position * position added in getFavorites query * added recoil state for favorites * reordering updated according to new method * Use accurate type --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -201,6 +201,7 @@ export class AbilityFactory {
|
||||
// Favorite
|
||||
can(AbilityAction.Read, 'Favorite', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Create, 'Favorite');
|
||||
can(AbilityAction.Update, 'Favorite', { workspaceId: workspace.id });
|
||||
can(AbilityAction.Delete, 'Favorite', { workspaceId: workspace.id });
|
||||
|
||||
return build();
|
||||
|
||||
@ -103,6 +103,7 @@ import {
|
||||
CreateFavoriteAbilityHandler,
|
||||
ReadFavoriteAbilityHandler,
|
||||
DeleteFavoriteAbilityHandler,
|
||||
UpdateFavoriteAbilityHandler,
|
||||
} from './handlers/favorite.ability-handler';
|
||||
import {
|
||||
CreateViewSortAbilityHandler,
|
||||
@ -219,6 +220,7 @@ import {
|
||||
//Favorite
|
||||
ReadFavoriteAbilityHandler,
|
||||
CreateFavoriteAbilityHandler,
|
||||
UpdateFavoriteAbilityHandler,
|
||||
DeleteFavoriteAbilityHandler,
|
||||
// View
|
||||
ReadViewAbilityHandler,
|
||||
|
||||
@ -57,6 +57,34 @@ export class CreateFavoriteAbilityHandler implements IAbilityHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class UpdateFavoriteAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
async handle(ability: AppAbility, context: ExecutionContext) {
|
||||
const gqlContext = GqlExecutionContext.create(context);
|
||||
const args = gqlContext.getArgs<FavoriteArgs>();
|
||||
|
||||
const favorite = await this.prismaService.client.favorite.findFirst({
|
||||
where: args.where,
|
||||
});
|
||||
assert(favorite, '', NotFoundException);
|
||||
|
||||
const allowed = await relationAbilityChecker(
|
||||
'Favorite',
|
||||
ability,
|
||||
this.prismaService.client,
|
||||
args,
|
||||
);
|
||||
|
||||
if (!allowed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ability.can(AbilityAction.Update, 'Favorite');
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class DeleteFavoriteAbilityHandler implements IAbilityHandler {
|
||||
constructor(private readonly prismaService: PrismaService) {}
|
||||
|
||||
Reference in New Issue
Block a user