Skip to content

Commit

Permalink
Merge pull request #2251 from hollaex/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
abeikverdi authored Jul 10, 2023
2 parents 22df1ab + c455e1c commit 4f9a99d
Show file tree
Hide file tree
Showing 120 changed files with 6,903 additions and 2,092 deletions.
23 changes: 17 additions & 6 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ trigger:
# - docker pull hollaex/hollaex-kit:$(cat .tags)
# - export DOCKER_CONTENT_TRUST=1
# - mkdir $${HOME}/.docker/trust && mkdir $${HOME}/.docker/trust/private
# - echo -n $${DOCKER_CONTENT_TRUST_PRIVATE_KEY} | base64 -d > $${HOME}/.docker/trust/private/88ce8696c017268731701ad17ae8b59dda7c31a3b750e986282c66c74ecb0d32.key
# - chmod 600 $${HOME}/.docker/trust/private/88ce8696c017268731701ad17ae8b59dda7c31a3b750e986282c66c74ecb0d32.key
# - docker trust key load $${HOME}/.docker/trust/private/88ce8696c017268731701ad17ae8b59dda7c31a3b750e986282c66c74ecb0d32.key --name bitholla-cicd
# - echo -n $${DOCKER_CONTENT_TRUST_PRIVATE_KEY} | base64 -d > $${HOME}/.docker/trust/private/2aa7f2853b764c97de67db773c493d379ee655d7d78ff909d68c04a442fe3b69.key
# - chmod 600 $${HOME}/.docker/trust/private/2aa7f2853b764c97de67db773c493d379ee655d7d78ff909d68c04a442fe3b69.key
# - docker trust key load $${HOME}/.docker/trust/private/2aa7f2853b764c97de67db773c493d379ee655d7d78ff909d68c04a442fe3b69.key --name bitholla-cicd
# - docker trust sign hollaex/hollaex-kit:$(cat .tags)

# - name: docker_tagging_arm64v8_testnet
Expand Down Expand Up @@ -194,6 +194,15 @@ steps:
when:
branch: master

# - name: docker_tagging_amd64_deployment
# image: alpine
# commands:
# - export TZ=UTC-9 && export GIT_COMMIT_SHORT="$(echo $DRONE_COMMIT | cut -c 1-7)" && export PACKAGE_VERSION="$(cat version)" && echo "2.7.0-testnet-86884d5" > .tags
# - echo "Current Docker tag is :" && cat .tags
# - echo "dockerTag:$(cat .tags)" > .dockerTag.yml
# when:
# branch: deployment

- name: docker_build_amd64
image: plugins/docker
settings:
Expand Down Expand Up @@ -228,9 +237,9 @@ steps:
- docker pull hollaex/hollaex-kit:$(cat .tags)
- export DOCKER_CONTENT_TRUST=1
- mkdir $${HOME}/.docker/trust && mkdir $${HOME}/.docker/trust/private
- echo -n $${DOCKER_CONTENT_TRUST_PRIVATE_KEY} | base64 -d > $${HOME}/.docker/trust/private/88ce8696c017268731701ad17ae8b59dda7c31a3b750e986282c66c74ecb0d32.key
- chmod 600 $${HOME}/.docker/trust/private/88ce8696c017268731701ad17ae8b59dda7c31a3b750e986282c66c74ecb0d32.key
- docker trust key load $${HOME}/.docker/trust/private/88ce8696c017268731701ad17ae8b59dda7c31a3b750e986282c66c74ecb0d32.key --name bitholla-cicd
- echo -n $${DOCKER_CONTENT_TRUST_PRIVATE_KEY} | base64 -d > $${HOME}/.docker/trust/private/2aa7f2853b764c97de67db773c493d379ee655d7d78ff909d68c04a442fe3b69.key
- chmod 600 $${HOME}/.docker/trust/private/2aa7f2853b764c97de67db773c493d379ee655d7d78ff909d68c04a442fe3b69.key
- docker trust key load $${HOME}/.docker/trust/private/2aa7f2853b764c97de67db773c493d379ee655d7d78ff909d68c04a442fe3b69.key --name bitholla-cicd
- docker trust sign hollaex/hollaex-kit:$(cat .tags)

