mirror of
https://github.com/bpatrik/pigallery2.git
synced 2026-06-20 00:15:49 +02:00
Add default view option to sharing entry #1133
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import {NextFunction, Request, Response} from 'express';
|
||||
import {CreateSharingDTO, SharingDTOKey, UpdateSharingDTO} from '../../common/entities/SharingDTO';
|
||||
import {CreateSharingDTO, SharingDTOKey, UpdateSharingDTO} from '../../common/entities/SharingDTO';
|
||||
import {ObjectManagers} from '../model/ObjectManagers';
|
||||
import {ErrorCodes, ErrorDTO} from '../../common/entities/Error';
|
||||
import {Config} from '../../common/config/private/Config';
|
||||
@@ -116,6 +116,8 @@ export class SharingMWs {
|
||||
sharingKey,
|
||||
searchQuery,
|
||||
password: createSharing.password,
|
||||
defaultSearchView: null,
|
||||
defaultDirectoryView: null,
|
||||
creator: req.session.context?.user as UserEntity, // only the user id is used
|
||||
expires:
|
||||
createSharing.valid >= 0 // if === -1 it's forever
|
||||
@@ -124,6 +126,13 @@ export class SharingMWs {
|
||||
timeStamp: Date.now(),
|
||||
};
|
||||
|
||||
if (createSharing.defaultDirectoryView) {
|
||||
sharing.defaultDirectoryView = createSharing.defaultDirectoryView;
|
||||
}
|
||||
if (createSharing.defaultSearchView) {
|
||||
sharing.defaultSearchView = createSharing.defaultSearchView;
|
||||
}
|
||||
|
||||
req.resultPipe =
|
||||
await ObjectManagers.getInstance().SharingManager.createSharing(
|
||||
sharing
|
||||
@@ -184,6 +193,15 @@ export class SharingMWs {
|
||||
timeStamp: Date.now(),
|
||||
};
|
||||
|
||||
|
||||
if (updateSharing.defaultDirectoryView) {
|
||||
sharing.defaultDirectoryView = updateSharing.defaultDirectoryView;
|
||||
}
|
||||
if (updateSharing.defaultSearchView) {
|
||||
sharing.defaultSearchView = updateSharing.defaultSearchView;
|
||||
}
|
||||
|
||||
|
||||
const forceUpdate = req.session.context.user.role >= UserRoles.Admin;
|
||||
req.resultPipe =
|
||||
await ObjectManagers.getInstance().SharingManager.updateSharing(
|
||||
|
||||
@@ -72,6 +72,10 @@ export class SharingManager {
|
||||
SearchQueryUtils.validateSearchQuery(sharing.searchQuery);
|
||||
sharing.searchQuery = SearchQueryUtils.sortQuery(sharing.searchQuery);
|
||||
}
|
||||
if(sharing.defaultSearchView){
|
||||
SearchQueryUtils.validateSearchQuery(sharing.defaultSearchView);
|
||||
sharing.searchQuery = SearchQueryUtils.sortQuery(sharing.defaultSearchView);
|
||||
}
|
||||
return connection.getRepository(SharingEntity).save(sharing);
|
||||
}
|
||||
|
||||
@@ -99,6 +103,13 @@ export class SharingManager {
|
||||
}
|
||||
// allow updating searchQuery and canonicalize it
|
||||
sharing.searchQuery = SearchQueryUtils.sortQuery(inSharing.searchQuery);
|
||||
if(inSharing.defaultSearchView){
|
||||
SearchQueryUtils.validateSearchQuery(inSharing.defaultSearchView);
|
||||
sharing.searchQuery = SearchQueryUtils.sortQuery(inSharing.defaultSearchView);
|
||||
}
|
||||
if(inSharing.defaultDirectoryView){
|
||||
sharing.defaultDirectoryView = inSharing.defaultDirectoryView;
|
||||
}
|
||||
sharing.expires = inSharing.expires;
|
||||
|
||||
return connection.getRepository(SharingEntity).save(sharing);
|
||||
|
||||
@@ -11,6 +11,10 @@ export class SharingEntity implements BaseSharingDTO {
|
||||
@Column()
|
||||
sharingKey: string;
|
||||
|
||||
/*
|
||||
* This query determines what is available for the user through sharing
|
||||
* Basically it's an allow-list of photos.
|
||||
* */
|
||||
@Column({
|
||||
type: 'text',
|
||||
nullable: false,
|
||||
@@ -25,6 +29,28 @@ export class SharingEntity implements BaseSharingDTO {
|
||||
})
|
||||
searchQuery: SearchQueryDTO;
|
||||
|
||||
/**
|
||||
* Only of the defaults should be set at most. If none is set the defaultSearchView will be searchQuery
|
||||
*/
|
||||
@Column({
|
||||
type: 'text',
|
||||
nullable: true
|
||||
})
|
||||
defaultDirectoryView: string;
|
||||
@Column({
|
||||
type: 'text',
|
||||
nullable: true,
|
||||
transformer: {
|
||||
from: (val: string) => {
|
||||
return val ? JSON.parse(val) : null;
|
||||
},
|
||||
to: (val: object) => {
|
||||
return val ? JSON.stringify(val) : null;
|
||||
},
|
||||
},
|
||||
})
|
||||
defaultSearchView: SearchQueryDTO;
|
||||
|
||||
@Column({type: 'text', nullable: true})
|
||||
password: string;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
* This version indicates that the sql/entities/*Entity.ts files got changed and the db needs to be recreated
|
||||
*/
|
||||
export const DataStructureVersion = 42;
|
||||
export const DataStructureVersion = 43;
|
||||
|
||||
@@ -7,6 +7,8 @@ export interface SharingDTOKey {
|
||||
|
||||
export interface BaseSharingDTO extends SharingDTOKey {
|
||||
id: number;
|
||||
defaultSearchView?: SearchQueryDTO;
|
||||
defaultDirectoryView?: string;
|
||||
searchQuery: SearchQueryDTO;
|
||||
sharingKey: string;
|
||||
expires: number;
|
||||
@@ -17,6 +19,8 @@ export interface BaseSharingDTO extends SharingDTOKey {
|
||||
|
||||
export interface ResponseSharingDTO extends BaseSharingDTO {
|
||||
id: number;
|
||||
defaultSearchView?: SearchQueryDTO;
|
||||
defaultDirectoryView?: string;
|
||||
searchQuery: SearchQueryDTO;
|
||||
sharingKey: string;
|
||||
expires: number;
|
||||
@@ -27,6 +31,8 @@ export interface ResponseSharingDTO extends BaseSharingDTO {
|
||||
|
||||
export interface UpdateSharingDTO extends BaseSharingDTO {
|
||||
id: number;
|
||||
defaultSearchView?: SearchQueryDTO;
|
||||
defaultDirectoryView?: string;
|
||||
searchQuery: SearchQueryDTO;
|
||||
sharingKey: string;
|
||||
password?: string;
|
||||
@@ -39,5 +45,7 @@ export interface CreateSharingDTO {
|
||||
id?: number;
|
||||
password: string;
|
||||
valid: number;
|
||||
defaultSearchView?: SearchQueryDTO;
|
||||
defaultDirectoryView?: string;
|
||||
searchQuery: SearchQueryDTO;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user