/
settings.py
1557 lines (1313 loc) · 51 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
~~AppSettings:Config~~
"""
import os
from portality import constants
from portality.lib import paths
###########################################
# Application Version information
# ~~->API:Feature~~
DOAJ_VERSION = "6.6.10"
API_VERSION = "3.0.1"
######################################
# Deployment configuration
HOST = '0.0.0.0'
DEBUG = False
PORT = 5004
SSL = True
VALID_ENVIRONMENTS = ['dev', 'test', 'staging', 'production', 'harvester']
CMS_BUILD_ASSETS_ON_STARTUP = False
# Cookies security
SESSION_COOKIE_SAMESITE='Strict'
SESSION_COOKIE_SECURE=True
REMEMBER_COOKIE_SECURE = True
####################################
# Testdrive for setting up the test environment.
# CAUTION - this can modify the index so should NEVER be used in production!
TESTDRIVE_ENABLED = False
####################################
# Debug Mode
# PyCharm debug settings
DEBUG_PYCHARM = False # do not try to connect to the PyCharm debugger by default
DEBUG_PYCHARM_SERVER = 'localhost'
DEBUG_PYCHARM_PORT = 6000
#~~->DebugToolbar:Framework~~
DEBUG_TB_TEMPLATE_EDITOR_ENABLED = True
DEBUG_TB_INTERCEPT_REDIRECTS = False
# set to True to enable the env list panel in the debug toolbar
DEBUG_TB_ENV_LIST_ENABLED = False
#######################################
# Elasticsearch configuration
#~~->Elasticsearch:Technology
# elasticsearch settings # TODO: changing from single host / esprit to multi host on ES & correct the default
ELASTIC_SEARCH_HOST = os.getenv('ELASTIC_SEARCH_HOST', 'http://localhost:9200') # remember the http:// or https://
ELASTICSEARCH_HOSTS = [{'host': 'localhost', 'port': 9200}, {'host': 'localhost', 'port': 9201}]
ELASTIC_SEARCH_VERIFY_CERTS = True # Verify the SSL certificate of the ES host. Set to False in dev.cfg to avoid having to configure your local certificates
# 2 sets of elasticsearch DB settings - index-per-project and index-per-type. Keep both for now so we can migrate.
# e.g. host:port/index/type/id
ELASTIC_SEARCH_DB = "doaj"
ELASTIC_SEARCH_TEST_DB = "doajtest"
# e.g. host:port/type/doc/id
ELASTIC_SEARCH_INDEX_PER_TYPE = True
INDEX_PER_TYPE_SUBSTITUTE = '_doc' # Migrated from esprit
ELASTIC_SEARCH_DB_PREFIX = "doaj-" # note: include the separator
ELASTIC_SEARCH_TEST_DB_PREFIX = "doajtest-"
INITIALISE_INDEX = True # whether or not to try creating the index and required index types on startup
ELASTIC_SEARCH_VERSION = "1.7.5"
ELASTIC_SEARCH_SNAPSHOT_REPOSITORY = None
ELASTIC_SEARCH_SNAPSHOT_TTL = 366
ES_TERMS_LIMIT = 1024
ES_READ_TIMEOUT = '2m'
#####################################################
# Elastic APM config (MUST be configured in env file)
# ~~->APM:Feature~~
ENABLE_APM = False
ELASTIC_APM = {
# Set required service name. Allowed characters:
# a-z, A-Z, 0-9, -, _, and space
'SERVICE_NAME': '',
# Use if APM Server requires a token
'SECRET_TOKEN': '',
# Set custom APM Server URL (default: http://localhost:8200)
'SERVER_URL': '',
}
###########################################
# Event handler
# use this to queue events asynchronously through kafka
EVENT_SEND_FUNCTION = "portality.events.kafka_producer.send_event"
# use this one to bypass kafka and process events immediately/synchronously
# EVENT_SEND_FUNCTION = "portality.events.shortcircuit.send_event"
KAFKA_BROKER = "kafka://localhost:9092"
KAFKA_EVENTS_TOPIC = "events"
KAFKA_BOOTSTRAP_SERVER = "localhost:9092"
###########################################
# Read Only Mode
#
# Use these options to place the application into READ ONLY mode
# This puts the UI into READ_ONLY mode
# ~~->ReadOnlyMode:Feature~~
READ_ONLY_MODE = False
# This puts the cron jobs into READ_ONLY mode
SCRIPTS_READ_ONLY_MODE = False
###########################################
# Feature Toggles
# ~~->OfflineMode:Feature~~
OFFLINE_MODE = False
# List the features we want to be active (API v1 and v2 remain with redirects to v3)
# ~~->API:Feature~~
FEATURES = ['api1', 'api2', 'api3', 'api4']
VALID_FEATURES = ['api1', 'api2', 'api3', 'api4']
########################################
# File Path and URL Path settings
# root of the git repo
ROOT_DIR = paths.rel2abs(__file__, "..")
# base path, to the directory where this settings file lives
BASE_FILE_PATH = paths.abs_dir_path(__file__)
BASE_URL = "https://doaj.org"
if BASE_URL.startswith('https://'):
BASE_DOMAIN = BASE_URL[8:]
elif BASE_URL.startswith('http://'):
BASE_DOMAIN = BASE_URL[7:]
else:
BASE_DOMAIN = BASE_URL
# ~~->API:Feature~~
BASE_API_URL = "https://doaj.org/api/"
API_CURRENT_BLUEPRINT_NAME = "api_v4" # change if upgrading API to new version and creating new view
# URL used for the journal ToC URL in the journal CSV export
# NOTE: must be the correct route as configured in view/doaj.py
# ~~->ToC:WebRoute~~
JOURNAL_TOC_URL_FRAG = BASE_URL + '/toc/'
# Used when generating external links, e.g. in the API docs
PREFERRED_URL_SCHEME = 'https'
# Whether the app is running behind a proxy, for generating URLs based on X-Forwarded-Proto
# ~~->ProxyFix:Framework~~
PROXIED = False
# directory to upload files to. MUST be full absolute path
# The default takes the directory above this, and then down in to "upload"
UPLOAD_DIR = os.path.join(ROOT_DIR, "upload")
UPLOAD_ASYNC_DIR = os.path.join(ROOT_DIR, "upload_async")
FAILED_ARTICLE_DIR = os.path.join(ROOT_DIR, "failed_articles")
# directory where reports are output
REPORTS_BASE_DIR = "/home/cloo/reports/"
##################################
# File store
# ~~->FileStore:Feature~~
# put this in your production.cfg, to store everything on S3:
# STORE_IMPL = "portality.store.StoreS3"
STORE_IMPL = "portality.store.StoreLocal"
STORE_SCOPE_IMPL = {
# Enable this by scope in order to have different scopes store via different storage implementations
# constants.STORE__SCOPE__PUBLIC_DATA_DUMP: "portality.store.StoreS3"
}
STORE_TMP_IMPL = "portality.store.TempStore"
STORE_LOCAL_DIR = paths.rel2abs(__file__, "..", "local_store", "main")
STORE_TMP_DIR = paths.rel2abs(__file__, "..", "local_store", "tmp")
STORE_LOCAL_EXPOSE = False # if you want to allow files in the local store to be exposed under /store/<path> urls. For dev only.
STORE_LOCAL_WRITE_BUFFER_SIZE = 16777216
STORE_TMP_WRITE_BUFFER_SIZE = 16777216
# containers (buckets in AWS) where various content will be stored
# These values are placeholders, and must be overridden in live deployment
# this prevents test environments from accidentally writing to the production buckets
STORE_ANON_DATA_CONTAINER = "doaj-anon-data-placeholder"
STORE_CACHE_CONTAINER = "doaj-data-cache-placeholder"
STORE_PUBLIC_DATA_DUMP_CONTAINER = "doaj-data-dump-placeholder"
STORE_HARVESTER_CONTAINER = "doaj-harvester"
# S3 credentials for relevant scopes
# ~~->S3:Technology~~
STORE_S3_SCOPES = {
"anon_data" : {
"aws_access_key_id" : "put this in your dev/test/production.cfg",
"aws_secret_access_key" : "put this in your dev/test/production.cfg"
},
"cache" : {
"aws_access_key_id" : "put this in your dev/test/production.cfg",
"aws_secret_access_key" : "put this in your dev/test/production.cfg"
},
# Used by the api_export script to dump data from the api
constants.STORE__SCOPE__PUBLIC_DATA_DUMP : {
"aws_access_key_id" : "put this in your dev/test/production.cfg",
"aws_secret_access_key" : "put this in your dev/test/production.cfg"
},
# Used to store harvester run logs to S3
"harvester" : {
"aws_access_key_id" : "put this in your dev/test/production.cfg",
"aws_secret_access_key" : "put this in your dev/test/production.cfg"
}
}
STORE_S3_MULTIPART_THRESHOLD = 5 * 1024**3 # 5GB
####################################
# CMS configuration
# paths where static content should be served from.
# * in the order you want them searched
# * relative to the portality directory
# ~~->CMS:DataStore~~
STATIC_PATHS = [
"static",
"../cms/assets"
]
# GitHub base url where static content can be edited by the DOAJ team (you can leave out the trailing slash)
#~~->GitHub:ExternalService~~
CMS_EDIT_BASE_URL = "https://github.com/DOAJ/doaj/edit/static_pages/cms"
# Where static files are served from - in case we need to serve a file
# from there ourselves using Flask instead of nginx (e.g. to support a
# legacy route to that file)
# Changing this will not change the actual folder that Flask serves
# static files from.
# http://flask.pocoo.org/snippets/102/
STATIC_DIR = os.path.join(ROOT_DIR, "portality", "static")
######################################
# Service Descriptive Text
SERVICE_NAME = "Directory of Open Access Journals"
###################################
# Cookie settings
# make this something secret in your overriding app.cfg
# ~~->Cookies:Feature~~
SECRET_KEY = "default-key"
# Consent Cookie and other Top-Level dismissable notes
# ~~->ConsentCookie:Feature~~
CONSENT_COOKIE_KEY = "doaj-cookie-consent"
# site notes, which can be configured to run any time with any content
# ~~-> SiteNote:Feature~~
SITE_NOTE_ACTIVE = False
SITE_NOTE_KEY = "doaj-site-note"
SITE_NOTE_SLEEP = 259200 # every 3 days
SITE_NOTE_COOKIE_VALUE = "You have seen our most recent site wide announcement"
SITE_NOTE_TEMPLATE = "doaj/site_note.html"
####################################
# Authorisation settings
# ~~->AuthNZ:Feature~~
# Can people register publicly? If false, only the superuser can create new accounts
PUBLIC_REGISTER = True
SUPER_USER_ROLE = "admin"
LOGIN_VIA_ACCOUNT_ID = True
# amount of time a reset token is valid for (86400 is 24 hours)
PASSWORD_RESET_TIMEOUT = 86400
# amount of time a reset token for a new account is valid for
PASSWORD_CREATE_TIMEOUT = PASSWORD_RESET_TIMEOUT * 14
#"api" top-level role is added to all acounts on creation; it can be revoked per account by removal of the role.
TOP_LEVEL_ROLES = [
"admin",
"publisher",
"editor",
"associate_editor",
"api",
"ultra_bulk_delete",
"preservation",
constants.ROLE_PUBLIC_DATA_DUMP,
constants.ROLE_PUBLISHER_JOURNAL_CSV
]
ROLE_MAP = {
"editor": [
"associate_editor", # note, these don't cascade, so we still need to list all the low-level roles
"edit_journal",
"edit_suggestion",
"edit_application", # todo: switchover from suggestion to application
"editor_area",
"assign_to_associate",
"list_group_journals",
"list_group_suggestions",
"read_notifications"
],
"associate_editor": [
"edit_journal",
"edit_suggestion",
"editor_area",
"read_notifications"
]
}
# If you change the reserved usernames, your data will likely need a migration to remove their
# existing use in the system.
SYSTEM_USERNAME = "system"
RESERVED_USERNAMES = [SYSTEM_USERNAME] # do not allow the creation of user accounts with this id
# Role map to destination route on login (when no other destination page is present)
# checked in order, if the user has the role in the first tuple position, they will
# be redirected to the endpoint in the second tuple position
ROLE_LOGIN_DESTINATIONS = [
("admin", "dashboard.top_todo"),
("editor", "editor.index"),
("associate_editor", "editor.index"),
("publisher", "publisher.index")
]
# if the user doesn't have one of the above roles, where should they be sent after login
DEFAULT_LOGIN_DESTINATION = "doaj.home"
####################################
# Email Settings
# ~~->Email:ExternalService
# Settings for Flask-Mail. Set in app.cfg
MAIL_SERVER = None # default localhost
MAIL_PORT = 25 # default 25
#MAIL_USE_TLS # default False
#MAIL_USE_SSL # default False
#MAIL_DEBUG # default app.debug
#MAIL_USERNAME # default None
#MAIL_PASSWORD # default None
#MAIL_DEFAULT_SENDER # default None
#MAIL_MAX_EMAILS # default None
#MAIL_SUPPRESS_SEND # default app.testing
ENABLE_EMAIL = True
ENABLE_PUBLISHER_EMAIL = True
ADMIN_NAME = "DOAJ"
ADMIN_EMAIL = "sysadmin@cottagelabs.com"
ADMINS = ["steve@cottagelabs.com", "mark@cottagelabs.com"]
MANAGING_EDITOR_EMAIL = "managing-editors@doaj.org"
CONTACT_FORM_ADDRESS = "feedback+contactform@doaj.org"
SCRIPT_TAG_DETECTED_EMAIL_RECIPIENTS = ["helpdesk@doaj.org"]
SYSTEM_EMAIL_FROM = 'helpdesk@doaj.org'
CC_ALL_EMAILS_TO = SYSTEM_EMAIL_FROM # DOAJ may get a dedicated inbox in the future
# Error logging via email
SUPPRESS_ERROR_EMAILS = False
ERROR_LOGGING_EMAIL = 'doaj.internal@gmail.com'
ERROR_MAIL_HOSTNAME = 'smtp.mailgun.org'
ERROR_MAIL_USERNAME = None
ERROR_MAIL_PASSWORD = None
# Reports email recipient
REPORTS_EMAIL_TO = ["helpdesk@doaj.org"]
########################################
# workflow email notification settings
# ~~->WorkflowNotifications:Feature~~
MAN_ED_IDLE_WEEKS = 4 # weeks before an application is considered reminder-worthy
ED_IDLE_WEEKS = 3 # weeks before the editor is warned about idle applications in their group
ASSOC_ED_IDLE_DAYS = 10
ASSOC_ED_IDLE_WEEKS = 3
# Which statuses the notification queries should be filtered to show
# ~~-> ApplicationStatuses:Config~~
MAN_ED_NOTIFICATION_STATUSES = [
constants.APPLICATION_STATUS_PENDING,
constants.APPLICATION_STATUS_IN_PROGRESS, constants.APPLICATION_STATUS_COMPLETED,
constants.APPLICATION_STATUS_ON_HOLD
]
ED_NOTIFICATION_STATUSES = [
constants.APPLICATION_STATUS_PENDING,
constants.APPLICATION_STATUS_IN_PROGRESS,
constants.APPLICATION_STATUS_COMPLETED
]
ASSOC_ED_NOTIFICATION_STATUSES = [
constants.APPLICATION_STATUS_PENDING,
constants.APPLICATION_STATUS_IN_PROGRESS
]
###################################
# status endpoint configuration
# ~~->StatusEndpoint:Feature~~
# /status endpoint connection to all app machines
APP_MACHINES_INTERNAL_IPS = [HOST + ':' + str(PORT)] # This should be set in production.cfg (or dev.cfg etc)
###########################################
# Background Jobs settings
# ~~->Huey:Technology~~
# ~~->Redis:Technology~~
# ~~->BackgroundTasks:Feature~~
# huey/redis settings
HUEY_REDIS_HOST = os.getenv('HUEY_REDIS_HOST', '127.0.0.1')
HUEY_REDIS_PORT = os.getenv('HUEY_REDIS_PORT', 6379)
HUEY_EAGER = False
# Crontab for never running a job - February 31st (use to disable tasks)
CRON_NEVER = {"month": "2", "day": "31", "day_of_week": "*", "hour": "*", "minute": "*"}
# Additional Logging for scheduled JournalCSV
EXTRA_JOURNALCSV_LOGGING = False
# Crontab schedules must be for unique times to avoid delays due to perceived race conditions
HUEY_SCHEDULE = {
"sitemap": {"month": "*", "day": "*", "day_of_week": "*", "hour": "8", "minute": "0"},
"reporting": {"month": "*", "day": "1", "day_of_week": "*", "hour": "0", "minute": "0"},
"journal_csv": {"month": "*", "day": "*", "day_of_week": "*", "hour": "*", "minute": "20"},
"read_news": {"month": "*", "day": "*", "day_of_week": "*", "hour": "*", "minute": "30"},
"article_cleanup_sync": {"month": "*", "day": "2", "day_of_week": "*", "hour": "0", "minute": "0"},
"async_workflow_notifications": {"month": "*", "day": "*", "day_of_week": "1", "hour": "5", "minute": "0"},
"request_es_backup": {"month": "*", "day": "*", "day_of_week": "*", "hour": "6", "minute": "0"},
"check_latest_es_backup": {"month": "*", "day": "*", "day_of_week": "*", "hour": "9", "minute": "0"},
"prune_es_backups": {"month": "*", "day": "*", "day_of_week": "*", "hour": "9", "minute": "15"},
"public_data_dump": {"month": "*", "day": "*/6", "day_of_week": "*", "hour": "10", "minute": "0"},
"harvest": {"month": "*", "day": "*", "day_of_week": "*", "hour": "5", "minute": "30"},
"anon_export": {"month": "*", "day": "10", "day_of_week": "*", "hour": "6", "minute": "30"},
"old_data_cleanup": {"month": "*", "day": "12", "day_of_week": "*", "hour": "6", "minute": "30"},
"monitor_bgjobs": {"month": "*", "day": "*/6", "day_of_week": "*", "hour": "10", "minute": "0"},
"find_discontinued_soon": {"month": "*", "day": "*", "day_of_week": "*", "hour": "0", "minute": "3"},
"datalog_journal_added_update": {"month": "*", "day": "*", "day_of_week": "*", "hour": "*", "minute": "*/30"},
"article_bulk_create": {"month": "*", "day": "*", "day_of_week": "*", "hour": "*", "minute": "20"},
}
HUEY_TASKS = {
"ingest_articles": {"retries": 10, "retry_delay": 15},
"preserve": {"retries": 0, "retry_delay": 15},
"application_autochecks": {"retries": 0, "retry_delay": 15},
"journal_autochecks": {"retries": 0, "retry_delay": 15}
}
####################################
# publisher area settings
# the earliest date accepted on the publisher's 'enter article metadata' form.
# code will default to 15 years before current year if commented out.
# ~~->ArticleMetadata:Page~~
METADATA_START_YEAR = 1960
# tick (on toc) and doaj seal settings
# ~~->Tick:Feature~~
TICK_THRESHOLD = '2014-03-19T00:00:00Z'
# ~~->UpdateRequests:Feature~~
UPDATE_REQUESTS_SHOW_OLDEST = "2018-01-01T00:00:00Z"
##############################################
# Elasticsearch Mappings
# ~~->Elasticsearch:Technology~~
FACET_FIELD = ".exact"
# an array of DAO classes from which to retrieve the type-specific ES mappings
# to be loaded into the index during initialisation.
ELASTIC_SEARCH_MAPPINGS = [
"portality.models.Journal", # ~~->Journal:Model~~
"portality.models.Application", # ~~->Application:Model~~
"portality.models.DraftApplication", # ~~-> DraftApplication:Model~~
"portality.models.harvester.HarvestState", # ~~->HarvestState:Model~~
"portality.models.background.BackgroundJob", # ~~-> BackgroundJob:Model~~
"portality.models.autocheck.Autocheck" # ~~-> Autocheck:Model~~
]
# Map from dataobj coercion declarations to ES mappings
# ~~->DataObj:Library~~
# ~~->Seamless:Library~~
DATAOBJ_TO_MAPPING_DEFAULTS = {
"unicode": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"str": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"unicode_upper": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"unicode_lower": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"isolang": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"isolang_2letter_strict": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"isolang_2letter_lax": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"country_code": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"currency_code_strict": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"currency_code_lax": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"issn": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"url": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
# "index": False,
"store": True
}
}
},
"utcdatetimemicros": {
"type": "date",
"format": "date_optional_time"
},
"utcdatetime": {
"type": "date",
"format": "date_optional_time"
},
"bool": {
"type": "boolean"
},
"integer": {
"type": "long"
},
"bigenddate": {
"type": "date",
"format": "date_optional_time"
},
"year": {
"type": "date",
"format": "year"
}
}
# Extension Map from dataobj coercion declarations to ES mappings.
# This is useful when some extensions required for some objects additional to defaults.
# ~~->DataObj:Library~~
# ~~->Seamless:Library~~
DATAOBJ_TO_MAPPING_COPY_TO_EXTENSIONS = {
"unicode": {"copy_to": ["all_meta"]},
"str": {"copy_to": ["all_meta"]},
"unicode_upper": {"copy_to": ["all_meta"]},
"unicode_lower": {"copy_to": ["all_meta"]},
"issn": {"copy_to": ["all_meta"]},
"url": {"copy_to": ["all_meta"]}
}
# TODO: we may want a big-type and little-type setting
DEFAULT_INDEX_SETTINGS = \
{
'number_of_shards': 4,
'number_of_replicas': 1
}
DEFAULT_DYNAMIC_MAPPING = {
'dynamic_templates': [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
#"normalizer": "lowercase"
}
}
}
}
}
]
}
# LEGACY MAPPINGS
# a dict of the ES mappings. identify by name, and include name as first object name
# and identifier for how non-analyzed fields for faceting are differentiated in the mappings
MAPPINGS = {
'account': { #~~->Account:Model~~
# 'aliases': {
# 'account': {}
# },
'mappings': DEFAULT_DYNAMIC_MAPPING,
'settings': DEFAULT_INDEX_SETTINGS
}
}
# MAPPINGS['article'] = {'article': DEFAULT_DYNAMIC_MAPPING} #~~->Article:Model~~
# MAPPINGS['upload'] = {'upload': DEFAULT_DYNAMIC_MAPPING} #~~->Upload:Model~~
# MAPPINGS['cache'] = {'cache': DEFAULT_DYNAMIC_MAPPING} #~~->Cache:Model~~
# MAPPINGS['lcc'] = {'lcc': DEFAULT_DYNAMIC_MAPPING} #~~->LCC:Model~~
# MAPPINGS['editor_group'] = {'editor_group': DEFAULT_DYNAMIC_MAPPING} #~~->EditorGroup:Model~~
# MAPPINGS['news'] = {'news': DEFAULT_DYNAMIC_MAPPING} #~~->News:Model~~
# MAPPINGS['lock'] = {'lock': DEFAULT_DYNAMIC_MAPPING} #~~->Lock:Model~~
# MAPPINGS['provenance'] = {'provenance': DEFAULT_DYNAMIC_MAPPING} #~~->Provenance:Model~~
# MAPPINGS['preserve'] = {'preserve': DEFAULT_DYNAMIC_MAPPING} #~~->Preservation:Model~~
MAPPINGS['article'] = MAPPINGS["account"] #~~->Article:Model~~
MAPPINGS['upload'] = MAPPINGS["account"] #~~->Upload:Model~~
MAPPINGS['bulk_articles'] = MAPPINGS["account"] #~~->BulkArticles:Model~~
MAPPINGS['cache'] = MAPPINGS["account"] #~~->Cache:Model~~
MAPPINGS['lcc'] = MAPPINGS["account"] #~~->LCC:Model~~
MAPPINGS['editor_group'] = MAPPINGS["account"] #~~->EditorGroup:Model~~
MAPPINGS['news'] = MAPPINGS["account"] #~~->News:Model~~
MAPPINGS['lock'] = MAPPINGS["account"] #~~->Lock:Model~~
MAPPINGS['provenance'] = MAPPINGS["account"] #~~->Provenance:Model~~
MAPPINGS['preserve'] = MAPPINGS["account"] #~~->Preservation:Model~~
MAPPINGS['notification'] = MAPPINGS["account"] #~~->Notification:Model~~
#########################################
# Query Routes
# ~~->Query:WebRoute~~
QUERY_ROUTE = {
"query" : {
# ~~->PublicJournalQuery:Endpoint~~
"journal" : {
"auth" : False,
"role" : None,
"query_validators" : ["non_public_fields_validator", "public_query_validator"],
"query_filters" : ["only_in_doaj", "last_update_fallback", "search_all_meta"],
"result_filters" : ["public_result_filter"],
"dao" : "portality.models.Journal", # ~~->Journal:Model~~
"required_parameters" : {"ref" : ["ssw", "public_journal", "subject_page"]}
},
# ~~->PublicArticleQuery:Endpoint~~
"article" : {
"auth" : False,
"role" : None,
"query_validators" : ["non_public_fields_validator", "public_query_validator"],
"query_filters" : ["only_in_doaj"],
"result_filters" : ["public_result_filter"],
"dao" : "portality.models.Article", # ~~->Article:Model~~
"required_parameters" : {"ref" : ["public_article", "toc", "subject_page"]}
},
# back-compat for fixed query widget
# ~~->PublicJournalArticleQuery:Endpoint~~
"journal,article" : {
"auth" : False,
"role" : None,
"query_validators" : ["non_public_fields_validator", "public_query_validator"],
"query_filters" : ["only_in_doaj", "strip_facets", "es_type_fix", "journal_article_filter"],
"result_filters" : ["public_result_filter", "add_fqw_facets", "fqw_back_compat"],
"dao" : "portality.models.JournalArticle", # ~~->JournalArticle:Model~~
"required_parameters" : {"ref" : ["fqw"]}
}
},
"publisher_query" : {
# ~~->PublisherJournalQuery:Endpoint~~
"journal" : {
"auth" : True,
"role" : "publisher",
"query_validators" : ["non_public_fields_validator"],
"query_filters" : ["owner", "only_in_doaj", "search_all_meta"],
"result_filters" : ["publisher_result_filter"],
"dao" : "portality.models.Journal" # ~~->Journal:Model~~
},
# ~~->PublisherApplicationQuery:Endpoint~~
"applications" : {
"auth" : True,
"role" : "publisher",
"query_validators" : ["non_public_fields_validator"],
"query_filters" : ["owner", "not_update_request", "search_all_meta"],
"result_filters" : ["publisher_result_filter"],
"dao" : "portality.models.AllPublisherApplications" # ~~->AllPublisherApplications:Model~~
},
# ~~->PublisherUpdateRequestsQuery:Endpoint~~
"update_requests" : {
"auth" : True,
"role" : "publisher",
"query_validators" : ["non_public_fields_validator"],
"query_filters" : ["owner", "update_request", "search_all_meta"],
"result_filters" : ["publisher_result_filter"],
"dao" : "portality.models.Application" # ~~->Application:Model~~
}
},
"admin_query" : {
# ~~->AdminJournalQuery:Endpoint~~
"journal" : {
"auth" : True,
"role" : "admin",
"dao" : "portality.models.Journal" # ~~->Journal:Model~~
},
# ~~->AdminApplicationQuery:Endpoint~~
"suggestion" : {
"auth" : True,
"role" : "admin",
"query_filters" : ["not_update_request"],
"dao" : "portality.models.Application" # ~~->Application:Model~~
},
# ~~->AdminUpdateRequestQuery:Endpoint~~
"update_requests": {
"auth": True,
"role": "admin",
"query_filters" : ["update_request"],
"dao": "portality.models.Application" # ~~->Application:Model~~
},
# ~~->AdminEditorGroupQuery:Endpoint~~
"editor,group" : {
"auth" : True,
"role" : "admin",
"dao" : "portality.models.EditorGroup" # ~~->EditorGroup:Model~~
},
# ~~->AdminAccountQuery:Endpoint~~
"account" : {
"auth" : True,
"role" : "admin",
"dao" : "portality.models.Account" # ~~->Account:Model~~
},
# ~~->AdminJournalArticleQuery:Endpoint~~
"journal,article" : {
"auth" : True,
"role" : "admin",
"dao" : "portality.models.search.JournalArticle" # ~~->JournalArticle:Model~~
},
# ~~->AdminBackgroundJobQuery:Endpoint~~
"background,job" : {
"auth" : True,
"role" : "admin",
"dao" : "portality.models.BackgroundJob" # ~~->BackgroundJob:Model~~
},
# ~~->APINotificationQuery:Endpoint~~
"notifications" : {
"auth" : False,
"role" : "admin",
"dao" : "portality.models.Notification", # ~~->Notification:Model~~
"required_parameters" : None
}
},
"associate_query" : {
# ~~->AssEdJournalQuery:Endpoint~~
"journal" : {
"auth" : True,
"role" : "associate_editor",
"query_validators" : ["non_public_fields_validator"],
"query_filters" : ["associate", "search_all_meta"],
"dao" : "portality.models.Journal" # ~~->Journal:Model~~
},
# ~~->AssEdApplicationQuery:Endpoint~~
"suggestion" : {
"auth" : True,
"role" : "associate_editor",
"query_validators" : ["non_public_fields_validator"],
"query_filters" : ["associate", "search_all_meta"],
"dao" : "portality.models.Application" # ~~->Application:Model~~
}
},
"editor_query" : {
# ~~->EditorJournalQuery:Endpoint~~
"journal" : {
"auth" : True,
"role" : "editor",
"query_validators" : ["non_public_fields_validator"],
"query_filters" : ["editor", "search_all_meta"],
"dao" : "portality.models.Journal" # ~~->Journal:Model~~
},
# ~~->EditorApplicationQuery:Endpoint~~
"suggestion" : {
"auth" : True,
"role" : "editor",
"query_validators" : ["non_public_fields_validator"],
"query_filters" : ["editor", "search_all_meta"],
"dao" : "portality.models.Application" # ~~->Application:Model~~
}
},
"api_query" : {
# ~~->APIArticleQuery:Endpoint~~
"article" : {
"auth" : False,
"role" : None,
"query_filters" : ["only_in_doaj", "public_source"],
"dao" : "portality.models.Article", # ~~->Article:Model~~
"required_parameters" : None,
"keepalive" : "10m"
},
# ~~->APIJournalQuery:Endpoint~~
"journal" : {
"auth" : False,
"role" : None,
"query_validators": ["non_public_fields_validator"],
"query_filters" : ["only_in_doaj", "public_source", "search_all_meta"],
"dao" : "portality.models.Journal", # ~~->Journal:Model~~
"required_parameters" : None
},
# ~~->APIApplicationQuery:Endpoint~~
"application" : {
"auth" : True,
"role" : None,
"query_validators": ["non_public_fields_validator"],
"query_filters" : ["owner", "private_source", "search_all_meta"],
"dao" : "portality.models.Suggestion", # ~~->Application:Model~~
"required_parameters" : None
}
},
"dashboard_query": {
# ~~->APINotificationQuery:Endpoint~~
"notifications" : {
"auth" : False,
"role" : "read_notifications",
"query_filters" : ["who_current_user"], # ~~-> WhoCurrentUser:Query
"dao" : "portality.models.Notification", # ~~->Notification:Model~~
"required_parameters" : None
}
}
}
QUERY_FILTERS = {
# sanitisers
"public_query_validator" : "portality.lib.query_filters.public_query_validator",
"non_public_fields_validator" : "portality.lib.query_filters.non_public_fields_validator",
# query filters
"only_in_doaj" : "portality.lib.query_filters.only_in_doaj",
"owner" : "portality.lib.query_filters.owner",
"update_request" : "portality.lib.query_filters.update_request",
"associate" : "portality.lib.query_filters.associate",
"editor" : "portality.lib.query_filters.editor",
"strip_facets" : "portality.lib.query_filters.strip_facets",
"es_type_fix" : "portality.lib.query_filters.es_type_fix",
"last_update_fallback" : "portality.lib.query_filters.last_update_fallback",
"not_update_request" : "portality.lib.query_filters.not_update_request",
"who_current_user" : "portality.lib.query_filters.who_current_user", # ~~-> WhoCurrentUser:Query ~~
"search_all_meta" : "portality.lib.query_filters.search_all_meta", # ~~-> SearchAllMeta:Query ~~
"journal_article_filter" : "portality.lib.query_filters.journal_article_filter", # ~~-> JournalArticleFilter:Query ~~
# result filters
"public_result_filter": "portality.lib.query_filters.public_result_filter",
"publisher_result_filter": "portality.lib.query_filters.publisher_result_filter",
"add_fqw_facets" : "portality.lib.query_filters.add_fqw_facets",
"fqw_back_compat" : "portality.lib.query_filters.fqw_back_compat",
# source filters
"private_source": "portality.lib.query_filters.private_source",
"public_source": "portality.lib.query_filters.public_source",
}
# Exclude the fields that doesn't want to be searched by public queries
# This is part of non_public_fields_validator.
PUBLIC_QUERY_VALIDATOR__EXCLUDED_FIELDS = [
"admin.notes.note",
"admin.notes.id",
"admin.notes.author_id"
]
ADMIN_NOTES_INDEX_ONLY_FIELDS = {
"all_meta" : {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
"store": True
}
}
}
}
ADMIN_NOTES_SEARCH_MAPPING = {
"admin.notes.id": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
"store": True
}
}
},
"admin.notes.note": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
"store": True
}
}
},
"admin.notes.author_id": {
"type": "text",
"fields": {
"exact": {
"type": "keyword",
"store": True
}
}
}
}
####################################################
# Autocomplete
# ~~->BibJSON:Model~~
AUTOCOMPLETE_ADVANCED_FIELD_MAPS = {
"bibjson.publisher.name" : "index.publisher_ac",
"bibjson.institution.name" : "index.institution_ac"
}