Skip to content

Commit

Permalink
Add trial claim-collection mechanism and fix colors
Browse files Browse the repository at this point in the history
  • Loading branch information
blokhin committed Dec 11, 2023
1 parent c19509e commit b39963d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
3 changes: 2 additions & 1 deletion db/seeds/010-collections-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ exports.seed = async function (knex) {
// id = 3
slug: 'statuses',
label: 'Statuses',
flavor: '#fff',
flavor: '#f5f5f5',
},
{
// id = 4
Expand All @@ -38,5 +38,6 @@ exports.seed = async function (knex) {
label: 'Customers',
flavor: '#5755D9',
},
// TODO datasource type
]);
};
4 changes: 2 additions & 2 deletions routes/[version]/calculations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ async function post(req, res, next) {
console.log('Got *engine* param: ' + engine);
console.log('Got *workflow* param: ' + workflow);

if (req.session.calculations.data.length > 15) {
/*if (req.session.calculations.data.length > 15) {
return next({
status: StatusCodes.PAYMENT_REQUIRED,
error: 'Sorry, your computing resources quota is exceeded.',
});
}
}*/

res.status(StatusCodes.ACCEPTED).json({ reqId });

Expand Down
24 changes: 24 additions & 0 deletions routes/[version]/collections/_helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const {
COLLECTIONS_TYPES_TABLE,
SHARED_COLLECTION_VISIBILITY,
USER_COLLECTIONS_TABLE,
USER_SHARED_COLLECTIONS_TABLE,
USER_DATASOURCES_TABLE,
USER_COLLECTIONS_DATASOURCES_TABLE,
db,
selectUserCollections,
Expand All @@ -13,6 +15,7 @@ const {
module.exports = {
getAndPrepareCollections,
saveCollection,
changeOwnership,
};

async function getAndPrepareCollections(collections = { data: [], total: 0 }) {
Expand Down Expand Up @@ -86,3 +89,24 @@ async function saveCollection(user, data) {

return collection;
}

async function changeOwnership(collectionId, userId) {

const SERVICE_UID = 3; // FIXME move to settings?

const ownerId = await db.select('userId').from(USER_COLLECTIONS_TABLE).where('id', collectionId);
if (!ownerId || ownerId[0].userId !== SERVICE_UID)
return 'Invalid collection selected';

const targetIds = await db.select('dataSourceId').from(USER_COLLECTIONS_DATASOURCES_TABLE).where('collectionId', collectionId);

const targets = [];
targetIds.forEach(function(item){
targets.push(item.dataSourceId);
});

await db(USER_DATASOURCES_TABLE).whereIn('id', targets).update({ userId });
await db(USER_COLLECTIONS_TABLE).where('id', collectionId).update({ userId });

return false;
}
29 changes: 29 additions & 0 deletions routes/[version]/collections/ownership.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { StatusCodes } = require('http-status-codes');
const { checkAuth } = require('../../../middlewares/auth');

const { changeOwnership } = require('./_helpers');

module.exports = {
post: [checkAuth, post],
};

/**
* @api {post} /v0/collections/ownership Get data into work and change ownership (experimental)
* @apiName ListCollectionData
* @apiGroup Collections
* @apiPermission GUI_ONLY
* @apiSuccess (202) reqId response sent to a separate server-side event stream.
* @apiUse SSEStreamResponse
*/
async function post(req, res, next) {
const reqId = req.id;

res.status(StatusCodes.ACCEPTED).json({ reqId });

try {
changeOwnership(req.body.collectionId, req.user.id);
res.sse.sendTo({ reqId, data: [] }, 'collections');
} catch (error) {
return next({ status: StatusCodes.MISDIRECTED_REQUEST, error });
}
}
2 changes: 1 addition & 1 deletion services/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const VISIBILITY_ENUM = [
];

const OAUTH_PROVIDERS_ENUM = ['dummy', 'github', 'linkedin', 'orcid', 'mpds', 'microsoft'];
const FLAVORS_ENUM = ['#900', '#ccc', '#fff', '#666', '#5755D9'];
const FLAVORS_ENUM = ['#900', '#ccc', '#f5f5f5', '#666', '#5755D9'];

const selectDataSourcesByUserId = selectAllByUserId(USER_DATASOURCES_TABLE, DATASOURCE_FIELDS);
const selectCalculationsByUserId = selectAllByUserId(USER_CALCULATIONS_TABLE);
Expand Down

0 comments on commit b39963d

Please sign in to comment.