Some changes
- Changing claim name to local_user_id to facilitate logout. - Changing AddAdmin back to using person_id
This commit is contained in:
parent
5998c83b2a
commit
8ee624a542
6 changed files with 16 additions and 13 deletions
|
@ -103,7 +103,7 @@ pub(crate) async fn get_local_user_view_from_jwt(
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(ApiError::err("not_logged_in").into()),
|
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 =
|
let local_user_view =
|
||||||
blocking(pool, move |conn| LocalUserView::read(conn, local_user_id)).await??;
|
blocking(pool, move |conn| LocalUserView::read(conn, local_user_id)).await??;
|
||||||
// Check for a site ban
|
// Check for a site ban
|
||||||
|
@ -131,7 +131,7 @@ pub(crate) async fn get_local_user_settings_view_from_jwt(
|
||||||
Ok(claims) => claims.claims,
|
Ok(claims) => claims.claims,
|
||||||
Err(_e) => return Err(ApiError::err("not_logged_in").into()),
|
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| {
|
let local_user_view = blocking(pool, move |conn| {
|
||||||
LocalUserSettingsView::read(conn, local_user_id)
|
LocalUserSettingsView::read(conn, local_user_id)
|
||||||
})
|
})
|
||||||
|
|
|
@ -650,9 +650,9 @@ impl Perform for AddAdmin {
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
let added = data.added;
|
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)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,7 +107,7 @@ pub struct MarkAllAsRead {
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct AddAdmin {
|
pub struct AddAdmin {
|
||||||
pub local_user_id: i32,
|
pub person_id: i32,
|
||||||
pub added: bool,
|
pub added: bool,
|
||||||
pub auth: String,
|
pub auth: String,
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub trait LocalUser_ {
|
||||||
local_user_id: i32,
|
local_user_id: i32,
|
||||||
new_password: &str,
|
new_password: &str,
|
||||||
) -> Result<LocalUser, Error>;
|
) -> 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 {
|
||||||
|
@ -94,8 +94,8 @@ 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> {
|
fn add_admin(conn: &PgConnection, for_person_id: i32, added: bool) -> Result<Self, Error> {
|
||||||
diesel::update(local_user.find(local_user_id))
|
diesel::update(local_user.filter(person_id.eq(for_person_id)))
|
||||||
.set(admin.eq(added))
|
.set(admin.eq(added))
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@ use diesel::PgConnection;
|
||||||
use lemmy_api_structs::blocking;
|
use lemmy_api_structs::blocking;
|
||||||
use lemmy_db_queries::{
|
use lemmy_db_queries::{
|
||||||
source::{community::Community_, person::Person_},
|
source::{community::Community_, person::Person_},
|
||||||
|
Crud,
|
||||||
ListingType,
|
ListingType,
|
||||||
SortType,
|
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::{
|
use lemmy_db_views::{
|
||||||
comment_view::{CommentQueryBuilder, CommentView},
|
comment_view::{CommentQueryBuilder, CommentView},
|
||||||
post_view::{PostQueryBuilder, PostView},
|
post_view::{PostQueryBuilder, PostView},
|
||||||
|
@ -223,7 +224,8 @@ fn get_feed_front(
|
||||||
jwt: String,
|
jwt: String,
|
||||||
) -> Result<ChannelBuilder, LemmyError> {
|
) -> Result<ChannelBuilder, LemmyError> {
|
||||||
let site_view = SiteView::read(&conn)?;
|
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)
|
let posts = PostQueryBuilder::create(&conn)
|
||||||
.listing_type(&ListingType::Subscribed)
|
.listing_type(&ListingType::Subscribed)
|
||||||
|
@ -249,7 +251,8 @@ fn get_feed_front(
|
||||||
|
|
||||||
fn get_feed_inbox(conn: &PgConnection, jwt: String) -> Result<ChannelBuilder, LemmyError> {
|
fn get_feed_inbox(conn: &PgConnection, jwt: String) -> Result<ChannelBuilder, LemmyError> {
|
||||||
let site_view = SiteView::read(&conn)?;
|
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;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ type Jwt = String;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Claims {
|
pub struct Claims {
|
||||||
pub id: i32,
|
pub local_user_id: i32,
|
||||||
pub iss: String,
|
pub iss: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ impl Claims {
|
||||||
|
|
||||||
pub fn jwt(local_user_id: i32, hostname: String) -> Result<Jwt, jsonwebtoken::errors::Error> {
|
pub fn jwt(local_user_id: i32, hostname: String) -> Result<Jwt, jsonwebtoken::errors::Error> {
|
||||||
let my_claims = Claims {
|
let my_claims = Claims {
|
||||||
id: local_user_id,
|
local_user_id,
|
||||||
iss: hostname,
|
iss: hostname,
|
||||||
};
|
};
|
||||||
encode(
|
encode(
|
||||||
|
|
Loading…
Reference in a new issue