-
Notifications
You must be signed in to change notification settings - Fork 17
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
Change mount_series
endpoint to accept and move existing series
#1225
base: next
Are you sure you want to change the base?
Changes from all commits
2db6210
a53d45f
5889f57
1d14142
de10cc2
1516e5f
4f86349
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ collections: | |
- name: prometheus.prometheus | ||
version: 0.16.3 | ||
- name: grafana.grafana | ||
version: 5.2.0 | ||
version: 5.5.0 |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -10,7 +10,7 @@ use super::{ | |||||
id::Id, | ||||||
Node, | ||||||
model::{ | ||||||
series::{Series, NewSeries}, | ||||||
series::{Series, NewSeries, PreparedSeries}, | ||||||
realm::{ | ||||||
ChildIndex, | ||||||
NewRealm, | ||||||
|
@@ -23,6 +23,7 @@ use super::{ | |||||
RealmSpecifier, | ||||||
RealmLineageComponent, | ||||||
CreateRealmLineageOutcome, | ||||||
RemoveMountedSeriesOutcome, | ||||||
}, | ||||||
block::{ | ||||||
BlockValue, | ||||||
|
@@ -275,6 +276,94 @@ impl Mutation { | |||||
Ok(CreateRealmLineageOutcome { num_created }) | ||||||
} | ||||||
|
||||||
async fn prepare_series(series: NewSeries, context: &Context) -> ApiResult<PreparedSeries> { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All new API endpoints should have some docs explaining what they do. |
||||||
if context.auth != AuthContext::TrustedExternal { | ||||||
return Err(not_authorized!("only trusted external applications can use this mutation")); | ||||||
} | ||||||
|
||||||
let series = Series::create(series, context).await?; | ||||||
|
||||||
Ok(PreparedSeries { id: series.id() }) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply return |
||||||
} | ||||||
|
||||||
async fn add_series_mount_point( | ||||||
series_oc_id: String, | ||||||
target_path: String, | ||||||
context: &Context, | ||||||
) -> ApiResult<Realm> { | ||||||
if context.auth != AuthContext::TrustedExternal { | ||||||
return Err(not_authorized!("only trusted external applications can use this mutation")); | ||||||
} | ||||||
Comment on lines
+294
to
+296
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These three lines are repeated a bit. How about adding a method to |
||||||
|
||||||
let series = Series::load_by_opencast_id(series_oc_id, context) | ||||||
.await? | ||||||
.ok_or_else(|| invalid_input!("`seriesId` does not refer to a valid series"))?; | ||||||
|
||||||
let target_realm = Realm::load_by_path(target_path, context) | ||||||
.await? | ||||||
.ok_or_else(|| invalid_input!("`targetRealmPath` does not refer to a valid realm"))?; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
BlockValue::add_series( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this, the check from |
||||||
Id::realm(target_realm.key), | ||||||
0, | ||||||
NewSeriesBlock { | ||||||
series: series.id(), | ||||||
show_title: false, | ||||||
show_metadata: true, | ||||||
order: VideoListOrder::NewToOld, | ||||||
layout: VideoListLayout::Gallery, | ||||||
}, | ||||||
context, | ||||||
).await?; | ||||||
|
||||||
let block = &BlockValue::load_for_realm(target_realm.key, context).await?[0]; | ||||||
|
||||||
Realm::rename( | ||||||
target_realm.id(), | ||||||
UpdatedRealmName::from_block(block.id()), | ||||||
context, | ||||||
).await | ||||||
} | ||||||
|
||||||
async fn remove_series_mount_point( | ||||||
path: String, | ||||||
context: &Context, | ||||||
) -> ApiResult<RemoveMountedSeriesOutcome> { | ||||||
if context.auth != AuthContext::TrustedExternal { | ||||||
return Err(not_authorized!("only trusted external applications can use this mutation")); | ||||||
} | ||||||
|
||||||
let old_realm = Realm::load_by_path(path, context) | ||||||
.await? | ||||||
.ok_or_else(|| invalid_input!("`currentRealmPath` does not refer to a valid realm"))?; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
let blocks = BlockValue::load_for_realm(old_realm.key, context).await?; | ||||||
|
||||||
if blocks.len() > 1 { | ||||||
return Err(invalid_input!("series can only be moved if its current realm has no other blocks")); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Error message needs adjusting (its not a "move" API anymore) |
||||||
} | ||||||
|
||||||
let mut removed_realm = None; | ||||||
let mut removed_block = None; | ||||||
|
||||||
if old_realm.children(context).await?.len() == 0 { | ||||||
// The realm has no children, so it can be removed. | ||||||
removed_realm = Some(Realm::remove(old_realm.id(), context).await?); | ||||||
} else { | ||||||
// At this point we can be certain that there is only one block, which is the series block. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually no, these checks are not happening in this method, at this point we only know that there is 0 or 1 blocks in this realm and that the realm has some children. If the block has 0 blocks, the |
||||||
// Ideally we would restore the previous title, but that's not stored anywhere. So the realm | ||||||
// gets the name of its path segment. | ||||||
Realm::rename( | ||||||
old_realm.id(), | ||||||
UpdatedRealmName::plain(old_realm.path_segment), | ||||||
context, | ||||||
).await?; | ||||||
removed_block = Some(BlockValue::remove(blocks[0].id(), context).await?); | ||||||
} | ||||||
|
||||||
Ok(RemoveMountedSeriesOutcome { removed_realm, removed_block }) | ||||||
} | ||||||
|
||||||
/// Atomically mount a series into an (empty) realm. | ||||||
/// Creates all the necessary realms on the path to the target | ||||||
/// and adds a block with the given series at the leaf. | ||||||
Comment on lines
367
to
369
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like there is always exactly one of these fields set to
Some
. Rather sounds like anenum
(Rust) /union
(graphql) to me?