| 14 | } |
| 15 | |
| 16 | pub async fn call<'t>(&self, tx: &mut PgTransaction<'t>) -> Result<()> { |
| 17 | let (user_id, name) = self.user_info(); |
| 18 | log::info!("completing registration for {}", name); |
| 19 | |
| 20 | log::info!("creating default org {} for {}", self.login, name); |
| 21 | let (organization_id,) = sqlx::query_as::<_, (Uuid,)>( |
| 22 | "insert into organizations |
| 23 | (login, name, public, owner_id) |
| 24 | values ($1, $2, false, $3) |
| 25 | returning id", |
| 26 | ) |
| 27 | .bind(self.login) |
| 28 | .bind(DEFAULT_ORGANIZATION_NAME) |
| 29 | .bind(user_id) |
| 30 | .fetch_one(&mut **tx) |
| 31 | .await?; |
| 32 | |
| 33 | log::info!( |
| 34 | "creating default repo {} for {}", |
| 35 | DEFAULT_REPOSITORY_NAME, |
| 36 | name |
| 37 | ); |
| 38 | let (repository_id,) = sqlx::query_as::<_, (Uuid,)>( |
| 39 | "insert into repositories |
| 40 | ( |
| 41 | organization_id, |
| 42 | name, |
| 43 | owner_id, |
| 44 | private |
| 45 | ) |
| 46 | values ( |
| 47 | $1::uuid, |
| 48 | $2, |
| 49 | $3, |
| 50 | 't', |
| 51 | ) |
| 52 | returning id", |
| 53 | ) |
| 54 | .bind(organization_id) |
| 55 | .bind(DEFAULT_REPOSITORY_NAME) |
| 56 | .bind(user_id) |
| 57 | .fetch_one(&mut **tx) |
| 58 | .await?; |
| 59 | |
| 60 | // Add permissions for personal repo |
| 61 | sqlx::query( |
| 62 | "insert into users_repositories (user_id, repository_id, can_read, can_write) |
| 63 | values ($1::uuid, $2, 't', 't') |
| 64 | on conflict do nothing", |
| 65 | ) |
| 66 | .bind(organization_id) |
| 67 | .bind(repository_id) |
| 68 | .execute(&mut **tx) |
| 69 | .await?; |
| 70 | |
| 71 | // Add permissions for wiki repo |
| 72 | sqlx::query( |
| 73 | "insert into users_repositories (user_id, repository_id, can_read, can_write) |