Skip to content

Commit

Permalink
Hide text results for events with passwords
Browse files Browse the repository at this point in the history
This is not a good solution as it relies on
a frontend check. Ideally this would be done in backend.
  • Loading branch information
owi92 committed Sep 12, 2024
1 parent 74a5df8 commit 8e8763f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
22 changes: 10 additions & 12 deletions backend/src/api/model/search/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,19 @@ impl SearchEvent {
caption_matches: &[MatchRange],
context: &Context,
) -> Self {
let read_roles: Vec<String> = src.read_roles.iter()
.map(|role| {
let bytes = hex::decode(role).expect("Failed to decode role");

String::from_utf8(bytes).expect("Failed to convert bytes to string")
})
.collect();

let mut text_matches = Vec::new();
if context.auth.overlaps_roles(&read_roles) {
src.slide_texts.resolve_matches(slide_matches, &mut text_matches, TextAssetType::SlideText);
src.caption_texts.resolve_matches(caption_matches, &mut text_matches, TextAssetType::Caption);
}
src.slide_texts.resolve_matches(slide_matches, &mut text_matches, TextAssetType::SlideText);
src.caption_texts.resolve_matches(caption_matches, &mut text_matches, TextAssetType::Caption);

let thumbnail = {
let read_roles: Vec<String> = src.read_roles.iter()
.map(|role| {
let bytes = hex::decode(role).expect("Failed to decode role");

String::from_utf8(bytes).expect("Failed to convert bytes to string")
})
.collect();

if context.auth.overlaps_roles(&read_roles) {
src.thumbnail
} else {
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/routes/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import { ellipsisOverflowCss, focusStyle } from "../ui";
import { COLORS } from "../color";
import { BREAKPOINT_MEDIUM, BREAKPOINT_SMALL } from "../GlobalStyle";
import { eventId, isExperimentalFlagSet, keyOfId, secondsToTimeString } from "../util";
import { DirectVideoRoute, VideoRoute } from "./Video";
import { DirectVideoRoute, getCredentials, VideoRoute } from "./Video";
import { DirectSeriesRoute } from "./Series";
import { PartOfSeriesLink } from "../ui/Blocks/VideoList";
import { SearchSlidePreviewQuery } from "./__generated__/SearchSlidePreviewQuery.graphql";
Expand Down Expand Up @@ -509,6 +509,9 @@ const SearchEvent: React.FC<SearchEventProps> = ({
? DirectVideoRoute.url({ videoId: id })
: VideoRoute.url({ realmPath: hostRealms[0].path, videoID: id });

// TODO: add backend check (api to get text-matches similarly to authorized event data)
const showMatches = hasPassword ? getCredentials(keyOfId(id)) : true;

return (
<Item key={id} link={link}>
<WithIcon Icon={LuPlayCircle} hideIconOnMobile>
Expand Down Expand Up @@ -545,7 +548,7 @@ const SearchEvent: React.FC<SearchEventProps> = ({
{seriesTitle && seriesId && <PartOfSeriesLink {...{ seriesTitle, seriesId }} />}

{/* Show timeline with matches if there are any */}
{textMatches.length > 0 && (
{textMatches.length > 0 && showMatches && (
<TextMatchTimeline {...{ id, duration, link, textMatches }} />
)}
</div>
Expand Down Expand Up @@ -595,11 +598,11 @@ type TextMatchTimelineProps = Pick<SearchEventProps, "id" | "duration" | "textMa
};

const slidePreviewQuery = graphql`
query SearchSlidePreviewQuery($id: ID!) {
query SearchSlidePreviewQuery($id: ID!, $seriesUser: String, $seriesPassword: String) {
eventById(id: $id) {
...on AuthorizedEvent {
id
authorizedData {
authorizedData(user: $seriesUser, password: $seriesPassword) {
segments { startTime uri }
}
}
Expand Down

0 comments on commit 8e8763f

Please sign in to comment.