Skip to content

Commit

Permalink
Merge pull request #424 from internxt/fix/prevent-move-files-if-statu…
Browse files Browse the repository at this point in the history
…s-deleted

[PB-1617]: fix/ select NOT deleted files when trying to move any file
  • Loading branch information
sg-gs authored Feb 15, 2024
2 parents a16e078 + 81c43b3 commit 24116fe
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/app/services/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,15 @@ module.exports = (Model, App) => {
: '';

// Check if there is a file with the same name
Model.file.findOne({
where: {
folder_id: { [Op.eq]: file.folder_id },
name: { [Op.eq]: cryptoFileName },
type: { [Op.eq]: file.type },
status: { [Op.eq]: 'EXISTS' },
},
})
Model.file
.findOne({
where: {
folder_id: { [Op.eq]: file.folder_id },
name: { [Op.eq]: cryptoFileName },
type: { [Op.eq]: file.type },
status: { [Op.eq]: 'EXISTS' },
},
})
.then((duplicateFile) => {
if (duplicateFile) {
return next(new FileWithNameAlreadyExistsError('File with this name exists'));
Expand All @@ -278,7 +279,10 @@ module.exports = (Model, App) => {
};

const MoveFile = async (user, fileId, destination) => {
const file = await Model.file.findOne({ where: { fileId: { [Op.eq]: fileId } }, userId: user.id });
const file = await Model.file.findOne({
where: { fileId: { [Op.eq]: fileId }, status: { [Op.not]: 'DELETED' } },
userId: user.id,
});

if (!file) {
throw Error('File not found');
Expand Down Expand Up @@ -330,19 +334,20 @@ module.exports = (Model, App) => {

const isFileOfTeamFolder = (fileId) =>
new Promise((resolve, reject) => {
Model.file.findOne({
where: {
file_id: { [Op.eq]: fileId },
},
include: [
{
model: Model.folder,
where: {
id_team: { [Op.ne]: null },
},
Model.file
.findOne({
where: {
file_id: { [Op.eq]: fileId },
},
],
})
include: [
{
model: Model.folder,
where: {
id_team: { [Op.ne]: null },
},
},
],
})
.then((file) => {
if (!file) {
throw Error('File not found on database, please refresh');
Expand Down Expand Up @@ -409,9 +414,9 @@ module.exports = (Model, App) => {
where: {
userId: user.id,
bucket: {
[Op.ne]: user.backupsBucket
[Op.ne]: user.backupsBucket,
},
status: { [Op.eq]: 'EXISTS' }
status: { [Op.eq]: 'EXISTS' },
},
include: [
{
Expand Down

0 comments on commit 24116fe

Please sign in to comment.