- name: docker_tagging_arm64v8_master
Expand All @@ -239,6 +248,8 @@ steps:
- export TZ=UTC-9 && export GIT_COMMIT_SHORT="$(echo $DRONE_COMMIT | cut -c 1-7)" && export PACKAGE_VERSION="$(cat version)" && echo " $PACKAGE_VERSION-arm64v8" > .tags
- echo "Current Docker tag is :" && cat .tags
- echo "dockerTag:$(cat .tags)" > .dockerTag.yml
when:
branch: master

- name: docker_build_arm64v8
image: plugins/docker
Expand Down
164 changes: 160 additions & 4 deletions server/api/controllers/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ const { loggerAdmin } = require('../../config/logger');
const toolsLib = require('hollaex-tools-lib');
const { cloneDeep, pick } = require('lodash');
const { all } = require('bluebird');
const { ROLES } = require('../../constants');
const { INIT_CHANNEL, ROLES } = require('../../constants');
const { USER_NOT_FOUND, API_KEY_NOT_PERMITTED, PROVIDE_VALID_EMAIL, INVALID_PASSWORD, USER_EXISTS } = require('../../messages');
const { sendEmail, testSendSMTPEmail, sendRawEmail } = require('../../mail');
const { MAILTYPE } = require('../../mail/strings');
const { errorMessageConverter } = require('../../utils/conversion');
const { isDate } = require('moment');
const { isEmail } = require('validator');
const { publisher } = require('../../db/pubsub');
const crypto = require('crypto');

