66
77'use strict' ;
88import logger from "../logger.js" ;
9- import express , { Request , Response , NextFunction } from 'express' ;
9+ import express , { Request , Response , NextFunction } from 'express' ;
1010import { body , param , query } from 'express-validator' ;
1111import multer from 'multer' ;
1212import { S3Client , PutObjectCommand } from '@aws-sdk/client-s3' ;
@@ -71,7 +71,7 @@ async function lookupOrganization(orgID: string) {
7171 { orgID } ,
7272 { _id : 0 , defaultProjectLead : 0 } ,
7373 ) . lean ( ) ;
74- if ( org ?. commonsModules ) {
74+ if ( org ?. commonsModules ) {
7575 // Remove _id and __v fields from commonsModules subdocument
7676 // @ts -ignore
7777 delete org . commonsModules . _id ;
@@ -225,6 +225,45 @@ async function getLibreGridOrganizations(_req: Request, res: Response) {
225225 }
226226}
227227
228+ async function getCustomCoverConfig ( req : Request , res : Response ) {
229+ try {
230+ const { orgID } = req . params ;
231+
232+ const orgData = await Organization . findOne (
233+ {
234+ orgID : { $eq : orgID }
235+ } ,
236+ {
237+ orgID : 1 ,
238+ name : 1 ,
239+ customCoverConfig : 1 ,
240+ }
241+ ) . lean ( ) ;
242+
243+ if ( ! orgData ) {
244+ return res . status ( 404 ) . send ( {
245+ err : true ,
246+ errMsg : conductorErrors . err11 ,
247+ } ) ;
248+ }
249+
250+ return res . send ( {
251+ err : false ,
252+ org : {
253+ orgID : orgData . orgID ,
254+ name : orgData . name ,
255+ } ,
256+ customCoverConfig : orgData . customCoverConfig || null ,
257+ } ) ;
258+ } catch ( e ) {
259+ logger . error ( { err : e } , "getCustomCoverConfig failed" ) ;
260+ return res . status ( 500 ) . send ( {
261+ err : true ,
262+ errMsg : conductorErrors . err6 ,
263+ } ) ;
264+ }
265+ }
266+
228267/**
229268 * Updates an Organization's information.
230269 *
@@ -248,11 +287,11 @@ async function updateOrganizationInfo(req: Request, res: Response) {
248287 }
249288 } ;
250289
251- if ( req . body . primaryColor ) {
290+ if ( req . body . primaryColor ) {
252291 updateObj . primaryColor = sanitizeCustomColor ( req . body . primaryColor )
253292 }
254293
255- if ( req . body . footerColor ) {
294+ if ( req . body . footerColor ) {
256295 updateObj . footerColor = sanitizeCustomColor ( req . body . footerColor )
257296 }
258297
@@ -274,7 +313,7 @@ async function updateOrganizationInfo(req: Request, res: Response) {
274313 ) ;
275314 }
276315
277- if ( Object . hasOwn ( updateObj , 'collectionsDisplayLabel' ) && isEmptyString ( updateObj . collectionsDisplayLabel ?? '' ) ) {
316+ if ( Object . hasOwn ( updateObj , 'collectionsDisplayLabel' ) && isEmptyString ( updateObj . collectionsDisplayLabel ?? '' ) ) {
278317 // Reset label to 'Collections' if empty string was passed
279318 updateObj . collectionsDisplayLabel = 'Collections'
280319 }
@@ -355,9 +394,9 @@ async function updateBrandingImageAsset(req: Request, res: Response) {
355394 errMsg : conductorErrors . err2 ,
356395 } ) ;
357396 }
358-
397+
359398 let assetVersion = 1 ;
360-
399+
361400 // @ts -ignore
362401 if ( org [ assetName ] . includes ( process . env . AWS_ORGDATA_DOMAIN ) ) {
363402 //@ts -ignore
@@ -472,7 +511,7 @@ function validateCommonsModules(commonsModules: any) {
472511 return false ;
473512 }
474513 for ( const module in commonsModules ) {
475- if ( module === "_id" || module === "__v" ) {
514+ if ( module === "_id" || module === "__v" ) {
476515 // ignore these fields (mongodb adds them because commonsModules is technically a subdocument of the Organization model)
477516 continue ;
478517 }
@@ -512,16 +551,20 @@ function validate(method: string) {
512551 return [
513552 param ( 'orgID' , conductorErrors . err1 ) . exists ( ) . isLength ( { min : 2 , max : 50 } ) ,
514553 ] ;
554+ case 'getCustomCoverConfig' :
555+ return [
556+ param ( 'orgID' , conductorErrors . err1 ) . exists ( ) . isLength ( { min : 2 , max : 50 } ) ,
557+ ] ;
515558 case 'updateinfo' :
516559 return [
517560 param ( 'orgID' , conductorErrors . err1 ) . exists ( ) . isLength ( { min : 2 , max : 50 } ) ,
518561 body ( 'aboutLink' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isURL ( ) ,
519562 body ( 'commonsHeader' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { max : 200 } ) ,
520563 body ( 'commonsMessage' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { max : 500 } ) ,
521- body ( 'collectionsDisplayLabel' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { max : 200 } ) ,
522- body ( 'collectionsMessage' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { max : 500 } ) ,
523- body ( 'primaryColor' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { min : 7 , max : 7 } ) . isHexColor ( ) ,
524- body ( 'footerColor' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { min : 7 , max : 7 } ) . isHexColor ( ) ,
564+ body ( 'collectionsDisplayLabel' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { max : 200 } ) ,
565+ body ( 'collectionsMessage' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { max : 500 } ) ,
566+ body ( 'primaryColor' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { min : 7 , max : 7 } ) . isHexColor ( ) ,
567+ body ( 'footerColor' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isLength ( { min : 7 , max : 7 } ) . isHexColor ( ) ,
525568 body ( 'addToLibreGridList' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isBoolean ( ) . toBoolean ( ) ,
526569 body ( 'supportTicketNotifiers' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isArray ( ) . isEmail ( ) ,
527570 body ( 'defaultAssetTagFrameworkUUID' , conductorErrors . err1 ) . optional ( { checkFalsy : true } ) . isUUID ( ) ,
@@ -549,6 +592,7 @@ export default {
549592 getOrganizationInfo,
550593 getCampusAdmins,
551594 getCurrentOrganization,
595+ getCustomCoverConfig,
552596 getAllOrganizations,
553597 getLibreGridOrganizations,
554598 updateOrganizationInfo,
0 commit comments