Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Pull request checks

on:
pull_request:

permissions:
contents: read

concurrency:
group: pr-checks-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
rust:
name: Rust format, lint, and test
runs-on: ubuntu-latest

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: Cache Rust build artifacts
uses: Swatinem/rust-cache@v2

- name: Check formatting
run: cargo fmt --all -- --check

- name: Run Clippy
run: cargo clippy --all-targets --all-features --locked -- -D warnings

- name: Run tests
run: cargo test --all-targets --all-features --locked
9 changes: 2 additions & 7 deletions src/handlers/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ struct AdminInvitesTemplate {
}

struct PermissionOptionView {
input_id: String,
value: &'static str,
label: &'static str,
description: &'static str,
Expand All @@ -62,7 +61,6 @@ struct InviteView {
link: String,
note: Option<String>,
created_by: String,
created_at: String,
expires_at: String,
}

Expand Down Expand Up @@ -238,9 +236,7 @@ fn permission_options(active_permissions: &[Permission]) -> Vec<PermissionOption
Permission::ALL
.iter()
.copied()
.enumerate()
.map(|(index, permission)| PermissionOptionView {
input_id: format!("permission-{index}"),
.map(|permission| PermissionOptionView {
value: permission.as_str(),
label: permission.label(),
description: permission.description(),
Expand All @@ -253,7 +249,7 @@ fn parse_permissions(values: &[String]) -> Result<Vec<Permission>, AppError> {
let mut permissions = Vec::new();

for value in values {
let Some(permission) = Permission::from_str(value) else {
let Some(permission) = Permission::parse(value) else {
return Err(AppError::BadRequest("Unknown permission selected."));
};

Expand All @@ -274,7 +270,6 @@ impl InviteView {
created_by: invite
.created_by_username
.unwrap_or_else(|| "Deleted user".to_owned()),
created_at: invite.created_at.format("%Y-%m-%d %H:%M UTC").to_string(),
expires_at: invite.expires_at.format("%Y-%m-%d %H:%M UTC").to_string(),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Permission {
}
}

pub fn from_str(value: &str) -> Option<Self> {
pub fn parse(value: &str) -> Option<Self> {
match value {
"user.permissions.edit" => Some(Self::UserPermissionsEdit),
"user.invites.create" => Some(Self::UserInvitesCreate),
Expand Down
3 changes: 2 additions & 1 deletion src/repositories/publications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ pub async fn create_publication(

fn publication_summary_from_row(row: sqlx::postgres::PgRow) -> PublicationSummary {
let title = row.get::<String, _>("title");
let contributor_names: Vec<String> = row.get::<Vec<String>, _>("contributor_names")
let contributor_names: Vec<String> = row
.get::<Vec<String>, _>("contributor_names")
.into_iter()
.filter(|n| !n.is_empty())
.collect();
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/user_permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub async fn list_permissions_for_user(

Ok(rows
.into_iter()
.filter_map(|row| Permission::from_str(row.get("permission")))
.filter_map(|row| Permission::parse(row.get("permission")))
.collect())
}

Expand Down
Loading