- Changing claim name to local_user_id to facilitate logout.
- Changing AddAdmin back to using person_id
Ok(claims) => claims.claims,
Err(_e) => return Err(ApiError::err("not_logged_in").into()),
};
Ok(claims) => claims.claims,
Err(_e) => return Err(ApiError::err("not_logged_in").into()),
};
- let local_user_id = claims.id;
+ let local_user_id = claims.local_user_id;
let local_user_view =
blocking(pool, move |conn| LocalUserView::read(conn, local_user_id)).await??;
// Check for a site ban
let local_user_view =
blocking(pool, move |conn| LocalUserView::read(conn, local_user_id)).await??;
// Check for a site ban
Ok(claims) => claims.claims,
Err(_e) => return Err(ApiError::err("not_logged_in").into()),
};
Ok(claims) => claims.claims,
Err(_e) => return Err(ApiError::err("not_logged_in").into()),
};
- let local_user_id = claims.id;
+ let local_user_id = claims.local_user_id;
let local_user_view = blocking(pool, move |conn| {
LocalUserSettingsView::read(conn, local_user_id)
})
let local_user_view = blocking(pool, move |conn| {
LocalUserSettingsView::read(conn, local_user_id)
})
is_admin(&local_user_view)?;
let added = data.added;
is_admin(&local_user_view)?;
let added = data.added;
- let added_local_user_id = data.local_user_id;
+ let added_person_id = data.person_id;
let added_admin = match blocking(context.pool(), move |conn| {
let added_admin = match blocking(context.pool(), move |conn| {
- LocalUser::add_admin(conn, added_local_user_id, added)
+ LocalUser::add_admin(conn, added_person_id, added)
#[derive(Deserialize)]
pub struct AddAdmin {
#[derive(Deserialize)]
pub struct AddAdmin {
- pub local_user_id: i32,
pub added: bool,
pub auth: String,
}
pub added: bool,
pub auth: String,
}
local_user_id: i32,
new_password: &str,
) -> Result<LocalUser, Error>;
local_user_id: i32,
new_password: &str,
) -> Result<LocalUser, Error>;
- fn add_admin(conn: &PgConnection, local_user_id: i32, added: bool) -> Result<LocalUser, Error>;
+ fn add_admin(conn: &PgConnection, person_id: i32, added: bool) -> Result<LocalUser, Error>;
}
impl LocalUser_ for LocalUser {
}
impl LocalUser_ for LocalUser {
.get_result::<Self>(conn)
}
.get_result::<Self>(conn)
}
- fn add_admin(conn: &PgConnection, local_user_id: i32, added: bool) -> Result<Self, Error> {
- diesel::update(local_user.find(local_user_id))
+ fn add_admin(conn: &PgConnection, for_person_id: i32, added: bool) -> Result<Self, Error> {
+ diesel::update(local_user.filter(person_id.eq(for_person_id)))
.set(admin.eq(added))
.get_result::<Self>(conn)
}
.set(admin.eq(added))
.get_result::<Self>(conn)
}
use lemmy_api_structs::blocking;
use lemmy_db_queries::{
source::{community::Community_, person::Person_},
use lemmy_api_structs::blocking;
use lemmy_db_queries::{
source::{community::Community_, person::Person_},
ListingType,
SortType,
};
ListingType,
SortType,
};
-use lemmy_db_schema::source::{community::Community, person::Person};
+use lemmy_db_schema::source::{community::Community, local_user::LocalUser, person::Person};
use lemmy_db_views::{
comment_view::{CommentQueryBuilder, CommentView},
post_view::{PostQueryBuilder, PostView},
use lemmy_db_views::{
comment_view::{CommentQueryBuilder, CommentView},
post_view::{PostQueryBuilder, PostView},
jwt: String,
) -> Result<ChannelBuilder, LemmyError> {
let site_view = SiteView::read(&conn)?;
jwt: String,
) -> Result<ChannelBuilder, LemmyError> {
let site_view = SiteView::read(&conn)?;
- let person_id = Claims::decode(&jwt)?.claims.id;
+ let local_user_id = Claims::decode(&jwt)?.claims.local_user_id;
+ let person_id = LocalUser::read(&conn, local_user_id)?.person_id;
let posts = PostQueryBuilder::create(&conn)
.listing_type(&ListingType::Subscribed)
let posts = PostQueryBuilder::create(&conn)
.listing_type(&ListingType::Subscribed)
fn get_feed_inbox(conn: &PgConnection, jwt: String) -> Result<ChannelBuilder, LemmyError> {
let site_view = SiteView::read(&conn)?;
fn get_feed_inbox(conn: &PgConnection, jwt: String) -> Result<ChannelBuilder, LemmyError> {
let site_view = SiteView::read(&conn)?;
- let person_id = Claims::decode(&jwt)?.claims.id;
+ let local_user_id = Claims::decode(&jwt)?.claims.local_user_id;
+ let person_id = LocalUser::read(&conn, local_user_id)?.person_id;
let sort = SortType::New;
let sort = SortType::New;
#[derive(Debug, Serialize, Deserialize)]
pub struct Claims {
#[derive(Debug, Serialize, Deserialize)]
pub struct Claims {
+ pub local_user_id: i32,
pub fn jwt(local_user_id: i32, hostname: String) -> Result<Jwt, jsonwebtoken::errors::Error> {
let my_claims = Claims {
pub fn jwt(local_user_id: i32, hostname: String) -> Result<Jwt, jsonwebtoken::errors::Error> {
let my_claims = Claims {
iss: hostname,
};
encode(
iss: hostname,
};
encode(