mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 08:47:40 -05:00
Get Email for Active System Owners
This commit is contained in:
@@ -13,6 +13,42 @@ exports.isLoggedIn = function (req, res, next) {
|
||||
|
||||
// -------------------------------------------
|
||||
|
||||
exports.listActiveUsers = async function (req,res,next) {
|
||||
if (!req.user.admin) {
|
||||
res.status(401);
|
||||
res.json({ success: false, message: "Not Authorized" });
|
||||
return;
|
||||
}
|
||||
let users = {};
|
||||
let fromDate = new Date(Date.now() - 60 * 60 * 24 * 30 * 1000);
|
||||
const systems = await System.find({lastActive: {$gte: fromDate}}).populate('userId', "screenName").catch( err => {
|
||||
console.error("Error - get_systems: " + err.message);
|
||||
res.json({
|
||||
success: false,
|
||||
message: err
|
||||
});
|
||||
return;
|
||||
});
|
||||
for (let index = 0; index < systems.length; index++) {
|
||||
const system = systems[index];
|
||||
|
||||
if (!users.hasOwnProperty(system.userId.toString())) {
|
||||
const user = await User.findById(system.userId, "_id email firstName lastName lastLogin");
|
||||
users[system.userId.toString()] = user.email;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let list = [];
|
||||
for (const id in users) {
|
||||
list.push(users[id]);
|
||||
}
|
||||
|
||||
res.json(list);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
exports.listUserSystems = async function (req,res,next) {
|
||||
if (!req.user.admin) {
|
||||
res.status(401);
|
||||
|
||||
@@ -153,6 +153,7 @@ app.get("/groups/:shortName/:groupId?", isLoggedIn, groups.getGroups);
|
||||
app.delete("/groups/:shortName/:groupId", isLoggedIn, groups.deleteGroup);
|
||||
app.get("/systems", isLoggedIn, systems.listSystems)
|
||||
app.get("/admin/systems", isAdmin, systems.listAllSystems)
|
||||
app.get("/admin/users/active", isAdmin, systems.listActiveUsers)
|
||||
app.get("/admin/users", isAdmin, systems.listUserSystems)
|
||||
app.delete("/systems/:shortName", isLoggedIn, systems.deleteSystem)
|
||||
app.post("/systems/:shortName", [isLoggedIn, systems.ownSystem, systems.validateSystem, systems.updateSystem])
|
||||
|
||||
37
admin/src/ActiveUsers/ActiveUsers.js
Normal file
37
admin/src/ActiveUsers/ActiveUsers.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import {
|
||||
Container,
|
||||
Header,
|
||||
Table,
|
||||
Icon
|
||||
} from "semantic-ui-react";
|
||||
import { useGetActiveUsersQuery, } from '../features/api/apiSlice'
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
const ActiveUsers = () => {
|
||||
const { data: users, isSuccess } = useGetActiveUsersQuery();
|
||||
|
||||
|
||||
//https://stackoverflow.com/questions/36559661/how-can-i-dispatch-from-child-components-in-react-redux
|
||||
//https://stackoverflow.com/questions/42597602/react-onclick-pass-event-with-parameter
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Container>
|
||||
<Header as="h1">Email of Active Users</Header>
|
||||
|
||||
|
||||
{users &&
|
||||
users.map((user) =>
|
||||
|
||||
<span>{user}, </span>
|
||||
)}
|
||||
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
export default ActiveUsers;
|
||||
@@ -9,6 +9,7 @@ import AllSystems from "../AllSystems/AllSystems"
|
||||
import ListSystems from "../System/ListSystems"
|
||||
import UpdateSystem from "../System/UpdateSystem"
|
||||
import CreateSystem from "../System/CreateSystem"
|
||||
import ActiveUsers from "../ActiveUsers/ActiveUsers"
|
||||
|
||||
|
||||
const App = (params) => {
|
||||
@@ -22,6 +23,7 @@ const App = (params) => {
|
||||
<Route path="/create-system" element={ <Restricted><CreateSystem/></Restricted>} />
|
||||
<Route path="/list-systems" element={ <Restricted><ListSystems/></Restricted>} />
|
||||
<Route path="/all-systems" element={ <AdminRestricted><AllSystems/></AdminRestricted>} />
|
||||
<Route path="/active-users" element={ <AdminRestricted><ActiveUsers/></AdminRestricted>} />
|
||||
<Route path="/" element={ <Restricted><ListSystems/></Restricted>} />
|
||||
<Route render={() => (<div>Miss</div>)} />
|
||||
</Routes>
|
||||
|
||||
@@ -24,6 +24,10 @@ const Navigation = (props) => {
|
||||
{process.env.REACT_APP_SITE_NAME}
|
||||
</Menu.Item>
|
||||
<Menu.Menu position="right">
|
||||
{admin &&
|
||||
<Link to="/active-users">
|
||||
<Menu.Item name="active-users">Active Users</Menu.Item>
|
||||
</Link> }
|
||||
{admin &&
|
||||
<Link to="/all-systems">
|
||||
<Menu.Item name="all-systems">All Systems</Menu.Item>
|
||||
|
||||
@@ -140,6 +140,10 @@ export const apiSlice = createApi({
|
||||
// The URL for the request is '/fakeApi/posts'
|
||||
query: () => ({ url: `/admin/users`, credentials: "include" })
|
||||
}),
|
||||
getActiveUsers: builder.query({
|
||||
// The URL for the request is '/fakeApi/posts'
|
||||
query: () => ({ url: `/admin/users/active`, credentials: "include" })
|
||||
}),
|
||||
createSystem: builder.mutation({
|
||||
query: (system) => ({
|
||||
url: `/systems`,
|
||||
@@ -202,4 +206,4 @@ export const apiSlice = createApi({
|
||||
})
|
||||
|
||||
// Export the auto-generated hook for the `getPosts` query endpoint
|
||||
export const { useGetGroupsQuery, useGetSystemsQuery, useGetAllSystemsQuery, useGetTalkgroupsQuery, useGetErrorsQuery, useDeleteGroupMutation, useCreateGroupMutation, useCreateSystemMutation, useUpdateSystemMutation, useDeleteSystemMutation, useSaveGroupOrderMutation, useUpdateGroupMutation, useImportTalkgroupsMutation } = apiSlice
|
||||
export const { useGetGroupsQuery, useGetSystemsQuery, useGetAllSystemsQuery, useGetActiveUsersQuery, useGetTalkgroupsQuery, useGetErrorsQuery, useDeleteGroupMutation, useCreateGroupMutation, useCreateSystemMutation, useUpdateSystemMutation, useDeleteSystemMutation, useSaveGroupOrderMutation, useUpdateGroupMutation, useImportTalkgroupsMutation } = apiSlice
|
||||
|
||||
Reference in New Issue
Block a user