continued
implemented HTMX implemented ORM (sequelize)
This commit is contained in:
parent
2a9bd4e81b
commit
d756a192e4
71 changed files with 3822 additions and 694 deletions
59
routes/htmx/admin/groups/[groupid].mjs
Normal file
59
routes/htmx/admin/groups/[groupid].mjs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
|
||||
import {
|
||||
Group,
|
||||
User
|
||||
} from "../../../../lib/database/connect.mjs";
|
||||
|
||||
import {
|
||||
getConfig
|
||||
} from "../../../../lib/config.mjs";
|
||||
|
||||
|
||||
export const get = async function (request, response) {
|
||||
if (request.getAuthState() != 'authenticated') {
|
||||
response.set('HX-Redirect', '/login').status(401).end();
|
||||
return;
|
||||
}
|
||||
|
||||
const dbGroup = await Group.findByPk(request.params.groupid);
|
||||
const config = await getConfig();
|
||||
|
||||
const userList = await User.findAll({
|
||||
attributes: [
|
||||
'id',
|
||||
'uidnumber',
|
||||
'name',
|
||||
'othergroups',
|
||||
'primarygroup'
|
||||
]
|
||||
}).filter((user) => {
|
||||
// check if users primary group is the group being edited
|
||||
if (user.primarygroup == dbGroup.gidnumber) {
|
||||
return true;
|
||||
}
|
||||
// check if users other groups include the group being edited
|
||||
if (user.othergroups.split(',').map(gidnumber => parseInt(gidnumber)).includes(dbGroup.gidnumber)) {
|
||||
return true;
|
||||
}
|
||||
// else exclude user
|
||||
return false;
|
||||
}).map((user) => {
|
||||
return {
|
||||
id: user.id,
|
||||
name: user.name,
|
||||
uidnumber: user.uidnumber,
|
||||
};
|
||||
});
|
||||
|
||||
response.render(`views/htmx/admin/editGroup.njk`, {
|
||||
group: {
|
||||
id: dbGroup.id,
|
||||
name: dbGroup.name,
|
||||
gidnumber: dbGroup.gidnumber,
|
||||
},
|
||||
ldap: {
|
||||
baseDN: config.ldap.baseDN,
|
||||
},
|
||||
userList: userList
|
||||
});
|
||||
}
|
||||
18
routes/htmx/admin/groups/table.mjs
Normal file
18
routes/htmx/admin/groups/table.mjs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
import {
|
||||
Group
|
||||
} from "../../../../lib/database/connect.mjs";
|
||||
|
||||
|
||||
export const get = async function (request, response) {
|
||||
if (request.getAuthState() != 'authenticated') {
|
||||
response.set('HX-Redirect', '/login').status(401).end();
|
||||
return;
|
||||
}
|
||||
|
||||
let groupList = await Group.findAll();
|
||||
|
||||
response.render(`views/htmx/admin/groupTable.njk`, {
|
||||
groupList: groupList
|
||||
});
|
||||
}
|
||||
53
routes/htmx/admin/users/[userid].mjs
Normal file
53
routes/htmx/admin/users/[userid].mjs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
|
||||
import {
|
||||
Group,
|
||||
User
|
||||
} from "../../../../lib/database/connect.mjs";
|
||||
|
||||
|
||||
export const get = async function (request, response) {
|
||||
if (request.getAuthState() != 'authenticated') {
|
||||
response.set('HX-Redirect', '/login').status(401).end();
|
||||
return;
|
||||
}
|
||||
|
||||
const dbUser = await User.findByPk(request.params.userid);
|
||||
|
||||
if (!dbUser) {
|
||||
response.status(404).end('User not found');
|
||||
return;
|
||||
}
|
||||
|
||||
const userGroups = await (async () => {
|
||||
if (!dbUser.othergroups || dbUser.othergroups.length == 0) {
|
||||
return [];
|
||||
} else {
|
||||
return dbUser.othergroups.split(',').map(gid => parseInt(gid));
|
||||
}
|
||||
})();
|
||||
|
||||
const groupList = (await Group.findAll()).map((dbGroup) => {
|
||||
return {
|
||||
id: dbGroup.id,
|
||||
gidnumber: dbGroup.gidnumber,
|
||||
name: dbGroup.name,
|
||||
isPrimaryGroup: dbUser.primarygroup == dbGroup.gidnumber,
|
||||
isOtherGroup: userGroups.includes(dbGroup.gidnumber)
|
||||
};
|
||||
});
|
||||
|
||||
console.log(groupList);
|
||||
|
||||
response.render(`views/htmx/admin/editUser.njk`, {
|
||||
user: {
|
||||
id: dbUser.id,
|
||||
username: dbUser.name,
|
||||
uidnumber: dbUser.uidnumber,
|
||||
firstName: dbUser.givenname,
|
||||
lastName: dbUser.sn,
|
||||
mail: dbUser.mail,
|
||||
disabled: dbUser.disabled,
|
||||
},
|
||||
groupList: groupList
|
||||
});
|
||||
}
|
||||
18
routes/htmx/admin/users/table.mjs
Normal file
18
routes/htmx/admin/users/table.mjs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
import {
|
||||
User
|
||||
} from "../../../../lib/database/connect.mjs";
|
||||
|
||||
|
||||
export const get = async function (request, response) {
|
||||
if (request.getAuthState() != 'authenticated') {
|
||||
response.set('HX-Redirect', '/login').status(401).end();
|
||||
return;
|
||||
}
|
||||
|
||||
let userList = await User.findAll();
|
||||
|
||||
response.render(`views/htmx/admin/userTable.njk`, {
|
||||
userList: userList
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue