Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null values in waiting series #1323

Merged
merged 1 commit into from
Jan 27, 2025
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
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
Loading