Server: Expose submission visibility settings
This commit is contained in:
parent
597bbe94b9
commit
c5e0b3e207
|
@ -341,15 +341,19 @@ pub(crate) fn can_view(
|
|||
return None;
|
||||
}
|
||||
|
||||
let requires_login = if let Some(profile) = cache.profile_map.get(&submission.profile_id())
|
||||
{
|
||||
profile.login_required()
|
||||
} else {
|
||||
let profile = store.profiles.by_id(submission.profile_id()).ok()??;
|
||||
let requires_login = profile.login_required();
|
||||
cache.profile_map.insert(profile.id(), profile);
|
||||
requires_login
|
||||
};
|
||||
if submission.is_followers_only() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let requires_login = submission.is_logged_in_only()
|
||||
|| if let Some(profile) = cache.profile_map.get(&submission.profile_id()) {
|
||||
profile.login_required()
|
||||
} else {
|
||||
let profile = store.profiles.by_id(submission.profile_id()).ok()??;
|
||||
let requires_login = profile.login_required();
|
||||
cache.profile_map.insert(profile.id(), profile);
|
||||
requires_login
|
||||
};
|
||||
|
||||
if requires_login {
|
||||
return None;
|
||||
|
|
|
@ -9,7 +9,12 @@ use crate::{
|
|||
ActixLoader, State,
|
||||
};
|
||||
use actix_web::{client::Client, web, HttpRequest, HttpResponse, Scope};
|
||||
use hyaenidae_profiles::store::{File, Profile, Submission, Visibility};
|
||||
use hyaenidae_profiles::{
|
||||
apub::actions::{
|
||||
CreateComment, CreateReport, CreateSubmission, DeleteSubmission, UpdateSubmission,
|
||||
},
|
||||
store::{File, Profile, Submission, Visibility},
|
||||
};
|
||||
use hyaenidae_toolkit::{Button, FileInput, Select, TextInput, Tile};
|
||||
use i18n_embed_fl::fl;
|
||||
use std::collections::HashMap;
|
||||
|
@ -41,6 +46,11 @@ pub(super) fn scope() -> Scope {
|
|||
.route(web::get().to(update_page))
|
||||
.route(web::post().to(update_submission)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/visibility")
|
||||
.route(web::get().to(route_to_update_page))
|
||||
.route(web::post().to(update_visibility)),
|
||||
)
|
||||
.service(
|
||||
web::resource("/add-file")
|
||||
.route(web::get().to(route_to_update_page))
|
||||
|
@ -219,7 +229,6 @@ async fn report(
|
|||
} else if form.body.trim().is_empty() {
|
||||
format!("Must be present")
|
||||
} else {
|
||||
use hyaenidae_profiles::apub::actions::CreateReport;
|
||||
let res = state
|
||||
.profiles
|
||||
.run(CreateReport::from_submission(
|
||||
|
@ -277,6 +286,7 @@ pub struct SubmissionState {
|
|||
pub(crate) remove_file_error: HashMap<Uuid, String>,
|
||||
pub(crate) publish_error: Option<String>,
|
||||
pub(crate) delete_error: Option<String>,
|
||||
pub(crate) visibility_error: Option<String>,
|
||||
}
|
||||
|
||||
impl SubmissionState {
|
||||
|
@ -309,6 +319,7 @@ impl SubmissionState {
|
|||
remove_file_error: HashMap::new(),
|
||||
publish_error: None,
|
||||
delete_error: None,
|
||||
visibility_error: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -367,6 +378,10 @@ impl SubmissionState {
|
|||
self.submission.view_path()
|
||||
}
|
||||
|
||||
pub(crate) fn visibility_path(&self) -> String {
|
||||
format!("/submissions/{}/visibility", self.submission.id())
|
||||
}
|
||||
|
||||
pub(crate) fn update_path(&self) -> String {
|
||||
format!("/submissions/{}/update", self.submission.id())
|
||||
}
|
||||
|
@ -440,6 +455,11 @@ impl SubmissionState {
|
|||
self.delete_error = Some(error);
|
||||
self
|
||||
}
|
||||
|
||||
fn visibility_error(mut self, error: String) -> Self {
|
||||
self.visibility_error = Some(error);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
async fn files_page(
|
||||
|
@ -472,8 +492,6 @@ async fn upload_files(
|
|||
|
||||
let error = match res {
|
||||
Ok(file_ids) if file_ids.len() == 1 => {
|
||||
use hyaenidae_profiles::apub::actions::CreateSubmission;
|
||||
|
||||
let res = state
|
||||
.profiles
|
||||
.run(CreateSubmission::from_file(profile.id(), file_ids[0]))
|
||||
|
@ -919,7 +937,6 @@ async fn create_comment(
|
|||
let submission = submission.0;
|
||||
let profile = profile.0;
|
||||
|
||||
use hyaenidae_profiles::apub::actions::CreateComment;
|
||||
let form = form.into_inner();
|
||||
|
||||
let store = state.profiles.clone();
|
||||
|
@ -993,7 +1010,6 @@ async fn create_comment(
|
|||
struct UpdateSubmissionForm {
|
||||
title: String,
|
||||
description: String,
|
||||
visibility: Option<Visibility>,
|
||||
}
|
||||
|
||||
async fn update_submission(
|
||||
|
@ -1007,7 +1023,6 @@ async fn update_submission(
|
|||
let submission = submission.0;
|
||||
let profile = profile.0;
|
||||
|
||||
use hyaenidae_profiles::apub::actions::UpdateSubmission;
|
||||
let form = form.into_inner();
|
||||
|
||||
if profile.id() != submission.profile_id() {
|
||||
|
@ -1024,7 +1039,6 @@ async fn update_submission(
|
|||
submission.id(),
|
||||
form.title.clone(),
|
||||
Some(form.description.clone()),
|
||||
form.visibility,
|
||||
))
|
||||
.await;
|
||||
|
||||
|
@ -1051,6 +1065,56 @@ async fn update_submission(
|
|||
})
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize)]
|
||||
struct UpdateVisibilityForm {
|
||||
visibility: Visibility,
|
||||
local_only: Option<String>,
|
||||
logged_in_only: Option<String>,
|
||||
}
|
||||
|
||||
async fn update_visibility(
|
||||
loader: ActixLoader,
|
||||
form: web::Form<UpdateVisibilityForm>,
|
||||
submission: CurrentSubmission,
|
||||
profile: UserProfile,
|
||||
nav_state: NavState,
|
||||
state: web::Data<State>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let submission = submission.0;
|
||||
let profile = profile.0;
|
||||
|
||||
let form = form.into_inner();
|
||||
|
||||
if profile.id() != submission.profile_id() {
|
||||
return Ok(crate::to_404());
|
||||
}
|
||||
|
||||
log::debug!("form: {:?}", form);
|
||||
|
||||
let res = state
|
||||
.profiles
|
||||
.run(UpdateSubmission::from_visibility(
|
||||
submission.id(),
|
||||
form.visibility,
|
||||
form.local_only.is_some(),
|
||||
form.logged_in_only.is_some(),
|
||||
))
|
||||
.await;
|
||||
|
||||
let error = match res {
|
||||
Ok(_) => return Ok(to_update_page(submission.id())),
|
||||
Err(e) => e.to_string(),
|
||||
};
|
||||
|
||||
let state = SubmissionState::new(submission, &state)
|
||||
.await?
|
||||
.visibility_error(error);
|
||||
|
||||
crate::rendered(HttpResponse::BadRequest(), |cursor| {
|
||||
crate::templates::submissions::update(cursor, &loader, &state, &nav_state)
|
||||
})
|
||||
}
|
||||
|
||||
async fn add_file(
|
||||
loader: ActixLoader,
|
||||
req: HttpRequest,
|
||||
|
@ -1064,8 +1128,6 @@ async fn add_file(
|
|||
let submission = submission.0;
|
||||
let profile = profile.0;
|
||||
|
||||
use hyaenidae_profiles::apub::actions::UpdateSubmission;
|
||||
|
||||
if profile.id() != submission.profile_id() {
|
||||
return Ok(crate::to_404());
|
||||
}
|
||||
|
@ -1116,8 +1178,6 @@ async fn remove_file(
|
|||
let submission = submission.0;
|
||||
let profile = profile.0;
|
||||
|
||||
use hyaenidae_profiles::apub::actions::UpdateSubmission;
|
||||
|
||||
if profile.id() != submission.profile_id() {
|
||||
return Ok(crate::to_404());
|
||||
}
|
||||
|
@ -1154,8 +1214,6 @@ async fn publish_submission(
|
|||
let submission = submission.0;
|
||||
let profile = profile.0;
|
||||
|
||||
use hyaenidae_profiles::apub::actions::UpdateSubmission;
|
||||
|
||||
if profile.id() != submission.profile_id() {
|
||||
return Ok(crate::to_404());
|
||||
}
|
||||
|
@ -1193,8 +1251,6 @@ async fn delete_submission(
|
|||
let submission = submission.0;
|
||||
let profile = profile.0;
|
||||
|
||||
use hyaenidae_profiles::apub::actions::DeleteSubmission;
|
||||
|
||||
if profile.id() != submission.profile_id() {
|
||||
return Ok(crate::to_404());
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
@use crate::templates::layouts::home;
|
||||
@use hyaenidae_toolkit::{templates::button_group, Button};
|
||||
@use hyaenidae_toolkit::{templates::{card, card_body, card_title}, Card};
|
||||
@use hyaenidae_toolkit::templates::checkbox;
|
||||
@use hyaenidae_toolkit::templates::profile;
|
||||
@use i18n_embed_fl::fl;
|
||||
|
||||
|
@ -27,21 +28,7 @@
|
|||
})
|
||||
}
|
||||
@:card_body({
|
||||
<label for="require_login">
|
||||
@if profile_state.login_required() {
|
||||
<input
|
||||
type="checkbox"
|
||||
name="require_login"
|
||||
checked
|
||||
/>
|
||||
} else {
|
||||
<input
|
||||
type="checkbox"
|
||||
name="require_login"
|
||||
/>
|
||||
}
|
||||
<span>@fl!(loader, "require-login-checkbox")</span>
|
||||
</label>
|
||||
@:checkbox("require_login", &fl!(loader, "require-login-checkbox"), profile_state.login_required())
|
||||
})
|
||||
@:card_body({
|
||||
@:button_group(&[
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
@use crate::templates::layouts::home;
|
||||
@use hyaenidae_toolkit::{templates::{button, button_group}, Button};
|
||||
@use hyaenidae_toolkit::{templates::{card, card_body, card_title}, Card};
|
||||
@use hyaenidae_toolkit::templates::checkbox;
|
||||
@use hyaenidae_toolkit::templates::file_input;
|
||||
@use hyaenidae_toolkit::templates::image;
|
||||
@use hyaenidae_toolkit::templates::profile;
|
||||
|
@ -125,21 +126,7 @@
|
|||
<h3>@fl!(loader, "update-require-login-heading")</h3>
|
||||
<p>@fl!(loader, "update-require-login-description")</p>
|
||||
<div class="text-section">
|
||||
<label for="require_login">
|
||||
@if state.profile.login_required() {
|
||||
<input
|
||||
type="checkbox"
|
||||
name="require_login"
|
||||
checked
|
||||
/>
|
||||
} else {
|
||||
<input
|
||||
type="checkbox"
|
||||
name="require_login"
|
||||
/>
|
||||
}
|
||||
<span>@fl!(loader, "update-require-login-checkbox")</span>
|
||||
</label>
|
||||
@:checkbox("require_login", &fl!(loader, "update-require-login-checkbox"), state.profile.login_required())
|
||||
</div>
|
||||
<div class="button-section">
|
||||
@:button_group(&[
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
@use crate::{templates::layouts::home, nav::NavState, submissions::SubmissionState};
|
||||
@use hyaenidae_toolkit::{templates::{button_group}, Button};
|
||||
@use hyaenidae_toolkit::{templates::{card, card_body, card_title}, Card};
|
||||
@use hyaenidae_toolkit::templates::checkbox;
|
||||
@use hyaenidae_toolkit::templates::file_input;
|
||||
@use hyaenidae_toolkit::templates::select;
|
||||
@use hyaenidae_toolkit::templates::text_input;
|
||||
|
@ -35,6 +36,30 @@
|
|||
</form>
|
||||
})
|
||||
}
|
||||
@if !state.is_published() {
|
||||
@:card(&Card::full_width().dark(nav_state.dark()), {
|
||||
<form method="POST" action="@state.visibility_path()">
|
||||
@:card_title({
|
||||
@fl!(loader, "submission-visibility-heading")
|
||||
})
|
||||
@if let Some(error) = &state.visibility_error {
|
||||
@:card_body({
|
||||
@error
|
||||
})
|
||||
}
|
||||
@:card_body({
|
||||
@:checkbox("local_only", &fl!(loader, "submission-local-only"), state.submission.is_local_only())
|
||||
@:checkbox("logged_in_only", &fl!(loader, "submission-login-required"), state.submission.is_logged_in_only())
|
||||
@:select(&state.visibility(loader).dark(nav_state.dark()))
|
||||
})
|
||||
@:card_body({
|
||||
@:button_group(&[
|
||||
Button::primary(&fl!(loader, "update-submission-info-button")),
|
||||
])
|
||||
})
|
||||
</form>
|
||||
})
|
||||
}
|
||||
@:card(&Card::full_width().dark(nav_state.dark()), {
|
||||
<form method="POST" action="@state.update_path()">
|
||||
@:card_title({
|
||||
|
@ -43,9 +68,6 @@
|
|||
@:card_body({
|
||||
@:text_input(&state.title_input(loader).dark(nav_state.dark()))
|
||||
@:text_input(&state.description_input(loader).dark(nav_state.dark()))
|
||||
@if !state.is_published() {
|
||||
@:select(&state.visibility(loader).dark(nav_state.dark()))
|
||||
}
|
||||
})
|
||||
@:card_body({
|
||||
@:button_group(&[
|
||||
|
|
|
@ -174,6 +174,10 @@ submission-visibility-followers = Followers Only
|
|||
submission-visibility-unlisted = Unlisted
|
||||
submission-visibility-public = Public
|
||||
|
||||
submission-visibility-heading = Audience
|
||||
submission-login-required = Require login to view this submission
|
||||
submission-local-only = Restrict this submission to your {site-name} server
|
||||
|
||||
update-submission-title = Edit Submission
|
||||
update-submission-subtitle = Edit information or update images
|
||||
update-submission-publish-title = Publish Submission
|
||||
|
|
Loading…
Reference in a new issue