mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
api endpoint for all languages, fix tests, context, adjust migrations
This commit is contained in:
parent
9d66314c32
commit
4c66675e55
7 changed files with 39 additions and 5 deletions
|
@ -1,4 +1,4 @@
|
||||||
use lemmy_db_schema::{CommunityId, PersonId};
|
use lemmy_db_schema::{CommunityId, PersonId, PrimaryLanguageTag};
|
||||||
use lemmy_db_views::{
|
use lemmy_db_views::{
|
||||||
comment_view::CommentView,
|
comment_view::CommentView,
|
||||||
local_user_view::LocalUserSettingsView,
|
local_user_view::LocalUserSettingsView,
|
||||||
|
@ -88,6 +88,7 @@ pub struct EditSite {
|
||||||
pub open_registration: Option<bool>,
|
pub open_registration: Option<bool>,
|
||||||
pub enable_nsfw: Option<bool>,
|
pub enable_nsfw: Option<bool>,
|
||||||
pub community_creation_admin_only: Option<bool>,
|
pub community_creation_admin_only: Option<bool>,
|
||||||
|
pub languages: Vec<PrimaryLanguageTag>,
|
||||||
pub auth: String,
|
pub auth: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,3 +141,11 @@ pub struct FederatedInstances {
|
||||||
pub allowed: Option<Vec<String>>,
|
pub allowed: Option<Vec<String>>,
|
||||||
pub blocked: Option<Vec<String>>,
|
pub blocked: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct GetLanguages {}
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone)]
|
||||||
|
pub struct LanguagesResponse {
|
||||||
|
pub languages: Vec<PrimaryLanguageTag>,
|
||||||
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ use lemmy_api_common::{
|
||||||
person::Register,
|
person::Register,
|
||||||
site::*,
|
site::*,
|
||||||
};
|
};
|
||||||
|
use lemmy_db_schema::PrimaryLanguageTag;
|
||||||
use lemmy_db_views::site_view::SiteView;
|
use lemmy_db_views::site_view::SiteView;
|
||||||
use lemmy_db_views_actor::person_view::PersonViewSafe;
|
use lemmy_db_views_actor::person_view::PersonViewSafe;
|
||||||
use lemmy_utils::{settings::structs::Settings, version, ConnectionId, LemmyError};
|
use lemmy_utils::{settings::structs::Settings, version, ConnectionId, LemmyError};
|
||||||
|
@ -98,3 +99,22 @@ impl PerformCrud for GetSite {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait(?Send)]
|
||||||
|
impl PerformCrud for GetLanguages {
|
||||||
|
type Response = LanguagesResponse;
|
||||||
|
|
||||||
|
async fn perform(
|
||||||
|
&self,
|
||||||
|
_context: &Data<LemmyContext>,
|
||||||
|
_websocket_id: Option<ConnectionId>,
|
||||||
|
) -> Result<LanguagesResponse, LemmyError> {
|
||||||
|
// TODO: get an actual language list
|
||||||
|
// https://github.com/pyfisch/rust-language-tags/issues/32
|
||||||
|
let languages = vec!["en", "es"]
|
||||||
|
.iter()
|
||||||
|
.map(|l| PrimaryLanguageTag(l.to_string()))
|
||||||
|
.collect();
|
||||||
|
Ok(LanguagesResponse { languages })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub fn lemmy_context() -> Result<Vec<AnyBase>, LemmyError> {
|
||||||
"sensitive": "as:sensitive",
|
"sensitive": "as:sensitive",
|
||||||
"stickied": "as:stickied",
|
"stickied": "as:stickied",
|
||||||
"pt": "https://join.lemmy.ml#",
|
"pt": "https://join.lemmy.ml#",
|
||||||
"comments_enabled": {
|
"commentsEnabled": {
|
||||||
"type": "sc:Boolean",
|
"type": "sc:Boolean",
|
||||||
"id": "pt:commentsEnabled"
|
"id": "pt:commentsEnabled"
|
||||||
},
|
},
|
||||||
|
@ -19,6 +19,9 @@ pub fn lemmy_context() -> Result<Vec<AnyBase>, LemmyError> {
|
||||||
"type": "sc:Text",
|
"type": "sc:Text",
|
||||||
"id": "as:alsoKnownAs"
|
"id": "as:alsoKnownAs"
|
||||||
},
|
},
|
||||||
|
"languages": {
|
||||||
|
"type": "sc:Text"
|
||||||
|
},
|
||||||
}))?;
|
}))?;
|
||||||
Ok(vec![
|
Ok(vec![
|
||||||
AnyBase::from(context()),
|
AnyBase::from(context()),
|
||||||
|
|
|
@ -522,6 +522,7 @@ mod tests {
|
||||||
name: bot_post_name,
|
name: bot_post_name,
|
||||||
creator_id: inserted_bot.id,
|
creator_id: inserted_bot.id,
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
|
language: Some(PrimaryLanguageTag("en".to_string())),
|
||||||
..PostForm::default()
|
..PostForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,5 +2,5 @@ ALTER TABLE comment DROP COLUMN language;
|
||||||
ALTER TABLE post DROP COLUMN language;
|
ALTER TABLE post DROP COLUMN language;
|
||||||
ALTER TABLE private_message DROP COLUMN language;
|
ALTER TABLE private_message DROP COLUMN language;
|
||||||
|
|
||||||
DROP TABLE discussion_languages;
|
ALTER TABLE local_user DROP COLUMN discussion_languages;
|
||||||
ALTER TABLE local_user RENAME COLUMN interface_language TO lang;
|
ALTER TABLE local_user RENAME COLUMN interface_language TO lang;
|
|
@ -2,5 +2,5 @@ ALTER TABLE comment ADD COLUMN language TEXT NOT NULL;
|
||||||
ALTER TABLE post ADD COLUMN language TEXT NOT NULL;
|
ALTER TABLE post ADD COLUMN language TEXT NOT NULL;
|
||||||
ALTER TABLE private_message ADD COLUMN language TEXT NOT NULL;
|
ALTER TABLE private_message ADD COLUMN language TEXT NOT NULL;
|
||||||
|
|
||||||
CREATE TABLE discussion_languages(id INTEGER PRIMARY KEY, local_user_id INT NOT NULL, language TEXT NOT NULL);
|
ALTER TABLE local_user ADD COLUMN discussion_languages TEXT[] NOT NULL;
|
||||||
ALTER TABLE local_user RENAME COLUMN lang TO interface_language;
|
ALTER TABLE local_user RENAME COLUMN lang TO interface_language;
|
|
@ -21,7 +21,8 @@ pub fn config(cfg: &mut web::ServiceConfig, rate_limit: &RateLimit) {
|
||||||
.route("", web::put().to(route_post_crud::<EditSite>))
|
.route("", web::put().to(route_post_crud::<EditSite>))
|
||||||
.route("/transfer", web::post().to(route_post::<TransferSite>))
|
.route("/transfer", web::post().to(route_post::<TransferSite>))
|
||||||
.route("/config", web::get().to(route_get::<GetSiteConfig>))
|
.route("/config", web::get().to(route_get::<GetSiteConfig>))
|
||||||
.route("/config", web::put().to(route_post::<SaveSiteConfig>)),
|
.route("/config", web::put().to(route_post::<SaveSiteConfig>))
|
||||||
|
.route("/languages", web::get().to(route_get_crud::<GetLanguages>)),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::resource("/modlog")
|
web::resource("/modlog")
|
||||||
|
|
Loading…
Reference in a new issue