Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/autocomplete
- Loading branch information
Showing
93 changed files
with
2,844 additions
and
654 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { EmailInbox } from '../../../models/server/raw'; | ||
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; | ||
import { Users } from '../../../models'; | ||
|
||
export async function findEmailInboxes({ userId, query = {}, pagination: { offset, count, sort } }) { | ||
if (!await hasPermissionAsync(userId, 'manage-email-inbox')) { | ||
throw new Error('error-not-allowed'); | ||
} | ||
const cursor = EmailInbox.find(query, { | ||
sort: sort || { name: 1 }, | ||
skip: offset, | ||
limit: count, | ||
}); | ||
|
||
const total = await cursor.count(); | ||
|
||
const emailInboxes = await cursor.toArray(); | ||
|
||
return { | ||
emailInboxes, | ||
count: emailInboxes.length, | ||
offset, | ||
total, | ||
}; | ||
} | ||
|
||
export async function findOneEmailInbox({ userId, _id }) { | ||
if (!await hasPermissionAsync(userId, 'manage-email-inbox')) { | ||
throw new Error('error-not-allowed'); | ||
} | ||
return EmailInbox.findOneById(_id); | ||
} | ||
|
||
export async function insertOneOrUpdateEmailInbox(userId, emailInboxParams) { | ||
const { _id, active, name, email, description, senderInfo, department, smtp, imap } = emailInboxParams; | ||
|
||
if (!_id) { | ||
emailInboxParams._createdAt = new Date(); | ||
emailInboxParams._updatedAt = new Date(); | ||
emailInboxParams._createdBy = Users.findOne(userId, { fields: { username: 1 } }); | ||
return EmailInbox.insertOne(emailInboxParams); | ||
} | ||
|
||
const emailInbox = await findOneEmailInbox({ userId, id: _id }); | ||
|
||
if (!emailInbox) { | ||
throw new Error('error-invalid-email-inbox'); | ||
} | ||
|
||
const updateEmailInbox = { | ||
$set: { | ||
active, | ||
name, | ||
email, | ||
description, | ||
senderInfo, | ||
smtp, | ||
imap, | ||
_updatedAt: new Date(), | ||
}, | ||
}; | ||
|
||
if (department === 'All') { | ||
updateEmailInbox.$unset = { | ||
department: 1, | ||
}; | ||
} else { | ||
updateEmailInbox.$set.department = department; | ||
} | ||
|
||
return EmailInbox.updateOne({ _id }, updateEmailInbox); | ||
} | ||
|
||
export async function findOneEmailInboxByEmail({ userId, email }) { | ||
if (!await hasPermissionAsync(userId, 'manage-email-inbox')) { | ||
throw new Error('error-not-allowed'); | ||
} | ||
return EmailInbox.findOne({ email }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import { check, Match } from 'meteor/check'; | ||
|
||
import { API } from '../api'; | ||
import { findEmailInboxes, findOneEmailInbox, insertOneOrUpdateEmailInbox } from '../lib/emailInbox'; | ||
import { hasPermission } from '../../../authorization/server/functions/hasPermission'; | ||
import { EmailInbox } from '../../../models'; | ||
import Users from '../../../models/server/models/Users'; | ||
import { sendTestEmailToInbox } from '../../../../server/features/EmailInbox/EmailInbox_Outgoing'; | ||
|
||
API.v1.addRoute('email-inbox.list', { authRequired: true }, { | ||
get() { | ||
const { offset, count } = this.getPaginationItems(); | ||
const { sort, query } = this.parseJsonQuery(); | ||
const emailInboxes = Promise.await(findEmailInboxes({ userId: this.userId, query, pagination: { offset, count, sort } })); | ||
|
||
return API.v1.success(emailInboxes); | ||
}, | ||
}); | ||
|
||
API.v1.addRoute('email-inbox', { authRequired: true }, { | ||
post() { | ||
if (!hasPermission(this.userId, 'manage-email-inbox')) { | ||
throw new Error('error-not-allowed'); | ||
} | ||
check(this.bodyParams, { | ||
_id: Match.Maybe(String), | ||
name: String, | ||
email: String, | ||
active: Boolean, | ||
description: Match.Maybe(String), | ||
senderInfo: Match.Maybe(String), | ||
department: Match.Maybe(String), | ||
smtp: Match.ObjectIncluding({ | ||
password: String, | ||
port: Number, | ||
secure: Boolean, | ||
server: String, | ||
username: String, | ||
}), | ||
imap: Match.ObjectIncluding({ | ||
password: String, | ||
port: Number, | ||
secure: Boolean, | ||
server: String, | ||
username: String, | ||
}), | ||
}); | ||
|
||
const emailInboxParams = this.bodyParams; | ||
|
||
const { _id } = emailInboxParams; | ||
|
||
Promise.await(insertOneOrUpdateEmailInbox(this.userId, emailInboxParams)); | ||
|
||
return API.v1.success({ _id }); | ||
}, | ||
}); | ||
|
||
API.v1.addRoute('email-inbox/:_id', { authRequired: true }, { | ||
get() { | ||
check(this.urlParams, { | ||
_id: String, | ||
}); | ||
|
||
const { _id } = this.urlParams; | ||
if (!_id) { throw new Error('error-invalid-param'); } | ||
const emailInboxes = Promise.await(findOneEmailInbox({ userId: this.userId, _id })); | ||
|
||
return API.v1.success(emailInboxes); | ||
}, | ||
delete() { | ||
if (!hasPermission(this.userId, 'manage-email-inbox')) { | ||
throw new Error('error-not-allowed'); | ||
} | ||
check(this.urlParams, { | ||
_id: String, | ||
}); | ||
|
||
const { _id } = this.urlParams; | ||
if (!_id) { throw new Error('error-invalid-param'); } | ||
|
||
const emailInboxes = EmailInbox.findOneById(_id); | ||
|
||
if (!emailInboxes) { | ||
return API.v1.notFound(); | ||
} | ||
EmailInbox.removeById(_id); | ||
return API.v1.success({ _id }); | ||
}, | ||
}); | ||
|
||
API.v1.addRoute('email-inbox.search', { authRequired: true }, { | ||
get() { | ||
if (!hasPermission(this.userId, 'manage-email-inbox')) { | ||
throw new Error('error-not-allowed'); | ||
} | ||
check(this.queryParams, { | ||
email: String, | ||
}); | ||
|
||
const { email } = this.queryParams; | ||
const emailInbox = Promise.await(EmailInbox.findOne({ email })); | ||
|
||
return API.v1.success({ emailInbox }); | ||
}, | ||
}); | ||
|
||
API.v1.addRoute('email-inbox.send-test/:_id', { authRequired: true }, { | ||
post() { | ||
if (!hasPermission(this.userId, 'manage-email-inbox')) { | ||
throw new Error('error-not-allowed'); | ||
} | ||
check(this.urlParams, { | ||
_id: String, | ||
}); | ||
|
||
const { _id } = this.urlParams; | ||
if (!_id) { throw new Error('error-invalid-param'); } | ||
const emailInbox = Promise.await(findOneEmailInbox({ userId: this.userId, _id })); | ||
|
||
if (!emailInbox) { | ||
return API.v1.notFound(); | ||
} | ||
|
||
const user = Users.findOneById(this.userId); | ||
|
||
Promise.await(sendTestEmailToInbox(emailInbox, user)); | ||
|
||
return API.v1.success({ _id }); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.