Format code

This commit is contained in:
Adrian Woźniak 2020-12-24 16:24:47 +01:00
parent 70ca962f8c
commit 5a7ddb03e1
31 changed files with 188 additions and 190 deletions

View File

@ -20,8 +20,8 @@ pub fn db_msg(item: TokenStream) -> TokenStream {
panic!("Expect to find keyword struct but nothing was found")
}
let _name = it
.next()
.expect("Expect to struct name but nothing was found");
.next()
.expect("Expect to struct name but nothing was found");
"".parse().unwrap()
}

View File

@ -1,7 +1,7 @@
use {
crate::{db_find, tokens::FindAccessToken},
diesel::prelude::*,
jirs_data::User,
crate::{db_find, tokens::FindAccessToken},
diesel::prelude::*,
jirs_data::User,
};
db_find! {

View File

@ -1,7 +1,7 @@
use {
crate::{db_create, db_delete, db_load, db_update},
diesel::prelude::*,
jirs_data::{Comment, CommentId, IssueId, UserId},
crate::{db_create, db_delete, db_load, db_update},
diesel::prelude::*,
jirs_data::{Comment, CommentId, IssueId, UserId},
};
db_load! {

View File

@ -1,7 +1,7 @@
use {
crate::{db_create, db_delete, db_load, db_update},
diesel::prelude::*,
jirs_data::Epic,
crate::{db_create, db_delete, db_load, db_update},
diesel::prelude::*,
jirs_data::Epic,
};
db_load! {

View File

@ -101,7 +101,7 @@ impl AcceptInvitation {
let invitation = crate::invitations::FindByBindToken {
token: self.invitation_token,
}
.execute(conn)?;
.execute(conn)?;
if invitation.state == InvitationState::Revoked {
return Err(crate::DatabaseError::Invitation(
@ -113,13 +113,13 @@ impl AcceptInvitation {
id: invitation.id,
state: InvitationState::Accepted,
}
.execute(conn)?;
.execute(conn)?;
UpdateInvitationState {
id: invitation.id,
state: InvitationState::Accepted,
}
.execute(conn)?;
.execute(conn)?;
match {
Register {
@ -128,7 +128,7 @@ impl AcceptInvitation {
project_id: Some(invitation.project_id),
role: UserRole::User,
}
.execute(conn)
.execute(conn)
} {
Ok(_) => (),
Err(crate::DatabaseError::User(crate::UserError::InvalidPair(..))) => (),
@ -139,7 +139,7 @@ impl AcceptInvitation {
name: invitation.name.clone(),
email: invitation.email.clone(),
}
.execute(conn)?;
.execute(conn)?;
CreateBindToken { user_id: user.id }.execute(conn)?;
crate::user_projects::CreateUserProject {
@ -149,7 +149,7 @@ impl AcceptInvitation {
is_default: false,
role: invitation.role,
}
.execute(conn)?;
.execute(conn)?;
crate::tokens::FindUserId { user_id: user.id }.execute(conn)
})

View File

@ -1,7 +1,7 @@
use {
crate::{db_create, db_delete, db_load, db_load_field},
diesel::{expression::dsl::not, prelude::*},
jirs_data::{IssueAssignee, IssueId, UserId},
crate::{db_create, db_delete, db_load, db_load_field},
diesel::{expression::dsl::not, prelude::*},
jirs_data::{IssueAssignee, IssueId, UserId},
};
db_create! {

View File

@ -1,7 +1,7 @@
use {
crate::{db_create, db_delete, db_load, db_update},
diesel::prelude::*,
jirs_data::{IssueStatus, IssueStatusId, Position, ProjectId, TitleString},
crate::{db_create, db_delete, db_load, db_update},
diesel::prelude::*,
jirs_data::{IssueStatus, IssueStatusId, Position, ProjectId, TitleString},
};
db_load! {

View File

@ -1,10 +1,10 @@
use {
crate::{
db_create_with_conn, db_delete_with_conn, db_find, db_load, db_update_with_conn,
models::Issue,
},
diesel::{expression::sql_literal::sql, prelude::*},
jirs_data::{IssueId, IssuePriority, IssueStatusId, IssueType, ProjectId, UserId},
crate::{
db_create_with_conn, db_delete_with_conn, db_find, db_load, db_update_with_conn,
models::Issue,
},
diesel::{expression::sql_literal::sql, prelude::*},
jirs_data::{IssueId, IssuePriority, IssueStatusId, IssueType, ProjectId, UserId},
};
db_find! {
@ -91,13 +91,13 @@ db_delete_with_conn! {
}
mod inner {
use {
crate::{db_create, models::Issue},
diesel::prelude::*,
jirs_data::{IssuePriority, IssueStatusId, IssueType},
};
use {
crate::{db_create, models::Issue},
diesel::prelude::*,
jirs_data::{IssuePriority, IssueStatusId, IssueType},
};
db_create! {
db_create! {
CreateIssue,
msg => issues => diesel::insert_into(issues)
.values((

View File

@ -1,10 +1,10 @@
use {
crate::{
db_create_with_conn, db_delete, db_load,
users::{FindUser, LookupUser},
},
diesel::prelude::*,
jirs_data::{BindToken, Message, MessageId, MessageType, User, UserId},
crate::{
db_create_with_conn, db_delete, db_load,
users::{FindUser, LookupUser},
},
diesel::prelude::*,
jirs_data::{BindToken, Message, MessageId, MessageType, User, UserId},
};
db_load! {

View File

@ -1,7 +1,7 @@
use {
crate::{db_create_with_conn, db_find, db_load, db_update},
diesel::prelude::*,
jirs_data::{NameString, Project, ProjectCategory, ProjectId, TimeTracking, UserId},
crate::{db_create_with_conn, db_find, db_load, db_update},
diesel::prelude::*,
jirs_data::{NameString, Project, ProjectCategory, ProjectId, TimeTracking, UserId},
};
db_find! {
@ -12,13 +12,13 @@ db_find! {
}
mod inner {
use {
crate::db_create,
diesel::prelude::*,
jirs_data::{NameString, Project, ProjectCategory, TimeTracking},
};
use {
crate::db_create,
diesel::prelude::*,
jirs_data::{NameString, Project, ProjectCategory, TimeTracking},
};
db_create! {
db_create! {
CreateProject,
msg => projects => diesel::insert_into(projects)
.values((

View File

@ -1,7 +1,7 @@
use {
crate::{db_create, db_find, db_update_with_conn},
diesel::prelude::*,
jirs_data::{Token, UserId},
crate::{db_create, db_find, db_update_with_conn},
diesel::prelude::*,
jirs_data::{Token, UserId},
};
db_find! {

View File

@ -1,7 +1,7 @@
use {
crate::{db_create, db_delete_with_conn, db_find, db_load, db_update_with_conn},
diesel::prelude::*,
jirs_data::{ProjectId, UserId, UserProject, UserProjectId, UserRole},
crate::{db_create, db_delete_with_conn, db_find, db_load, db_update_with_conn},
diesel::prelude::*,
jirs_data::{ProjectId, UserId, UserProject, UserProjectId, UserRole},
};
db_find! {
@ -27,13 +27,13 @@ db_load! {
}
mod inner {
use {
crate::db_update,
diesel::prelude::*,
jirs_data::{UserId, UserProject, UserProjectId},
};
use {
crate::db_update,
diesel::prelude::*,
jirs_data::{UserId, UserProject, UserProjectId},
};
db_update! {
db_update! {
ChangeProjectIsCurrent,
msg => user_projects => {
match msg.id {

View File

@ -1,10 +1,10 @@
use {
crate::{
db_create, db_create_with_conn, db_find, db_load, db_update, projects::CreateProject, q,
user_projects::CreateUserProject, DbPooledConn,
},
diesel::prelude::*,
jirs_data::{EmailString, IssueId, ProjectId, User, UserId, UserRole, UsernameString},
crate::{
db_create, db_create_with_conn, db_find, db_load, db_update, projects::CreateProject, q,
user_projects::CreateUserProject, DbPooledConn,
},
diesel::prelude::*,
jirs_data::{EmailString, IssueId, ProjectId, User, UserId, UserRole, UsernameString},
};
db_find! {
@ -205,7 +205,7 @@ mod tests {
use jirs_data::{Project, ProjectCategory};
use crate::build_pool;
use crate::build_pool;
use super::*;

View File

@ -32,13 +32,13 @@ fn mail_client(config: &jirs_config::mail::Configuration) -> lettre::SmtpClient
let mail_host = config.host.as_str();
lettre::SmtpClient::new_simple(mail_host)
.expect("Failed to init SMTP client")
.credentials(lettre::smtp::authentication::Credentials::new(
mail_user.to_string(),
mail_pass.to_string(),
))
.connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited)
.smtp_utf8(true)
.expect("Failed to init SMTP client")
.credentials(lettre::smtp::authentication::Credentials::new(
mail_user.to_string(),
mail_pass.to_string(),
))
.connection_reuse(lettre::smtp::ConnectionReuseParameters::ReuseUnlimited)
.smtp_utf8(true)
}
fn mail_transport(config: &jirs_config::mail::Configuration) -> MailTransport {

View File

@ -46,7 +46,7 @@ pub async fn upload(
disposition,
fs.clone(),
)
.await?,
.await?,
);
}
_ => continue,

View File

@ -57,13 +57,13 @@ impl Into<HttpResponse> for ServiceError {
errors: vec![error.to_str().to_string()],
}),
ServiceError::Highlight(HighlightError::UnknownTheme) => HttpResponse::BadRequest()
.json(ErrorResponse::single(
"Code highlight Failed. Unexpected theme",
)),
.json(ErrorResponse::single(
"Code highlight Failed. Unexpected theme",
)),
ServiceError::Highlight(HighlightError::UnknownLanguage) => HttpResponse::BadRequest()
.json(ErrorResponse::single(
"Can't highlight in given language. It's unknown",
)),
.json(ErrorResponse::single(
"Can't highlight in given language. It's unknown",
)),
ServiceError::Highlight(HighlightError::ResultUnserializable) => {
HttpResponse::BadRequest().json(ErrorResponse::single(
"Highlight succeed but result can't be send",

View File

@ -76,11 +76,11 @@ pub(crate) async fn handle_image(
{
use filesystem_actor::RemoveTmpFile;
let _ = fs
.send(RemoveTmpFile {
file_name: format!("{}-{}", user_id, filename),
})
.await
.ok();
.send(RemoveTmpFile {
file_name: format!("{}-{}", user_id, filename),
})
.await
.ok();
};
Ok(new_link.unwrap_or_default())
}
@ -113,11 +113,11 @@ pub(crate) async fn handle_image(
{
use filesystem_actor::RemoveTmpFile;
let _ = fs
.send(RemoveTmpFile {
file_name: format!("{}-{}", user_id, filename),
})
.await
.ok();
.send(RemoveTmpFile {
file_name: format!("{}-{}", user_id, filename),
})
.await
.ok();
};
Ok(new_link.unwrap_or_default())
}
@ -183,11 +183,11 @@ async fn local_storage_write(
let fs_config = jirs_config::fs::Configuration::read();
let _ = fs
.send(filesystem_actor::CreateFile {
source: receiver,
file_name: system_file_name.clone(),
})
.await;
.send(filesystem_actor::CreateFile {
source: receiver,
file_name: system_file_name.clone(),
})
.await;
Some(format!(
"{proto}://{bind}{port}{client_path}/{user_id}-{filename}",

View File

@ -3,11 +3,11 @@ extern crate log;
pub use errors::*;
use {
crate::middleware::authorize::token_from_headers,
actix::Addr,
actix_web::{web::Data, HttpRequest, HttpResponse},
database_actor::{authorize_user::AuthorizeUser, DbExecutor},
jirs_data::User,
crate::middleware::authorize::token_from_headers,
actix::Addr,
actix_web::{web::Data, HttpRequest, HttpResponse},
database_actor::{authorize_user::AuthorizeUser, DbExecutor},
jirs_data::User,
};
pub mod avatar;
@ -16,21 +16,21 @@ pub mod handlers;
pub mod middleware;
pub async fn user_from_request(
req: HttpRequest,
db: &Data<Addr<DbExecutor>>,
req: HttpRequest,
db: &Data<Addr<DbExecutor>>,
) -> Result<User, HttpResponse> {
let token = match token_from_headers(req.headers()) {
Ok(uuid) => uuid,
_ => return Err(ServiceError::Unauthorized.into_http_response()),
};
match db
.send(AuthorizeUser {
access_token: token,
})
.await
{
Ok(Ok(user)) => Ok(user),
Ok(Err(_e)) => Err(HttpResponse::InternalServerError().body("Critical database error")),
_ => Err(ServiceError::Unauthorized.into_http_response()),
}
let token = match token_from_headers(req.headers()) {
Ok(uuid) => uuid,
_ => return Err(ServiceError::Unauthorized.into_http_response()),
};
match db
.send(AuthorizeUser {
access_token: token,
})
.await
{
Ok(Ok(user)) => Ok(user),
Ok(Err(_e)) => Err(HttpResponse::InternalServerError().body("Critical database error")),
_ => Err(ServiceError::Unauthorized.into_http_response()),
}
}

View File

@ -100,11 +100,11 @@ fn check_token(
token_from_headers(headers).and_then(|access_token| {
use database_actor::authorize_user::AuthorizeUser;
let conn = pool
.get()
.map_err(|_| crate::errors::ServiceError::DatabaseConnectionLost)?;
.get()
.map_err(|_| crate::errors::ServiceError::DatabaseConnectionLost)?;
AuthorizeUser { access_token }
.execute(&conn)
.map_err(|_| crate::errors::ServiceError::Unauthorized)
.execute(&conn)
.map_err(|_| crate::errors::ServiceError::Unauthorized)
})
}

View File

@ -10,7 +10,7 @@ impl WsHandler<LoadEpics> for WebSocketActor {
fn handle_msg(&mut self, _msg: LoadEpics, _ctx: &mut Self::Context) -> WsResult {
let project_id = self.require_user_project()?.project_id;
let epics =
crate::query_db_or_print!(self, database_actor::epics::LoadEpics { project_id });
crate::query_db_or_print!(self, database_actor::epics::LoadEpics { project_id });
Ok(Some(WsMsg::EpicsLoaded(epics)))
}
}

View File

@ -46,23 +46,23 @@ impl WsHandler<CreateInvitation> for WebSocketActor {
let CreateInvitation { email, name, role } = msg;
let invitation =
match block_on(self.db.send(database_actor::invitations::CreateInvitation {
user_id,
project_id,
email: email.clone(),
name: name.clone(),
role,
})) {
Ok(Ok(invitation)) => invitation,
Ok(Err(e)) => {
error!("{:?}", e);
return Ok(Some(WsMsg::InvitationSendFailure));
}
Err(e) => {
error!("{}", e);
return Ok(Some(WsMsg::InvitationSendFailure));
}
};
match block_on(self.db.send(database_actor::invitations::CreateInvitation {
user_id,
project_id,
email: email.clone(),
name: name.clone(),
role,
})) {
Ok(Ok(invitation)) => invitation,
Ok(Err(e)) => {
error!("{:?}", e);
return Ok(Some(WsMsg::InvitationSendFailure));
}
Err(e) => {
error!("{}", e);
return Ok(Some(WsMsg::InvitationSendFailure));
}
};
match block_on(self.mail.send(mail_actor::invite::Invite {
bind_token: invitation.bind_token,
email: invitation.email,
@ -168,13 +168,13 @@ impl WsHandler<AcceptInvitation> for WebSocketActor {
for message in block_on(
self.db
.send(database_actor::messages::LookupMessagesByToken {
token: invitation_token,
user_id: token.user_id,
}),
.send(database_actor::messages::LookupMessagesByToken {
token: invitation_token,
user_id: token.user_id,
}),
)
.unwrap_or_else(|_| Ok(vec![]))
.unwrap_or_default()
.unwrap_or_else(|_| Ok(vec![]))
.unwrap_or_default()
{
match block_on(self.db.send(database_actor::messages::MarkMessageSeen {
user_id: token.user_id,

View File

@ -151,7 +151,7 @@ impl WsHandler<DeleteIssue> for WebSocketActor {
self.require_user()?;
let m = match block_on(
self.db
.send(database_actor::issues::DeleteIssue { issue_id: msg.id }),
.send(database_actor::issues::DeleteIssue { issue_id: msg.id }),
) {
Ok(Ok(n)) => Some(WsMsg::IssueDeleted(msg.id, n)),
Ok(Err(e)) => {

View File

@ -1,6 +1,6 @@
pub use {
auth::*, comments::*, epics::*, invitations::*, issue_statuses::*, issues::*, messages::*,
projects::*, user_projects::*, users::*,
auth::*, comments::*, epics::*, invitations::*, issue_statuses::*, issues::*, messages::*,
projects::*, user_projects::*, users::*,
};
pub mod auth;

View File

@ -32,7 +32,7 @@ impl WsHandler<UpdateProjectPayload> for WebSocketActor {
};
let projects = match block_on(
self.db
.send(database_actor::projects::LoadProjects { user_id: *user_id }),
.send(database_actor::projects::LoadProjects { user_id: *user_id }),
) {
Ok(Ok(projects)) => projects,
Ok(Err(e)) => {

View File

@ -67,7 +67,7 @@ impl WsHandler<LoadInvitedUsers> for WebSocketActor {
let users = match block_on(
self.db
.send(database_actor::users::LoadInvitedUsers { user_id }),
.send(database_actor::users::LoadInvitedUsers { user_id }),
) {
Ok(Ok(users)) => users,
_ => return Ok(None),
@ -123,11 +123,11 @@ impl WsHandler<RemoveInvitedUser> for WebSocketActor {
} = self.require_user_project()?.clone();
match block_on(
self.db
.send(database_actor::user_projects::RemoveInvitedUser {
invited_id,
inviter_id,
project_id,
}),
.send(database_actor::user_projects::RemoveInvitedUser {
invited_id,
inviter_id,
project_id,
}),
) {
Ok(Ok(_users)) => Ok(Some(WsMsg::InvitedUserRemoveSuccess(invited_id))),
Ok(Err(e)) => {

View File

@ -44,9 +44,9 @@ impl actix::Handler<InnerMsg> for WsServer {
match msg {
InnerMsg::Join(project_id, user_id, recipient) => {
let v = self
.sessions
.entry(user_id)
.or_insert_with(Default::default);
.sessions
.entry(user_id)
.or_insert_with(Default::default);
v.push(recipient);
self.ensure_room(project_id);

View File

@ -26,9 +26,9 @@ pub fn update(msg: &Msg, model: &mut Model, orders: &mut impl Orders<Msg>) {
);
}
Msg::WebSocketChange(WebSocketChanged::WsMsg(WsMsg::IssueStatusDeleted(
_id,
_n_deleted,
))) => {
_id,
_n_deleted,
))) => {
orders.skip().send_msg(Msg::ModalDropped);
}
_ => (),

View File

@ -46,17 +46,17 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
}
}
Msg::WebSocketChange(WebSocketChanged::WsMsg(WsMsg::IssueDeleted(id, count)))
if count > 0 =>
{
let mut old: Vec<Issue> = vec![];
std::mem::swap(&mut old, &mut model.issues);
for is in old {
if is.id != id {
model.issues.push(is);
}
if count > 0 =>
{
let mut old: Vec<Issue> = vec![];
std::mem::swap(&mut old, &mut model.issues);
for is in old {
if is.id != id {
model.issues.push(is);
}
orders.skip().send_msg(Msg::ModalDropped);
}
orders.skip().send_msg(Msg::ModalDropped);
}
Msg::StyledSelectChanged(
FieldId::EditIssueModal(EditIssueModalSection::Issue(IssueFieldId::Type)),
StyledSelectChanged::Text(text),

View File

@ -160,8 +160,8 @@ pub fn update(msg: &WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
}
}
model
.issue_statuses
.sort_by(|a, b| a.position.cmp(&b.position));
.issue_statuses
.sort_by(|a, b| a.position.cmp(&b.position));
}
WsMsg::IssueStatusDeleted(dropped_id, _count) => {
let mut old = vec![];
@ -172,8 +172,8 @@ pub fn update(msg: &WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
}
}
model
.issue_statuses
.sort_by(|a, b| a.position.cmp(&b.position));
.issue_statuses
.sort_by(|a, b| a.position.cmp(&b.position));
}
WsMsg::IssueDeleted(id, _count) => {
let mut old = vec![];
@ -185,7 +185,7 @@ pub fn update(msg: &WsMsg, model: &mut Model, orders: &mut impl Orders<Msg>) {
model.issue_statuses.push(is);
}
model
.issue_statuses
.issue_statuses
.sort_by(|a, b| a.position.cmp(&b.position));
}
// users

View File

@ -36,7 +36,7 @@ async fn main() -> Result<(), String> {
highlight_actor::HighlightActor::default,
);
#[cfg(feature = "local-storage")]
let fs_addr = actix::SyncArbiter::start(
let fs_addr = actix::SyncArbiter::start(
jirs_config::fs::Configuration::read().concurrency,
filesystem_actor::FileSystemExecutor::default,
);
@ -48,21 +48,19 @@ async fn main() -> Result<(), String> {
// data step
let app = app
.data(ws_server.clone())
.data(db_addr.clone())
.data(mail_addr.clone())
.data(hi_addr.clone())
.data(database_actor::build_pool());
featured! { app, "local-storage", app.data(fs_addr.clone()) }
;
.data(ws_server.clone())
.data(db_addr.clone())
.data(mail_addr.clone())
.data(hi_addr.clone())
.data(database_actor::build_pool());
featured! { app, "local-storage", app.data(fs_addr.clone()) };
// services step
let app = app
.service(websocket_actor::index)
.service(actix_web::web::scope("/avatar").service(web_actor::avatar::upload));
.service(websocket_actor::index)
.service(actix_web::web::scope("/avatar").service(web_actor::avatar::upload));
featured! { app, "local-storage", app.service(filesystem_actor::service()) }
;
featured! { app, "local-storage", app.service(filesystem_actor::service()) };
app
})
.workers(web_config.concurrency)

View File

@ -12,7 +12,7 @@ impl Default for Configuration {
"postgres://postgres@localhost:5432/jirs_test".to_string()
} else {
std::env::var("DATABASE_URL")
.unwrap_or_else(|_| "postgres://postgres@localhost:5432/jirs".to_string())
.unwrap_or_else(|_| "postgres://postgres@localhost:5432/jirs".to_string())
};
Self {
concurrency: 2,