stuff #29

Merged
PouuleT merged 1 commits from stuff into master 2020-04-16 16:00:05 +00:00
3 changed files with 16 additions and 3 deletions
Showing only changes of commit cb6618e9f1 - Show all commits

View File

@ -4,6 +4,7 @@ import (
"database/sql" "database/sql"
"errors" "errors"
"fmt" "fmt"
"time"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/jmoiron/sqlx/types" "github.com/jmoiron/sqlx/types"
@ -25,7 +26,16 @@ const (
RETURNING *;` RETURNING *;`
deleteUserQuery = `DELETE FROM users WHERE id=:id;` deleteUserQuery = `DELETE FROM users WHERE id=:id;`
getAllUsersQuery = `SELECT * FROM users order by created_at;` getAllUsersQuery = `
SELECT u.*, tok.last_seen
FROM users u
LEFT OUTER JOIN (
SELECT username, MAX(last_used) AS last_seen
FROM tokens GROUP BY username
) AS tok
ON u.name = tok.username
ORDER by u.created_at;
`
getPolochonUsersQuery = `SELECT * FROM users WHERE polochon_id = $1;` getPolochonUsersQuery = `SELECT * FROM users WHERE polochon_id = $1;`
) )
@ -51,6 +61,7 @@ type User struct {
PolochonID sql.NullString `json:"polochon_id" db:"polochon_id"` PolochonID sql.NullString `json:"polochon_id" db:"polochon_id"`
PolochonActivated bool `json:"polochon_activated" db:"polochon_activated"` PolochonActivated bool `json:"polochon_activated" db:"polochon_activated"`
Polochon *Polochon `json:"polochon"` Polochon *Polochon `json:"polochon"`
LastSeen *time.Time `json:"last_seen" db:"last_seen"`
} }
// NewPapiClient creates a new papi client for the given user // NewPapiClient creates a new papi client for the given user

View File

@ -1,4 +1,5 @@
import React from "react"; import React from "react";
import moment from "moment";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
@ -7,10 +8,10 @@ import { UserEdit } from "./userEdit";
export const User = ({ id }) => { export const User = ({ id }) => {
const user = useSelector((state) => state.admin.users.get(id)); const user = useSelector((state) => state.admin.users.get(id));
const polochon = user.polochon; const polochon = user.polochon;
const lastSeen = moment(user.last_seen, "YYYY-MM-DDTHH:mm:ss.SZ");
return ( return (
<tr> <tr>
<td>{user.id}</td>
<td>{user.name}</td> <td>{user.name}</td>
<td> <td>
<span <span
@ -32,6 +33,7 @@ export const User = ({ id }) => {
} }
></span> ></span>
</td> </td>
<td>{lastSeen.isValid() ? lastSeen.fromNow() : "-"}</td>
<td> <td>
<UserEdit id={id} /> <UserEdit id={id} />
</td> </td>

View File

@ -24,13 +24,13 @@ export const UserList = () => {
<table className="table table-striped"> <table className="table table-striped">
<thead className="table-secondary"> <thead className="table-secondary">
<tr> <tr>
<th>#</th>
<th>Name</th> <th>Name</th>
<th>Activated</th> <th>Activated</th>
<th>Admin</th> <th>Admin</th>
<th>Polochon URL</th> <th>Polochon URL</th>
<th>Polochon token</th> <th>Polochon token</th>
<th>Polochon activated</th> <th>Polochon activated</th>
<th>Last seen</th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>