]> Untitled Git - lemmy.git/blob - crates/api_common/src/site.rs
Add option to limit community creation to admins only (fixes #1586) (#1587)
[lemmy.git] / crates / api_common / src / site.rs
1 use lemmy_db_schema::{CommunityId, PersonId};
2 use lemmy_db_views::{
3   comment_view::CommentView,
4   local_user_view::LocalUserSettingsView,
5   post_view::PostView,
6   site_view::SiteView,
7 };
8 use lemmy_db_views_actor::{community_view::CommunityView, person_view::PersonViewSafe};
9 use lemmy_db_views_moderator::{
10   mod_add_community_view::ModAddCommunityView,
11   mod_add_view::ModAddView,
12   mod_ban_from_community_view::ModBanFromCommunityView,
13   mod_ban_view::ModBanView,
14   mod_lock_post_view::ModLockPostView,
15   mod_remove_comment_view::ModRemoveCommentView,
16   mod_remove_community_view::ModRemoveCommunityView,
17   mod_remove_post_view::ModRemovePostView,
18   mod_sticky_post_view::ModStickyPostView,
19 };
20 use serde::{Deserialize, Serialize};
21
22 #[derive(Deserialize, Debug)]
23 pub struct Search {
24   pub q: String,
25   pub type_: String,
26   pub community_id: Option<CommunityId>,
27   pub community_name: Option<String>,
28   pub sort: String,
29   pub page: Option<i64>,
30   pub limit: Option<i64>,
31   pub auth: Option<String>,
32 }
33
34 #[derive(Serialize, Debug)]
35 pub struct SearchResponse {
36   pub type_: String,
37   pub comments: Vec<CommentView>,
38   pub posts: Vec<PostView>,
39   pub communities: Vec<CommunityView>,
40   pub users: Vec<PersonViewSafe>,
41 }
42
43 #[derive(Deserialize)]
44 pub struct GetModlog {
45   pub mod_person_id: Option<PersonId>,
46   pub community_id: Option<CommunityId>,
47   pub page: Option<i64>,
48   pub limit: Option<i64>,
49 }
50
51 #[derive(Serialize)]
52 pub struct GetModlogResponse {
53   pub removed_posts: Vec<ModRemovePostView>,
54   pub locked_posts: Vec<ModLockPostView>,
55   pub stickied_posts: Vec<ModStickyPostView>,
56   pub removed_comments: Vec<ModRemoveCommentView>,
57   pub removed_communities: Vec<ModRemoveCommunityView>,
58   pub banned_from_community: Vec<ModBanFromCommunityView>,
59   pub banned: Vec<ModBanView>,
60   pub added_to_community: Vec<ModAddCommunityView>,
61   pub added: Vec<ModAddView>,
62 }
63
64 #[derive(Deserialize)]
65 pub struct CreateSite {
66   pub name: String,
67   pub sidebar: Option<String>,
68   pub description: Option<String>,
69   pub icon: Option<String>,
70   pub banner: Option<String>,
71   pub enable_downvotes: bool,
72   pub open_registration: bool,
73   pub enable_nsfw: bool,
74   pub community_creation_admin_only: bool,
75   pub auth: String,
76 }
77
78 #[derive(Deserialize)]
79 pub struct EditSite {
80   pub name: String,
81   pub sidebar: Option<String>,
82   pub description: Option<String>,
83   pub icon: Option<String>,
84   pub banner: Option<String>,
85   pub enable_downvotes: bool,
86   pub open_registration: bool,
87   pub enable_nsfw: bool,
88   pub community_creation_admin_only: Option<bool>,
89   pub auth: String,
90 }
91
92 #[derive(Deserialize)]
93 pub struct GetSite {
94   pub auth: Option<String>,
95 }
96
97 #[derive(Serialize, Clone)]
98 pub struct SiteResponse {
99   pub site_view: SiteView,
100 }
101
102 #[derive(Serialize)]
103 pub struct GetSiteResponse {
104   pub site_view: Option<SiteView>, // Because the site might not be set up yet
105   pub admins: Vec<PersonViewSafe>,
106   pub banned: Vec<PersonViewSafe>,
107   pub online: usize,
108   pub version: String,
109   pub my_user: Option<LocalUserSettingsView>,
110   pub federated_instances: Option<FederatedInstances>, // Federation may be disabled
111 }
112
113 #[derive(Deserialize)]
114 pub struct TransferSite {
115   pub person_id: PersonId,
116   pub auth: String,
117 }
118
119 #[derive(Deserialize)]
120 pub struct GetSiteConfig {
121   pub auth: String,
122 }
123
124 #[derive(Serialize)]
125 pub struct GetSiteConfigResponse {
126   pub config_hjson: String,
127 }
128
129 #[derive(Deserialize)]
130 pub struct SaveSiteConfig {
131   pub config_hjson: String,
132   pub auth: String,
133 }
134
135 #[derive(Serialize)]
136 pub struct FederatedInstances {
137   pub linked: Vec<String>,
138   pub allowed: Option<Vec<String>>,
139   pub blocked: Option<Vec<String>>,
140 }