Content-Length: 505096 | pFad | https://github.com/sebadob/rauthy/commit/4c41d64f570dbbe94dcb8b681ac31608ed492652

8D Merge pull request #431 from sebadob/413-sort-users-created-login · sebadob/rauthy@4c41d64 · GitHub
Skip to content

Commit

Permalink
Merge pull request #431 from sebadob/413-sort-users-created-login
Browse files Browse the repository at this point in the history
feat: sort users created login
  • Loading branch information
sebadob authored May 10, 2024
2 parents 033db25 + 3e55b74 commit 4c41d64
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 39 deletions.
26 changes: 2 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions frontend/src/components/admin/users/Users.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import PaginationServer from "$lib/PaginationServer.svelte";
let msg = '';
let isInitialized = false;
let users = [];
let resUsers = [];
Expand Down Expand Up @@ -42,6 +41,20 @@
label: 'ID',
callback: (a, b) => a.id.localeCompare(b.id),
},
{
label: 'Created',
callback: (a, b) => a.created_at < b.created_at,
},
{
label: 'Last Login',
callback: (a, b) => {
// 9999999999 as default to make ordering correct with a unix timestamp
// otherwise undefined values will screw ordering up
let al = a.last_login || 9999999999;
let bl = b.last_login || 9999999999;
return al < bl;
}
},
];
onMount(async () => {
Expand Down Expand Up @@ -157,7 +170,7 @@

<div id="users">
{#if useServerSideIdx && !isSearchFiltered}
{#each users as user (user.id)}
{#each resUsers as user (user.id)}
<div>
<UserTile userId={user.id} userEmail={user.email} onSave={onSave}/>
</div>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/lib/search/SearchBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import IconMagnify from "$lib/icons/IconMagnify.svelte";
import {onMount} from "svelte";
import Tooltip from "../Tooltip.svelte";
import {getKey} from "../utils/helpers.js";
import IconBackspace from "$lib/icons/IconBackspace.svelte";
import {getSearch} from "../../utils/dataFetchingAdmin.js";
import {SERVER_SIDE_SEARCH_THRES} from "../../utils/constants.js";
Expand Down Expand Up @@ -56,6 +57,12 @@
}
function filerItems() {
if (search.length < 2) {
resItems = items;
isSearchFiltered = false;
return;
}
resItems = [...items.filter(i => {
// This switch is a bit more annoying to maintain, but we can set a more strict CSP without `eval`
if (options.length > 0) {
Expand Down Expand Up @@ -103,6 +110,7 @@
<input
class="input"
type="text"
name={getKey()}
bind:value={search}
placeholder="Search"
autocomplete="off"
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ migrate-postgres:


# runs any of: none (sqlite), postgres, ui
@run ty="sqlite":
run ty="sqlite":
#!/usr/bin/env bash
set -euxo pipefail
clear
Expand Down
38 changes: 27 additions & 11 deletions rauthy-models/src/entity/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl User {
) -> Result<Vec<UserResponseSimple>, ErrorResponse> {
let res = sqlx::query_as!(
UserResponseSimple,
"SELECT id, email FROM users ORDER BY created_at ASC"
"SELECT id, email, created_at, last_login FROM users ORDER BY created_at ASC"
)
.fetch_all(&data.db)
.await?;
Expand Down Expand Up @@ -373,7 +373,7 @@ impl User {
if backwards {
offset += page_size;
let mut rows = sqlx::query!(
r#"SELECT id, email, created_at
r#"SELECT id, email, created_at, last_login
FROM users
WHERE created_at <= $1 AND id != $2
ORDER BY created_at DESC
Expand All @@ -393,12 +393,14 @@ impl User {
res.push(UserResponseSimple {
id: row.id,
email: row.email,
created_at: row.created_at,
last_login: row.last_login,
});
latest_ts = row.created_at;
}
} else {
let rows = sqlx::query!(
r#"SELECT id, email, created_at
r#"SELECT id, email, created_at, last_login
FROM users
WHERE created_at >= $1 AND id != $2
ORDER BY created_at ASC
Expand All @@ -416,6 +418,8 @@ impl User {
res.push(UserResponseSimple {
id: row.id,
email: row.email,
created_at: row.created_at,
last_login: row.last_login,
});
latest_ts = row.created_at;
}
Expand All @@ -424,7 +428,7 @@ impl User {
// backwards without any continuation token will simply
// serve the last elements without any other conditions
let mut rows = sqlx::query!(
r#"SELECT id, email, created_at
r#"SELECT id, email, created_at, last_login
FROM users
ORDER BY created_at DESC
LIMIT $1
Expand All @@ -441,12 +445,14 @@ impl User {
res.push(UserResponseSimple {
id: row.id,
email: row.email,
created_at: row.created_at,
last_login: row.last_login,
});
latest_ts = row.created_at;
}
} else {
let rows = sqlx::query!(
r#"SELECT id, email, created_at
r#"SELECT id, email, created_at, last_login
FROM users
ORDER BY created_at ASC
LIMIT $1
Expand All @@ -461,6 +467,8 @@ impl User {
res.push(UserResponseSimple {
id: row.id,
email: row.email,
created_at: row.created_at,
last_login: row.last_login,
});
latest_ts = row.created_at;
}
Expand Down Expand Up @@ -620,7 +628,11 @@ impl User {
SearchParamsIdx::Id | SearchParamsIdx::UserId => {
query_as!(
UserResponseSimple,
"SELECT id, email FROM users WHERE id LIKE $1 ORDER BY created_at ASC LIMIT $2",
r#"SELECT id, email, created_at, last_login
FROM users
WHERE id LIKE $1
ORDER BY created_at ASC
LIMIT $2"#,
q,
limit
)
Expand All @@ -629,11 +641,15 @@ impl User {
}
SearchParamsIdx::Email => {
query_as!(
UserResponseSimple,
"SELECT id, email FROM users WHERE email LIKE $1 ORDER BY created_at ASC LIMIT $2",
q,
limit
)
UserResponseSimple,
r#"SELECT id, email, created_at, last_login
FROM users
WHERE email LIKE $1
ORDER BY created_at ASC
LIMIT $2"#,
q,
limit
)
.fetch_all(&data.db)
.await?
}
Expand Down
4 changes: 4 additions & 0 deletions rauthy-models/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,17 @@ impl UserResponse {
pub struct UserResponseSimple {
pub id: String,
pub email: String,
pub created_at: i64,
pub last_login: Option<i64>,
}

impl From<User> for UserResponseSimple {
fn from(value: User) -> Self {
Self {
id: value.id,
email: value.email,
created_at: value.created_at,
last_login: value.last_login,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rauthy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ SWAGGER_UI_EXTERNAL=true
# change search and pagination for users in the Admin UI from client
# side to server side to not have a degradation in performance.
# default: 1000
SSP_THRESHOLD=2
SSP_THRESHOLD=1000

#####################################
############ TEMPLATES ##############
Expand Down

0 comments on commit 4c41d64

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/4c41d64f570dbbe94dcb8b681ac31608ed492652

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy