Skip to content

Commit

Permalink
Fix “waiting” series creation with non-null roles
Browse files Browse the repository at this point in the history
In #a4bff75a314d04e85f7cd977076550a6dfa5373d I added
read- and write-roles to the series API, but didn't
allow `null` values. This lead to deserialization
errors when creating waiting series.

This fix adds the roles as empty arrays.
  • Loading branch information
owi92 committed Jan 27, 2025
1 parent 0de3ca3 commit caafabf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
4 changes: 2 additions & 2 deletions backend/src/api/model/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ impl AuthorizedEvent {
synced_data: None,
created: None,
metadata: None,
read_roles: vec![],
write_roles: vec![],
read_roles: None,
write_roles: None,
}))
} else {
// We need to load the series as fields were requested that were not preloaded.
Expand Down
34 changes: 19 additions & 15 deletions backend/src/api/model/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
acl::{self, Acl},
},
},
db::{types::{SeriesState as State}, util::impl_from_db},
db::{types::SeriesState as State, util::impl_from_db},
model::{Key, ExtraMetadata},
prelude::*,
};
Expand All @@ -31,8 +31,8 @@ pub(crate) struct Series {
pub(crate) title: String,
pub(crate) created: Option<DateTime<Utc>>,
pub(crate) metadata: Option<ExtraMetadata>,
pub(crate) read_roles: Vec<String>,
pub(crate) write_roles: Vec<String>,
pub(crate) read_roles: Option<Vec<String>>,
pub(crate) write_roles: Option<Vec<String>>,
}

#[derive(GraphQLObject)]
Expand Down Expand Up @@ -98,17 +98,21 @@ impl Series {
.pipe(Ok)
}

async fn load_acl(&self, context: &Context) -> ApiResult<Acl> {
let raw_roles_sql = "\
select unnest($1::text[]) as role, 'read' as action
union
select unnest($2::text[]) as role, 'write' as action
";

acl::load_for(context, raw_roles_sql, dbargs![
&self.read_roles,
&self.write_roles,
]).await
async fn load_acl(&self, context: &Context) -> ApiResult<Option<Acl>> {
match (self.read_roles.as_ref(), self.write_roles.as_ref()) {
(None, None) => Ok(None),
(read_roles, write_roles) => {
let raw_roles_sql = "\
select unnest($1::text[]) as role, 'read' as action
union
select unnest($2::text[]) as role, 'write' as action
";

acl::load_for(context, raw_roles_sql, dbargs![&read_roles, &write_roles])
.await
.map(Some)
}
}
}

pub(crate) async fn create(series: NewSeries, context: &Context) -> ApiResult<Self> {
Expand Down Expand Up @@ -295,7 +299,7 @@ impl Series {
&self.synced_data
}

async fn acl(&self, context: &Context) -> ApiResult<Acl> {
async fn acl(&self, context: &Context) -> ApiResult<Option<Acl>> {
self.load_acl(context).await
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ type Series implements Node {
created: DateTime
metadata: ExtraMetadata
syncedData: SyncedSeriesData
acl: [AclItem!]!
acl: [AclItem!]
hostRealms: [Realm!]!
entries: [VideoListEntry!]!
"""
Expand Down

0 comments on commit caafabf

Please sign in to comment.