mirror of
https://github.com/plankanban/planka.git
synced 2025-07-24 23:59:48 +02:00
parent
ad7fb51cfa
commit
2ee1166747
1557 changed files with 76832 additions and 47042 deletions
|
@ -1,9 +1,15 @@
|
|||
/*!
|
||||
* Copyright (c) 2024 PLANKA Software GmbH
|
||||
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
|
||||
*/
|
||||
|
||||
const bcrypt = require('bcrypt');
|
||||
|
||||
const buildData = () => {
|
||||
const data = {
|
||||
isAdmin: true,
|
||||
isSso: false,
|
||||
role: 'admin',
|
||||
isSsoUser: false,
|
||||
isDeactivated: false,
|
||||
};
|
||||
|
||||
if (process.env.DEFAULT_ADMIN_PASSWORD) {
|
||||
|
@ -20,21 +26,66 @@ const buildData = () => {
|
|||
};
|
||||
|
||||
exports.seed = async (knex) => {
|
||||
if (!process.env.DEFAULT_ADMIN_EMAIL) {
|
||||
return;
|
||||
const email = process.env.DEFAULT_ADMIN_EMAIL && process.env.DEFAULT_ADMIN_EMAIL.toLowerCase();
|
||||
|
||||
if (email) {
|
||||
const data = buildData();
|
||||
|
||||
let userId;
|
||||
try {
|
||||
[{ id: userId }] = await knex('user_account').insert(
|
||||
{
|
||||
...data,
|
||||
email,
|
||||
subscribeToOwnCards: false,
|
||||
subscribeToCardWhenCommenting: true,
|
||||
turnOffRecentCardHighlighting: false,
|
||||
enableFavoritesByDefault: false,
|
||||
defaultEditorMode: 'wysiwyg',
|
||||
defaultHomeView: 'groupedProjects',
|
||||
defaultProjectsOrder: 'byDefault',
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
'id',
|
||||
);
|
||||
} catch (error) {
|
||||
/* empty */
|
||||
}
|
||||
|
||||
if (!userId) {
|
||||
await knex('user_account').update(data).where('email', email);
|
||||
}
|
||||
}
|
||||
|
||||
const email = process.env.DEFAULT_ADMIN_EMAIL.toLowerCase();
|
||||
const data = buildData();
|
||||
const activeUsersLimit = parseInt(process.env.ACTIVE_USERS_LIMIT, 10);
|
||||
|
||||
try {
|
||||
await knex('user_account').insert({
|
||||
...data,
|
||||
email,
|
||||
subscribeToOwnCards: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
});
|
||||
} catch (error) {
|
||||
await knex('user_account').update(data).where('email', email);
|
||||
if (!Number.isNaN(activeUsersLimit)) {
|
||||
let orderByQuery;
|
||||
let orderByQueryValues;
|
||||
|
||||
if (email) {
|
||||
orderByQuery = 'CASE WHEN email = ? THEN 0 WHEN role = ? THEN 1 ELSE 2 END';
|
||||
orderByQueryValues = [email, 'admin'];
|
||||
} else {
|
||||
orderByQuery = 'CASE WHEN role = ? THEN 0 ELSE 1 END';
|
||||
orderByQueryValues = 'admin';
|
||||
}
|
||||
|
||||
const users = await knex('user_account')
|
||||
.select('id')
|
||||
.where('is_deactivated', false)
|
||||
.orderByRaw(orderByQuery, orderByQueryValues)
|
||||
.orderBy('id')
|
||||
.offset(activeUsersLimit);
|
||||
|
||||
if (users.length > 0) {
|
||||
const userIds = users.map(({ id }) => id);
|
||||
|
||||
await knex('user_account')
|
||||
.update({
|
||||
isDeactivated: true,
|
||||
})
|
||||
.whereIn('id', userIds);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue