|
|
@ -1,6 +1,5 @@
|
|
|
|
use crate::structs::PersonView;
|
|
|
|
use crate::structs::PersonView;
|
|
|
|
use diesel::{
|
|
|
|
use diesel::{
|
|
|
|
dsl::exists,
|
|
|
|
|
|
|
|
pg::Pg,
|
|
|
|
pg::Pg,
|
|
|
|
result::Error,
|
|
|
|
result::Error,
|
|
|
|
BoolExpressionMethods,
|
|
|
|
BoolExpressionMethods,
|
|
|
@ -13,7 +12,17 @@ use diesel_async::RunQueryDsl;
|
|
|
|
use lemmy_db_schema::{
|
|
|
|
use lemmy_db_schema::{
|
|
|
|
newtypes::PersonId,
|
|
|
|
newtypes::PersonId,
|
|
|
|
schema::{local_user, person, person_aggregates},
|
|
|
|
schema::{local_user, person, person_aggregates},
|
|
|
|
utils::{fuzzy_search, limit_and_offset, now, DbConn, DbPool, ListFn, Queries, ReadFn},
|
|
|
|
utils::{
|
|
|
|
|
|
|
|
functions::coalesce,
|
|
|
|
|
|
|
|
fuzzy_search,
|
|
|
|
|
|
|
|
limit_and_offset,
|
|
|
|
|
|
|
|
now,
|
|
|
|
|
|
|
|
DbConn,
|
|
|
|
|
|
|
|
DbPool,
|
|
|
|
|
|
|
|
ListFn,
|
|
|
|
|
|
|
|
Queries,
|
|
|
|
|
|
|
|
ReadFn,
|
|
|
|
|
|
|
|
},
|
|
|
|
SortType,
|
|
|
|
SortType,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
@ -48,21 +57,15 @@ fn post_to_person_sort_type(sort: SortType) -> PersonSortType {
|
|
|
|
|
|
|
|
|
|
|
|
fn queries<'a>(
|
|
|
|
fn queries<'a>(
|
|
|
|
) -> Queries<impl ReadFn<'a, PersonView, PersonId>, impl ListFn<'a, PersonView, ListMode>> {
|
|
|
|
) -> Queries<impl ReadFn<'a, PersonView, PersonId>, impl ListFn<'a, PersonView, ListMode>> {
|
|
|
|
let creator_is_admin = exists(
|
|
|
|
|
|
|
|
local_user::table.filter(
|
|
|
|
|
|
|
|
person::id
|
|
|
|
|
|
|
|
.eq(local_user::person_id)
|
|
|
|
|
|
|
|
.and(local_user::admin.eq(true)),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
let all_joins = move |query: person::BoxedQuery<'a, Pg>| {
|
|
|
|
let all_joins = move |query: person::BoxedQuery<'a, Pg>| {
|
|
|
|
query
|
|
|
|
query
|
|
|
|
.inner_join(person_aggregates::table)
|
|
|
|
.inner_join(person_aggregates::table)
|
|
|
|
|
|
|
|
.left_join(local_user::table)
|
|
|
|
.filter(person::deleted.eq(false))
|
|
|
|
.filter(person::deleted.eq(false))
|
|
|
|
.select((
|
|
|
|
.select((
|
|
|
|
person::all_columns,
|
|
|
|
person::all_columns,
|
|
|
|
person_aggregates::all_columns,
|
|
|
|
person_aggregates::all_columns,
|
|
|
|
creator_is_admin,
|
|
|
|
coalesce(local_user::admin.nullable(), false),
|
|
|
|
))
|
|
|
|
))
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -77,7 +80,7 @@ fn queries<'a>(
|
|
|
|
match mode {
|
|
|
|
match mode {
|
|
|
|
ListMode::Admins => {
|
|
|
|
ListMode::Admins => {
|
|
|
|
query = query
|
|
|
|
query = query
|
|
|
|
.filter(creator_is_admin.eq(true))
|
|
|
|
.filter(local_user::admin.eq(true))
|
|
|
|
.filter(person::deleted.eq(false))
|
|
|
|
.filter(person::deleted.eq(false))
|
|
|
|
.order_by(person::published);
|
|
|
|
.order_by(person::published);
|
|
|
|
}
|
|
|
|
}
|
|
|
|