Fix loading invited users.

This commit is contained in:
Adrian Wozniak 2020-04-22 15:28:02 +02:00
parent ff0d4bb329
commit c4cc1b55d6
2 changed files with 53 additions and 8 deletions

View File

@ -15,6 +15,52 @@ insert into users (project_id, email, name, avatar_url) values (
'Mike Keningham',
'https://cdn0.iconfinder.com/data/icons/user-pictures/100/matureman1-512.png'
);
insert into invitations ( email, name, state, project_id, invited_by_id) values (
'foo1@example.com',
'Foo1',
'sent',
1,
1
), (
'foo1+revoked@example.com',
'Foo1 Revoked',
'revoked',
1,
1
), (
'foo1+accepted@example.com',
'Foo1 Accepted',
'accepted',
1,
1
), (
'foo2@example.com',
'Foo2',
'sent',
2,
2
), (
'foo2+accepted@example.com',
'Foo2 Accepted',
'accepted',
2,
2
), (
'foo2+revoked@example.com',
'Foo2 Revoked',
'revoked',
2,
2
);
insert into users (project_id, email, name) values (
2,
'foo2+accepted@example.com',
'Foo2 Accepted'
), (
1,
'foo1+accepted@example.com',
'Foo1 Accepted'
);
insert into tokens (user_id, access_token, refresh_token) values (1, uuid_generate_v4(), uuid_generate_v4() );
insert into issues(
title,
@ -57,7 +103,6 @@ insert into issues(
2,
1
);
insert into comments (user_id, issue_id, body) values (
1, 1, 'Vestibulum non neque at dui maximus porttitor fermentum consectetur eros.'
),

View File

@ -176,23 +176,23 @@ impl Handler<LoadInvitedUsers> for DbExecutor {
type Result = Result<Vec<User>, ServiceErrors>;
fn handle(&mut self, msg: LoadInvitedUsers, _ctx: &mut Self::Context) -> Self::Result {
use crate::schema::invitations::dsl as idsl;
use crate::schema::users::dsl as udsl;
use crate::schema::invitations::dsl::{email as i_email, invitations, invited_by_id};
use crate::schema::users::dsl::{email as u_email, users};
let conn = &self
.pool
.get()
.map_err(|_| ServiceErrors::DatabaseConnectionLost)?;
let query = udsl::users
.inner_join(idsl::invitations.on(idsl::email.eq(udsl::email)))
.filter(idsl::invited_by_id.eq(msg.user_id))
.select(udsl::users::all_columns());
let query = users
.inner_join(invitations.on(i_email.eq(u_email)))
.filter(invited_by_id.eq(msg.user_id))
.select(users::all_columns());
debug!("{}", diesel::debug_query::<Pg, _>(&query).to_string());
let res: Vec<User> = query
.load(conn)
.map_err(|_| ServiceErrors::DatabaseConnectionLost)?;
.map_err(|e| ServiceErrors::DatabaseQueryFailed(format!("{}", e)))?;
Ok(res)
}
}