diff options
author | Felix <me@nutomic.com> | 2020-01-14 16:26:19 +0100 |
---|---|---|
committer | Felix <me@nutomic.com> | 2020-01-14 16:30:54 +0100 |
commit | eaf548b5db326addee318bcc2c7c742e4b79b6fa (patch) | |
tree | febdc483976b5e3d38db4c68cfadd57ce89b3f61 /server/src/api/community.rs | |
parent | 35489a706bdd48bdb840a4ac13986214c456d6c9 (diff) | |
parent | b300db475cbca846aea89800ecaa8661c59fd70b (diff) |
Merge branch 'master' into federation
Diffstat (limited to 'server/src/api/community.rs')
-rw-r--r-- | server/src/api/community.rs | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/server/src/api/community.rs b/server/src/api/community.rs index 2edaa0b2..1854dd14 100644 --- a/server/src/api/community.rs +++ b/server/src/api/community.rs @@ -1,4 +1,5 @@ use super::*; +use diesel::PgConnection; use std::str::FromStr; #[derive(Serialize, Deserialize)] @@ -118,9 +119,8 @@ pub struct TransferCommunity { } impl Perform<GetCommunityResponse> for Oper<GetCommunity> { - fn perform(&self) -> Result<GetCommunityResponse, Error> { + fn perform(&self, conn: &PgConnection) -> Result<GetCommunityResponse, Error> { let data: &GetCommunity = &self.data; - let conn = establish_connection(); let user_id: Option<i32> = match &data.auth { Some(auth) => match Claims::decode(&auth) { @@ -173,9 +173,8 @@ impl Perform<GetCommunityResponse> for Oper<GetCommunity> { } impl Perform<CommunityResponse> for Oper<CreateCommunity> { - fn perform(&self) -> Result<CommunityResponse, Error> { + fn perform(&self, conn: &PgConnection) -> Result<CommunityResponse, Error> { let data: &CreateCommunity = &self.data; - let conn = establish_connection(); let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, @@ -248,15 +247,13 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> { } impl Perform<CommunityResponse> for Oper<EditCommunity> { - fn perform(&self) -> Result<CommunityResponse, Error> { + fn perform(&self, conn: &PgConnection) -> Result<CommunityResponse, Error> { let data: &EditCommunity = &self.data; if has_slurs(&data.name) || has_slurs(&data.title) { return Err(APIError::err(&self.op, "no_slurs").into()); } - let conn = establish_connection(); - let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, Err(_e) => return Err(APIError::err(&self.op, "not_logged_in").into()), @@ -325,9 +322,8 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> { } impl Perform<ListCommunitiesResponse> for Oper<ListCommunities> { - fn perform(&self) -> Result<ListCommunitiesResponse, Error> { + fn perform(&self, conn: &PgConnection) -> Result<ListCommunitiesResponse, Error> { let data: &ListCommunities = &self.data; - let conn = establish_connection(); let user_claims: Option<Claims> = match &data.auth { Some(auth) => match Claims::decode(&auth) { @@ -366,9 +362,8 @@ impl Perform<ListCommunitiesResponse> for Oper<ListCommunities> { } impl Perform<CommunityResponse> for Oper<FollowCommunity> { - fn perform(&self) -> Result<CommunityResponse, Error> { + fn perform(&self, conn: &PgConnection) -> Result<CommunityResponse, Error> { let data: &FollowCommunity = &self.data; - let conn = establish_connection(); let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, @@ -404,9 +399,8 @@ impl Perform<CommunityResponse> for Oper<FollowCommunity> { } impl Perform<GetFollowedCommunitiesResponse> for Oper<GetFollowedCommunities> { - fn perform(&self) -> Result<GetFollowedCommunitiesResponse, Error> { + fn perform(&self, conn: &PgConnection) -> Result<GetFollowedCommunitiesResponse, Error> { let data: &GetFollowedCommunities = &self.data; - let conn = establish_connection(); let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, @@ -430,9 +424,8 @@ impl Perform<GetFollowedCommunitiesResponse> for Oper<GetFollowedCommunities> { } impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> { - fn perform(&self) -> Result<BanFromCommunityResponse, Error> { + fn perform(&self, conn: &PgConnection) -> Result<BanFromCommunityResponse, Error> { let data: &BanFromCommunity = &self.data; - let conn = establish_connection(); let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, @@ -485,9 +478,8 @@ impl Perform<BanFromCommunityResponse> for Oper<BanFromCommunity> { } impl Perform<AddModToCommunityResponse> for Oper<AddModToCommunity> { - fn perform(&self) -> Result<AddModToCommunityResponse, Error> { + fn perform(&self, conn: &PgConnection) -> Result<AddModToCommunityResponse, Error> { let data: &AddModToCommunity = &self.data; - let conn = establish_connection(); let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, @@ -536,9 +528,8 @@ impl Perform<AddModToCommunityResponse> for Oper<AddModToCommunity> { } impl Perform<GetCommunityResponse> for Oper<TransferCommunity> { - fn perform(&self) -> Result<GetCommunityResponse, Error> { + fn perform(&self, conn: &PgConnection) -> Result<GetCommunityResponse, Error> { let data: &TransferCommunity = &self.data; - let conn = establish_connection(); let claims = match Claims::decode(&data.auth) { Ok(claims) => claims.claims, |