contributors.rs

 1use super::*;
 2
 3impl Database {
 4    /// Retrieves the GitHub logins of all users who have signed the CLA.
 5    pub async fn get_contributors(&self) -> Result<Vec<String>> {
 6        self.transaction(|tx| async move {
 7            #[derive(Copy, Clone, Debug, EnumIter, DeriveColumn)]
 8            enum QueryGithubLogin {
 9                GithubLogin,
10            }
11
12            Ok(contributor::Entity::find()
13                .inner_join(user::Entity)
14                .order_by_asc(contributor::Column::SignedAt)
15                .select_only()
16                .column(user::Column::GithubLogin)
17                .into_values::<_, QueryGithubLogin>()
18                .all(&*tx)
19                .await?)
20        })
21        .await
22    }
23
24    /// Records that a given user has signed the CLA.
25    pub async fn add_contributor(
26        &self,
27        github_login: &str,
28        github_user_id: i32,
29        github_email: Option<&str>,
30        github_name: Option<&str>,
31        github_user_created_at: DateTimeUtc,
32        initial_channel_id: Option<ChannelId>,
33    ) -> Result<()> {
34        self.transaction(|tx| async move {
35            let user = self
36                .update_or_create_user_by_github_account_tx(
37                    github_login,
38                    github_user_id,
39                    github_email,
40                    github_name,
41                    github_user_created_at.naive_utc(),
42                    initial_channel_id,
43                    &tx,
44                )
45                .await?;
46
47            contributor::Entity::insert(contributor::ActiveModel {
48                user_id: ActiveValue::Set(user.id),
49                signed_at: ActiveValue::NotSet,
50            })
51            .on_conflict(
52                OnConflict::column(contributor::Column::UserId)
53                    .do_nothing()
54                    .to_owned(),
55            )
56            .exec_without_returning(&*tx)
57            .await?;
58            Ok(())
59        })
60        .await
61    }
62}