Change AddAdmin to use person_id instead of local_user_id (#3941)

- Front ends don't have easy access to local_user_id on moddable
  items like comments and posts.
pull/3947/head
Dessalines 2023-09-06 05:37:03 -04:00 committed by GitHub
parent a0ea8dbc00
commit 797d26fdf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -11,6 +11,7 @@ use lemmy_db_schema::{
},
traits::Crud,
};
use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::PersonView;
use lemmy_utils::error::{LemmyError, LemmyErrorExt, LemmyErrorType};
@ -24,9 +25,14 @@ pub async fn add_admin(
// Make sure user is an admin
is_admin(&local_user_view)?;
// Make sure that the person_id added is local
let added_local_user = LocalUserView::read_person(&mut context.pool(), data.person_id)
.await
.with_lemmy_type(LemmyErrorType::ObjectNotLocal)?;
let added_admin = LocalUser::update(
&mut context.pool(),
data.local_user_id,
added_local_user.local_user.id,
&LocalUserUpdateForm {
admin: Some(data.added),
..Default::default()

View File

@ -1,6 +1,6 @@
use crate::sensitive::Sensitive;
use lemmy_db_schema::{
newtypes::{CommentReplyId, CommunityId, LanguageId, LocalUserId, PersonId, PersonMentionId},
newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
CommentSortType,
ListingType,
SortType,
@ -198,7 +198,7 @@ pub struct MarkAllAsRead {
#[cfg_attr(feature = "full", ts(export))]
/// Adds an admin to a site.
pub struct AddAdmin {
pub local_user_id: LocalUserId,
pub person_id: PersonId,
pub added: bool,
pub auth: Sensitive<String>,
}