Create API endpoint for adding aliases
This commit is contained in:
parent
13df9e0478
commit
99f6c08e9a
4 changed files with 68 additions and 1 deletions
|
@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
- Support calling `/api/v1/accounts/search` with `resolve` parameter.
|
- Support calling `/api/v1/accounts/search` with `resolve` parameter.
|
||||||
- Created `/api/v1/accounts/aliases/all` API endpoint.
|
- Created `/api/v1/accounts/aliases/all` API endpoint.
|
||||||
|
- Created API endpoint for adding aliases.
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -803,6 +803,28 @@ paths:
|
||||||
$ref: '#/components/schemas/CredentialAccount'
|
$ref: '#/components/schemas/CredentialAccount'
|
||||||
400:
|
400:
|
||||||
description: Invalid request data.
|
description: Invalid request data.
|
||||||
|
/api/v1/settings/aliases:
|
||||||
|
post:
|
||||||
|
summary: Add alias (not verified).
|
||||||
|
requestBody:
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
acct:
|
||||||
|
description: Actor address.
|
||||||
|
type: string
|
||||||
|
example: user@example.com
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Successful operation
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
$ref: '#/components/schemas/Aliases'
|
||||||
|
404:
|
||||||
|
description: Profile not found.
|
||||||
/api/v1/settings/export_followers:
|
/api/v1/settings/export_followers:
|
||||||
get:
|
get:
|
||||||
summary: Export followers to CSV file
|
summary: Export followers to CSV file
|
||||||
|
|
|
@ -10,6 +10,11 @@ pub struct ImportFollowsRequest {
|
||||||
pub follows_csv: String,
|
pub follows_csv: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct AddAliasRequest {
|
||||||
|
pub acct: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct MoveFollowersRequest {
|
pub struct MoveFollowersRequest {
|
||||||
pub from_actor_id: String,
|
pub from_actor_id: String,
|
||||||
|
|
|
@ -12,7 +12,12 @@ use mitra_config::Config;
|
||||||
use mitra_models::{
|
use mitra_models::{
|
||||||
database::{get_database_client, DatabaseError, DbPool},
|
database::{get_database_client, DatabaseError, DbPool},
|
||||||
profiles::helpers::find_verified_aliases,
|
profiles::helpers::find_verified_aliases,
|
||||||
profiles::queries::get_profile_by_remote_actor_id,
|
profiles::queries::{
|
||||||
|
get_profile_by_acct,
|
||||||
|
get_profile_by_remote_actor_id,
|
||||||
|
update_profile,
|
||||||
|
},
|
||||||
|
profiles::types::ProfileUpdateData,
|
||||||
users::queries::set_user_password,
|
users::queries::set_user_password,
|
||||||
};
|
};
|
||||||
use mitra_utils::passwords::hash_password;
|
use mitra_utils::passwords::hash_password;
|
||||||
|
@ -21,6 +26,7 @@ use crate::activitypub::identifiers::profile_actor_id;
|
||||||
use crate::errors::ValidationError;
|
use crate::errors::ValidationError;
|
||||||
use crate::http::get_request_base_url;
|
use crate::http::get_request_base_url;
|
||||||
use crate::mastodon_api::{
|
use crate::mastodon_api::{
|
||||||
|
accounts::helpers::get_aliases,
|
||||||
accounts::types::Account,
|
accounts::types::Account,
|
||||||
errors::MastodonError,
|
errors::MastodonError,
|
||||||
oauth::auth::get_current_user,
|
oauth::auth::get_current_user,
|
||||||
|
@ -33,6 +39,7 @@ use super::helpers::{
|
||||||
parse_address_list,
|
parse_address_list,
|
||||||
};
|
};
|
||||||
use super::types::{
|
use super::types::{
|
||||||
|
AddAliasRequest,
|
||||||
ImportFollowsRequest,
|
ImportFollowsRequest,
|
||||||
MoveFollowersRequest,
|
MoveFollowersRequest,
|
||||||
PasswordChangeRequest,
|
PasswordChangeRequest,
|
||||||
|
@ -59,6 +66,37 @@ async fn change_password_view(
|
||||||
Ok(HttpResponse::Ok().json(account))
|
Ok(HttpResponse::Ok().json(account))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[post("/aliases")]
|
||||||
|
async fn add_alias_view(
|
||||||
|
auth: BearerAuth,
|
||||||
|
config: web::Data<Config>,
|
||||||
|
connection_info: ConnectionInfo,
|
||||||
|
db_pool: web::Data<DbPool>,
|
||||||
|
request_data: web::Json<AddAliasRequest>,
|
||||||
|
) -> Result<HttpResponse, MastodonError> {
|
||||||
|
let db_client = &mut **get_database_client(&db_pool).await?;
|
||||||
|
let mut current_user = get_current_user(db_client, auth.token()).await?;
|
||||||
|
let alias = get_profile_by_acct(db_client, &request_data.acct).await?;
|
||||||
|
let instance = config.instance();
|
||||||
|
let alias_id = profile_actor_id(&instance.url(), &alias);
|
||||||
|
let mut profile_data = ProfileUpdateData::from(¤t_user.profile);
|
||||||
|
if !profile_data.aliases.contains(&alias_id) {
|
||||||
|
profile_data.aliases.push(alias_id);
|
||||||
|
};
|
||||||
|
current_user.profile = update_profile(
|
||||||
|
db_client,
|
||||||
|
¤t_user.id,
|
||||||
|
profile_data,
|
||||||
|
).await?;
|
||||||
|
let aliases = get_aliases(
|
||||||
|
db_client,
|
||||||
|
&get_request_base_url(connection_info),
|
||||||
|
&instance.url(),
|
||||||
|
¤t_user.profile,
|
||||||
|
).await?;
|
||||||
|
Ok(HttpResponse::Ok().json(aliases))
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/export_followers")]
|
#[get("/export_followers")]
|
||||||
async fn export_followers_view(
|
async fn export_followers_view(
|
||||||
auth: BearerAuth,
|
auth: BearerAuth,
|
||||||
|
@ -185,6 +223,7 @@ async fn move_followers(
|
||||||
pub fn settings_api_scope() -> Scope {
|
pub fn settings_api_scope() -> Scope {
|
||||||
web::scope("/api/v1/settings")
|
web::scope("/api/v1/settings")
|
||||||
.service(change_password_view)
|
.service(change_password_view)
|
||||||
|
.service(add_alias_view)
|
||||||
.service(export_followers_view)
|
.service(export_followers_view)
|
||||||
.service(export_follows_view)
|
.service(export_follows_view)
|
||||||
.service(import_follows_view)
|
.service(import_follows_view)
|
||||||
|
|
Loading…
Reference in a new issue