From dd0d546c318fedc6d6c6a14598e9d8466f8fc814 Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Tue, 12 Jul 2022 10:19:56 -0500 Subject: [PATCH 1/9] Store materials link on employees --- .../down.sql | 1 + .../up.sql | 1 + cio/src/configs.rs | 23 +++++++++++++++++++ cio/src/schema.rs | 1 + 4 files changed, 26 insertions(+) create mode 100644 cio/migrations/2022-07-12-150519_add_materials_to_employees/down.sql create mode 100644 cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql diff --git a/cio/migrations/2022-07-12-150519_add_materials_to_employees/down.sql b/cio/migrations/2022-07-12-150519_add_materials_to_employees/down.sql new file mode 100644 index 000000000..e661484fc --- /dev/null +++ b/cio/migrations/2022-07-12-150519_add_materials_to_employees/down.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP COLUMN materials; \ No newline at end of file diff --git a/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql b/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql new file mode 100644 index 000000000..55a02608e --- /dev/null +++ b/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN materials VARCHAR NOT NULL ''; \ No newline at end of file diff --git a/cio/src/configs.rs b/cio/src/configs.rs index 1c7e56dcd..2f7bf399d 100644 --- a/cio/src/configs.rs +++ b/cio/src/configs.rs @@ -277,6 +277,9 @@ pub struct UserConfig { #[serde(default, skip_serializing_if = "Vec::is_empty")] pub public_ssh_keys: Vec, + #[serde(default, skip_serializing_if = "String::is_empty")] + pub materials: String, + #[serde(default, rename = "type", skip_serializing_if = "String::is_empty")] pub typev: String, @@ -829,6 +832,24 @@ impl UserConfig { } } + // If the user does not yet have a materials url, attempt to look it up from our applicant + // data based on the recovery email. This is performed when a user joins the + // organization and their record is first populated. If these do not match, then materials + // urls will need to be manually assigned + pub async fn populate_materials(&mut self, db: &Database) { + if self.materials.is_empty() { + if let Ok(applicant) = applicants::dsl::applicants + .filter(applicants::dsl::email.eq(self.recovery_email.to_string())) + .first_async::(db.pool()) + .await + { + self.materials = applicant.materials; + } else { + log::info!("Unable to find matching applicant when attempting to assign materials to employee {}", self.id); + } + } + } + pub fn populate_type(&mut self) { // TODO: make this an enum. self.typev = "full-time".to_string(); @@ -894,6 +915,8 @@ impl UserConfig { self.populate_start_date(db).await; + self.populate_materials(db).await; + // Create the link to the manager. if !self.manager.is_empty() { self.link_to_manager = vec![self.manager.to_string()]; diff --git a/cio/src/schema.rs b/cio/src/schema.rs index 60160f2ee..02d8fb7c8 100644 --- a/cio/src/schema.rs +++ b/cio/src/schema.rs @@ -908,6 +908,7 @@ table! { start_date -> Date, birthday -> Date, public_ssh_keys -> Array, + materials -> Varchar, typev -> Varchar, google_anniversary_event_id -> Varchar, email -> Varchar, From b535f526991f1b698f5032f5f6901c346dfd1dfa Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Tue, 12 Jul 2022 10:44:04 -0500 Subject: [PATCH 2/9] Lookup materials directly from employee record instead of crossing over to applicants --- cio/src/configs.rs | 3 ++- cio/src/interviews.rs | 23 ++++------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/cio/src/configs.rs b/cio/src/configs.rs index 2f7bf399d..7483089bb 100644 --- a/cio/src/configs.rs +++ b/cio/src/configs.rs @@ -845,7 +845,8 @@ impl UserConfig { { self.materials = applicant.materials; } else { - log::info!("Unable to find matching applicant when attempting to assign materials to employee {}", self.id); + // TODO: Change this so we are not logging usernames + log::info!("Unable to find matching applicant when attempting to assign materials to employee {}", self.username); } } } diff --git a/cio/src/interviews.rs b/cio/src/interviews.rs index 2ab9c016f..56a114826 100644 --- a/cio/src/interviews.rs +++ b/cio/src/interviews.rs @@ -344,28 +344,13 @@ pub async fn compile_packets(db: &Database, company: &Company) -> Result<()> { continue; } - // Get their application materials. - let mut materials_url = "".to_string(); - if let Ok(a) = applicants::dsl::applicants - .filter(applicants::dsl::email.eq(employee.recovery_email.to_string())) - .first_async::(db.pool()) - .await - { - materials_url = a.materials; - } - - if materials_url.is_empty() { - if employee.username == "ben.leonard" { - // Add Ben's materials. - materials_url = "https://drive.google.com/open?id=1bOHalcpSyXwaxr4E-_2LeT06HGXQCW0n".to_string(); - } else { - info!("could not find materials for email {}", employee.recovery_email); - continue; - } + if employee.materials.is_empty() { + info!("could not find materials for employee {}", employee.id); + continue; } // Let's download the contents of their materials locally. - download_materials_as_pdf(&drive_client, &materials_url, &employee.username) + download_materials_as_pdf(&drive_client, &employee.materials, &employee.username) .await .map_err(|err| { log::error!( From c42516193bf04bca7ff995052061374933f6afc3 Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Tue, 12 Jul 2022 23:21:24 -0500 Subject: [PATCH 3/9] Fmt --- cio/src/configs.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cio/src/configs.rs b/cio/src/configs.rs index 7483089bb..9a8e22967 100644 --- a/cio/src/configs.rs +++ b/cio/src/configs.rs @@ -846,7 +846,10 @@ impl UserConfig { self.materials = applicant.materials; } else { // TODO: Change this so we are not logging usernames - log::info!("Unable to find matching applicant when attempting to assign materials to employee {}", self.username); + log::info!( + "Unable to find matching applicant when attempting to assign materials to employee {}", + self.username + ); } } } From 0284ba3f4b125288636302a58d235cb51f320010 Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 13 Jul 2022 10:21:45 -0500 Subject: [PATCH 4/9] Fix log error --- cio/src/configs.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cio/src/configs.rs b/cio/src/configs.rs index 9a8e22967..65b7ae887 100644 --- a/cio/src/configs.rs +++ b/cio/src/configs.rs @@ -845,10 +845,11 @@ impl UserConfig { { self.materials = applicant.materials; } else { - // TODO: Change this so we are not logging usernames + // TODO: When user structs are fixed so they always carry ids, this should be + // updated to log the user id instead log::info!( - "Unable to find matching applicant when attempting to assign materials to employee {}", - self.username + "Unable to find matching applicant when attempting to assign materials to employee starting on {}", + self.start_date ); } } From 6b47edb0490c41a2023e45a037226e0fe36d345a Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 13 Jul 2022 11:06:59 -0500 Subject: [PATCH 5/9] Cleanup duplicate queries --- cio/src/configs.rs | 23 +++++++++++++---------- cio/src/interviews.rs | 6 ++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/cio/src/configs.rs b/cio/src/configs.rs index 65b7ae887..2eba60458 100644 --- a/cio/src/configs.rs +++ b/cio/src/configs.rs @@ -816,14 +816,21 @@ impl UserConfig { self.work_address_formatted = self.work_address_formatted.replace('\n', "\\n"); } + // Looks up an applicant record based on the users recovery_email. There is a historical + // implicit assumption here that employees use the email that they applied with as their + // recovery_email + async fn applicant_record(&self, db: &Database) -> Result { + Ok(applicants::dsl::applicants + .filter(applicants::dsl::email.eq(self.recovery_email.to_string())) + .first_async::(db.pool()) + .await?) + } + pub async fn populate_start_date(&mut self, db: &Database) { // Only populate the start date, if we could not update it from Gusto. if self.start_date == crate::utils::default_date() { - if let Ok(a) = applicants::dsl::applicants - .filter(applicants::dsl::email.eq(self.recovery_email.to_string())) - .first_async::(db.pool()) - .await - { + if let Ok(a) = self.applicant_record(db).await { + // Get their start date. if a.start_date.is_some() { self.start_date = a.start_date.unwrap(); @@ -838,11 +845,7 @@ impl UserConfig { // urls will need to be manually assigned pub async fn populate_materials(&mut self, db: &Database) { if self.materials.is_empty() { - if let Ok(applicant) = applicants::dsl::applicants - .filter(applicants::dsl::email.eq(self.recovery_email.to_string())) - .first_async::(db.pool()) - .await - { + if let Ok(applicant) = self.applicant_record(db).await { self.materials = applicant.materials; } else { // TODO: When user structs are fixed so they always carry ids, this should be diff --git a/cio/src/interviews.rs b/cio/src/interviews.rs index 9e639e091..c30d84775 100644 --- a/cio/src/interviews.rs +++ b/cio/src/interviews.rs @@ -336,8 +336,10 @@ pub async fn compile_packets(db: &Database, company: &Company) -> Result<()> { .create_folder(&drive_id, "", "interview_packets") .await?; - // Iterate over each user we have in gsuite and download their materials - // locally. + // Iterate over each user we have in gsuite and download their materials locally. + // TODO: This function currently creates local copies of every employees materials prior to + // compiling interview packets. While this is efficient in terms of only requesting each + // materials document once, it is wasteful in that it downloads materials it does not need. let employees = Users::get_from_db(db, company.id).await?; for employee in employees { if employee.is_system_account() { From cc421d935c7aac24ff0fb60b3fcbc9593fff5c4c Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 13 Jul 2022 11:41:38 -0500 Subject: [PATCH 6/9] Copy material urls based on implicit logic during initial migration --- .../up.sql | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql b/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql index 55a02608e..e7faa6b50 100644 --- a/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql +++ b/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql @@ -1 +1,15 @@ -ALTER TABLE users ADD COLUMN materials VARCHAR NOT NULL ''; \ No newline at end of file +ALTER TABLE users ADD COLUMN materials VARCHAR NOT NULL DEFAULT ''; + +UPDATE + users +SET + materials = applicant.materials +FROM ( + SELECT + email, + materials + FROM + applicants +) AS applicant +WHERE + users.recovery_email = applicant.email; \ No newline at end of file From 3b8030c6e2921aabb513ea7e2af70f6d36a0d84a Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 13 Jul 2022 11:50:31 -0500 Subject: [PATCH 7/9] Fmt --- cio/src/configs.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cio/src/configs.rs b/cio/src/configs.rs index 2eba60458..56f65dd54 100644 --- a/cio/src/configs.rs +++ b/cio/src/configs.rs @@ -819,7 +819,7 @@ impl UserConfig { // Looks up an applicant record based on the users recovery_email. There is a historical // implicit assumption here that employees use the email that they applied with as their // recovery_email - async fn applicant_record(&self, db: &Database) -> Result { + async fn applicant_record(&self, db: &Database) -> Result { Ok(applicants::dsl::applicants .filter(applicants::dsl::email.eq(self.recovery_email.to_string())) .first_async::(db.pool()) @@ -830,7 +830,6 @@ impl UserConfig { // Only populate the start date, if we could not update it from Gusto. if self.start_date == crate::utils::default_date() { if let Ok(a) = self.applicant_record(db).await { - // Get their start date. if a.start_date.is_some() { self.start_date = a.start_date.unwrap(); From 3020408d4c351aecc59ab70a0e4971f3a970eca2 Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Wed, 13 Jul 2022 13:27:01 -0500 Subject: [PATCH 8/9] Attempt space cleanup --- .github/workflows/cargo-test.yml | 5 +++++ .github/workflows/docker-image-cio.yml | 5 +++++ .github/workflows/docker-image-webhooky.yml | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/.github/workflows/cargo-test.yml b/.github/workflows/cargo-test.yml index 92d33f418..c6cb869dd 100644 --- a/.github/workflows/cargo-test.yml +++ b/.github/workflows/cargo-test.yml @@ -22,6 +22,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master + - name: Cleanup unused space + shell: bash + run: | + sudo rm -rf /usr/local/lib/android + sudo rm -rf /usr/share/dotnet - uses: actions/setup-node@v2 - name: Install asciidoctor, pandoc, and pdftotext shell: bash diff --git a/.github/workflows/docker-image-cio.yml b/.github/workflows/docker-image-cio.yml index 31ed29abf..e841ed0eb 100644 --- a/.github/workflows/docker-image-cio.yml +++ b/.github/workflows/docker-image-cio.yml @@ -27,6 +27,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master + - name: Cleanup unused space + shell: bash + run: | + sudo rm -rf /usr/local/lib/android + sudo rm -rf /usr/share/dotnet - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Cache Docker layers diff --git a/.github/workflows/docker-image-webhooky.yml b/.github/workflows/docker-image-webhooky.yml index 3d402194a..cd2d39f14 100644 --- a/.github/workflows/docker-image-webhooky.yml +++ b/.github/workflows/docker-image-webhooky.yml @@ -27,6 +27,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master + - name: Cleanup unused space + shell: bash + run: | + sudo rm -rf /usr/local/lib/android + sudo rm -rf /usr/share/dotnet - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Cache Docker layers From ebc67109c737a25db35984b3894832154bfaaa4d Mon Sep 17 00:00:00 2001 From: Augustus Mayo Date: Thu, 14 Jul 2022 10:24:49 -0500 Subject: [PATCH 9/9] Formattinggs --- .../2022-07-12-150519_add_materials_to_employees/up.sql | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql b/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql index e7faa6b50..0b4e06a6b 100644 --- a/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql +++ b/cio/migrations/2022-07-12-150519_add_materials_to_employees/up.sql @@ -1,9 +1,7 @@ ALTER TABLE users ADD COLUMN materials VARCHAR NOT NULL DEFAULT ''; -UPDATE - users -SET - materials = applicant.materials +UPDATE users +SET materials = applicant.materials FROM ( SELECT email, @@ -11,5 +9,4 @@ FROM ( FROM applicants ) AS applicant -WHERE - users.recovery_email = applicant.email; \ No newline at end of file +WHERE users.recovery_email = applicant.email; \ No newline at end of file