}
pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> {
- if !local_user_view.local_user.admin {
+ if !local_user_view.person.admin {
return Err(ApiError::err("not_an_admin").into());
}
Ok(())
public_key: Some(Some(actor_keypair.public_key)),
inbox_url: Some(generate_inbox_url(&actor_id)?),
shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)),
+ admin: Some(no_admins),
..PersonForm::default()
};
person_id: inserted_person.id,
email: Some(data.email.to_owned()),
password_encrypted: data.password.to_owned(),
- admin: Some(no_admins),
show_nsfw: Some(data.show_nsfw),
theme: Some("browser".into()),
default_sort_type: Some(SortType::Active as i16),
actor_id: None,
bio,
local: None,
+ admin: None,
private_key: None,
public_key: None,
last_refreshed_at: None,
person_id,
email,
password_encrypted,
- admin: None,
show_nsfw: data.show_nsfw,
theme: data.theme.to_owned(),
default_sort_type,
let added = data.added;
let added_person_id = data.person_id;
let added_admin = match blocking(context.pool(), move |conn| {
- LocalUser::add_admin(conn, added_person_id, added)
+ Person::add_admin(conn, added_person_id, added)
})
.await?
{
// Mod tables
let form = ModAddForm {
mod_person_id: local_user_view.person.id,
- other_person_id: added_admin.person_id,
+ other_person_id: added_admin.id,
removed: Some(!data.added),
};
actor_id: Some(check_object_domain(person, expected_domain)?),
bio: Some(bio),
local: Some(false),
+ admin: Some(false),
private_key: None,
public_key: Some(Some(person.ext_one.public_key.to_owned().public_key_pem)),
last_refreshed_at: Some(naive_now()),
schema::local_user::dsl::*,
source::local_user::{LocalUser, LocalUserForm},
LocalUserId,
- PersonId,
};
mod safe_settings_type {
id,
person_id,
email,
- admin,
show_nsfw,
theme,
default_sort_type,
id,
person_id,
email,
- admin,
show_nsfw,
theme,
default_sort_type,
local_user_id: LocalUserId,
new_password: &str,
) -> Result<LocalUser, Error>;
- fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result<LocalUser, Error>;
}
impl LocalUser_ for LocalUser {
))
.get_result::<Self>(conn)
}
-
- fn add_admin(conn: &PgConnection, for_person_id: PersonId, added: bool) -> Result<Self, Error> {
- diesel::update(local_user.filter(person_id.eq(for_person_id)))
- .set(admin.eq(added))
- .get_result::<Self>(conn)
- }
}
impl Crud<LocalUserForm, LocalUserId> for LocalUser {
inbox_url,
shared_inbox_url,
matrix_user_id,
+ admin,
);
impl ToSafe for Person {
inbox_url,
shared_inbox_url,
matrix_user_id,
+ admin,
)
}
}
inbox_url,
shared_inbox_url,
matrix_user_id,
+ admin,
);
impl ToSafe for PersonAlias1 {
inbox_url,
shared_inbox_url,
matrix_user_id,
+ admin,
)
}
}
inbox_url,
shared_inbox_url,
matrix_user_id,
+ admin,
);
impl ToSafe for PersonAlias2 {
inbox_url,
shared_inbox_url,
matrix_user_id,
+ admin,
)
}
}
pub trait Person_ {
fn ban_person(conn: &PgConnection, person_id: PersonId, ban: bool) -> Result<Person, Error>;
+ fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result<Person, Error>;
fn find_by_name(conn: &PgConnection, name: &str) -> Result<Person, Error>;
fn mark_as_updated(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error>;
fn delete_account(conn: &PgConnection, person_id: PersonId) -> Result<Person, Error>;
.get_result::<Self>(conn)
}
+ fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result<Self, Error> {
+ diesel::update(person.find(person_id))
+ .set(admin.eq(added))
+ .get_result::<Self>(conn)
+ }
+
fn find_by_name(conn: &PgConnection, from_name: &str) -> Result<Person, Error> {
person
.filter(deleted.eq(false))
actor_id: inserted_person.actor_id.to_owned(),
bio: None,
local: true,
+ admin: false,
private_key: None,
public_key: None,
last_refreshed_at: inserted_person.published,
person_id -> Int4,
password_encrypted -> Text,
email -> Nullable<Text>,
- admin -> Bool,
show_nsfw -> Bool,
theme -> Varchar,
default_sort_type -> Int2,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
+ admin -> Bool,
}
}
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
+ admin -> Bool,
}
}
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
+ admin -> Bool,
}
}
pub person_id: PersonId,
pub password_encrypted: String,
pub email: Option<String>,
- pub admin: bool,
pub show_nsfw: bool,
pub theme: String,
pub default_sort_type: i16,
pub person_id: PersonId,
pub password_encrypted: String,
pub email: Option<Option<String>>,
- pub admin: Option<bool>,
pub show_nsfw: Option<bool>,
pub theme: Option<String>,
pub default_sort_type: Option<i16>,
pub id: LocalUserId,
pub person_id: PersonId,
pub email: Option<String>,
- pub admin: bool,
pub show_nsfw: bool,
pub theme: String,
pub default_sort_type: i16,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
+ pub admin: bool,
}
/// A safe representation of person, without the sensitive info
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
+ pub admin: bool,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
+ pub admin: bool,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
+ pub admin: bool,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
+ pub admin: bool,
}
#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
+ pub admin: bool,
}
#[derive(Insertable, AsChangeset, Clone, Default)]
pub inbox_url: Option<DbUrl>,
pub shared_inbox_url: Option<Option<DbUrl>>,
pub matrix_user_id: Option<Option<String>>,
+ pub admin: Option<bool>,
}
local: true,
banned: false,
deleted: false,
+ admin: false,
bio: None,
banner: None,
updated: None,
avatar: None,
actor_id: inserted_person.actor_id.to_owned(),
local: true,
+ admin: false,
banned: false,
deleted: false,
bio: None,
ViewToVec,
};
use lemmy_db_schema::{
- schema::{local_user, person, person_aggregates},
+ schema::{person, person_aggregates},
source::person::{Person, PersonSafe},
PersonId,
};
pub fn admins(conn: &PgConnection) -> Result<Vec<Self>, Error> {
let admins = person::table
.inner_join(person_aggregates::table)
- .inner_join(local_user::table)
.select((Person::safe_columns_tuple(), person_aggregates::all_columns))
- .filter(local_user::admin.eq(true))
+ .filter(person::admin.eq(true))
.order_by(person::published)
.load::<PersonViewSafeTuple>(conn)?;
alter table local_user add column matrix_user_id text;
+alter table local_user add column admin boolean default false not null;
update local_user lu
-set matrix_user_id = p.matrix_user_id
+set
+ matrix_user_id = p.matrix_user_id,
+ admin = p.admin
from person p
where p.id = lu.person_id;
drop view person_alias_1, person_alias_2;
alter table person drop column matrix_user_id;
+alter table person drop column admin;
-- Regenerate the person_alias views
create view person_alias_1 as select * from person;
alter table person add column matrix_user_id text;
+alter table person add column admin boolean default false not null;
update person p
-set matrix_user_id = lu.matrix_user_id
+set
+ matrix_user_id = lu.matrix_user_id,
+ admin = lu.admin
from local_user lu
where p.id = lu.person_id;
alter table local_user drop column matrix_user_id;
+alter table local_user drop column admin;
-- Regenerate the person_alias views
drop view person_alias_1, person_alias_2;