const VERIFY_STATUS = {
Expand Down Expand Up @@ -112,7 +113,34 @@ const putAdminKit = (req, res) => {
const getUsersAdmin = (req, res) => {
loggerAdmin.verbose(req.uuid, 'controllers/admin/getUsers/auth', req.auth);

const { id, search, type, pending, pending_type, limit, page, order_by, order, start_date, end_date, format } = req.swagger.params;
const {
id,
search,
type,
pending,
pending_type,
limit,
page,
order_by,
order,
start_date,
end_date,
format,
email,
username,
full_name,
dob_start_date,
dob_end_date,
gender,
nationality,
verification_level,
email_verified,
otp_enabled,
phone_number,
kyc,
bank

} = req.swagger.params;

if (order_by.value && typeof order_by.value !== 'string') {
loggerAdmin.error(
Expand Down Expand Up @@ -140,6 +168,19 @@ const getUsersAdmin = (req, res) => {
end_date: end_date.value,
format: format.value,
type: type.value,
email: email.value,
username: username.value,
full_name: full_name.value,
dob_start_date: dob_start_date.value,
dob_end_date: dob_end_date.value,
gender: gender.value,
nationality: nationality.value,
verification_level: verification_level.value,
email_verified: email_verified.value,
otp_enabled: otp_enabled.value,
phone_number: phone_number.value,
kyc: kyc.value,
bank: bank.value,
additionalHeaders: {
'x-forwarded-for': req.headers['x-forwarded-for']
}
Expand Down Expand Up @@ -441,7 +482,7 @@ const getAdminUserLogins = (req, res) => {
'controllers/admin/getAdminUserLogins/auth',
req.auth
);
const { user_id, limit, page, start_date, order_by, order, end_date, format } = req.swagger.params;
const { user_id, status, limit, page, start_date, order_by, order, end_date, format } = req.swagger.params;

if (start_date.value && !isDate(start_date.value)) {
loggerAdmin.error(
Expand Down Expand Up @@ -472,6 +513,7 @@ const getAdminUserLogins = (req, res) => {

toolsLib.user.getUserLogins({
userId: user_id.value,
status: status.value,
limit: limit.value,
page: page.value,
orderBy: order_by.value,
Expand Down Expand Up @@ -2343,6 +2385,116 @@ const sendRawEmailByAdmin = (req, res) => {
});
};

const getUserSessionsByAdmin = (req, res) => {
loggerAdmin.verbose(req.uuid, 'controllers/admin/getUserSessionsByAdmin/auth', req.auth);

const { user_id, status, limit, page, order_by, order, start_date, end_date, format } = req.swagger.params;

if (order_by.value && typeof order_by.value !== 'string') {
loggerAdmin.error(
req.uuid,
'controllers/admin/getUserSessionsByAdmin invalid order_by',
order_by.value
);
return res.status(400).json({ message: 'Invalid order by' });
}

toolsLib.user.getExchangeUserSessions({
user_id: user_id.value,
status: status.value,
limit: limit.value,
page: page.value,
order_by: order_by.value,
order: order.value,
start_date: start_date.value,
end_date: end_date.value,
format: format.value
}
)
.then((data) => {
if (format.value === 'csv') {
res.setHeader('Content-disposition', `attachment; filename=${toolsLib.getKitConfig().api_name}-logins.csv`);
res.set('Content-Type', 'text/csv');
return res.status(202).send(data);
} else {
return res.json(data);
}
})
.catch((err) => {
loggerAdmin.error(req.uuid, 'controllers/admin/getUserSessionsByAdmin', err.message);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const revokeUserSessionByAdmin = (req, res) => {
loggerAdmin.verbose(req.uuid, 'controllers/admin/revokeUserSessionByAdmin/auth', req.auth);

const { session_id } = req.swagger.params.data.value;

toolsLib.user.revokeExchangeUserSession(session_id)
.then((data) => {
return res.json(data);
})
.catch((err) => {
loggerAdmin.error(req.uuid, 'controllers/admin/revokeUserSessionByAdmin', err.message);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
}

const updateQuickTradeConfig = (req, res) => {
loggerAdmin.verbose(req.uuid, 'controllers/admin/updateQuickTradeConfig/auth', req.auth);

const { symbol, type, active } = req.swagger.params.data.value;

toolsLib.order.updateQuickTradeConfig({ symbol, active, type }
)
.then((data) => {
publisher.publish(INIT_CHANNEL, JSON.stringify({ type: 'refreshInit' }));
return res.json(data);
})
.catch((err) => {
loggerAdmin.error(req.uuid, 'controllers/admin/updateQuickTradeConfig', err.message);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
};

const getBalancesAdmin = (req, res) => {
loggerAdmin.verbose(req.uuid, 'controllers/admin/getBalancesAdmin/auth', req.auth);

const {
user_id,
currency,
format
} = req.swagger.params;


if (format.value && req.auth.scopes.indexOf(ROLES.ADMIN) === -1) {
return res.status(403).json({ message: API_KEY_NOT_PERMITTED });
}

toolsLib.user.getAllBalancesAdmin({
user_id: user_id.value,
currency: currency.value,
format: format.value,
additionalHeaders: {
'x-forwarded-for': req.headers['x-forwarded-for']
}
})
.then((data) => {
if (format.value === 'all') {
res.setHeader('Content-disposition', `attachment; filename=${toolsLib.getKitConfig().api_name}-users.csv`);
res.set('Content-Type', 'text/csv');
return res.status(202).send(data);
} else {
return res.json(data);
}
})
.catch((err) => {
loggerAdmin.error(req.uuid, 'controllers/admin/getBalancesAdmin', err.message);
return res.status(err.statusCode || 400).json({ message: errorMessageConverter(err) });
});
}

module.exports = {
createInitialAdmin,
getAdminKit,
Expand Down Expand Up @@ -2400,6 +2552,10 @@ module.exports = {
createUserByAdmin,
createUserWalletByAdmin,
getWalletsByAdmin,
getUserSessionsByAdmin,
revokeUserSessionByAdmin,
sendEmailByAdmin,
sendRawEmailByAdmin
sendRawEmailByAdmin,
updateQuickTradeConfig,
getBalancesAdmin
};
Loading

0 comments on commit 4f9a99d

Please sign in to comment.