Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor ColdFront settings #264

Merged
merged 37 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7048714
Refactor ColdFront settings.
aebruno Feb 27, 2021
93d9449
Add local settings overrides and better env file parsing.
aebruno Feb 28, 2021
9fe6f53
Rename environment variables
aebruno Feb 28, 2021
057bfef
Remove not used
aebruno Feb 28, 2021
8849d80
Remove not used
aebruno Feb 28, 2021
6944ee0
Clean up handling of ondemand url if not found
aebruno Feb 28, 2021
8c92a16
Merge ood config into core. Cleanup ood url handling
aebruno Feb 28, 2021
60cef81
Add config settings via environment variables
aebruno Feb 28, 2021
1280319
Default creating db in current working directory
aebruno Feb 28, 2021
6818cab
Fix circular import
aebruno Feb 28, 2021
48f766d
Remove unused configs
aebruno Feb 28, 2021
44156ae
Add documenation on installation and configuration
aebruno Mar 1, 2021
266a351
Add more generic openid plugin
aebruno Mar 1, 2021
ce58ed8
Add BASE_DIR
aebruno Mar 1, 2021
561510a
Fix timezone warning
aebruno Mar 1, 2021
f61b993
Fix docs
aebruno Mar 1, 2021
ff0bb95
Require email settings only if enabled. Remove bad defaults
aebruno Mar 1, 2021
f93488c
Add import check and better error message
aebruno Mar 1, 2021
5e9d971
Add docs about required packages
aebruno Mar 1, 2021
d1b4060
Add upgrading docs
aebruno Mar 1, 2021
444e304
Minor doc updates
aebruno Mar 1, 2021
4a55373
Fix plugin readmes
aebruno Mar 1, 2021
08fade0
Clean up readme
aebruno Mar 1, 2021
388affb
Add link to upgrading
aebruno Mar 1, 2021
3213f08
Remove redundant verbiage
aebruno Mar 1, 2021
98dd76a
Fix default value
aebruno Mar 1, 2021
4542cab
Fix typos
aebruno Mar 1, 2021
1228f61
Bump version add required python
aebruno Mar 1, 2021
f425a3b
Update changelog
aebruno Mar 1, 2021
91758ac
Add environment variables for custom templates and static files
aebruno Mar 2, 2021
b3f0381
Remove install demo
aebruno Mar 2, 2021
eb6bfa7
Merge intro into index
aebruno Mar 2, 2021
41cc86d
Add plugin to control order of top level nav
aebruno Mar 2, 2021
b841b03
Change name
aebruno Mar 2, 2021
3f56356
Add docs on custom branding
aebruno Mar 2, 2021
4883533
Add start to deployment docs
aebruno Mar 2, 2021
71723ae
Minor tweaks
aebruno Mar 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ coldfront.db
*.code-workspace
.vscode
db.json
.env
28 changes: 8 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,18 @@ Python and released under the GPLv3 license.
- Integration with 3rd party systems for automation and access control
- Center director approval system and annual project reviews

## Plug-in Documentation
- [Slurm](coldfront/plugins/slurm)
- [FreeIPA](coldfront/plugins/freeipa)
- [LDAP](coldfront/plugins/ldap_user_search)
- [Mokey/Hydra OpenID Connect](coldfront/plugins/mokey_oidc)
- [iQuota](coldfront/plugins/iquota)
- [Open OnDemand](coldfront/plugins/ondemand)
- [Open XDMoD](coldfront/plugins/xdmod)
- [System Monitor](coldfront/plugins/system_monitor) (example of ways to integrate your own plug-ins)
## Documentation


## Installation

[Quick Start Instructions](docs/pages/quickstart.md)


## ColdFront Demos

[Animated gifs demonstrating ColdFront features](docs/pages/demos.md)
For more information on installing and using ColdFront see our [documentation here](https://coldfront.readthedocs.io)

## Contact Information
If you would like a live demo followed by QA, please contact us at ccr-coldfront-admin-list@listserv.buffalo.edu. You can also contact us for general inquiries and installation troubleshooting.
If you would like a live demo followed by QA, please contact us at
ccr-coldfront-admin-list@listserv.buffalo.edu. You can also contact us for
general inquiries and installation troubleshooting.

If you would like to join our mailing list to receive news and updates, please send an email to listserv@listserv.buffalo.edu with no subject, and the following command in the body of the message:
If you would like to join our mailing list to receive news and updates, please
send an email to listserv@listserv.buffalo.edu with no subject, and the
following command in the body of the message:

subscribe ccr-open-coldfront-list@listserv.buffalo.edu first_name last_name

Expand Down
29 changes: 29 additions & 0 deletions coldfront/config/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from coldfront.config.env import ENV
from coldfront.config.base import INSTALLED_APPS, AUTHENTICATION_BACKENDS, TEMPLATES

#------------------------------------------------------------------------------
# ColdFront default authentication settings
#------------------------------------------------------------------------------
AUTHENTICATION_BACKENDS += [
'django.contrib.auth.backends.ModelBackend',
]

LOGIN_URL = '/user/login'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

SU_LOGIN_CALLBACK = "coldfront.core.utils.common.su_login_callback"
SU_LOGOUT_REDIRECT_URL = "/admin/auth/user/"

SESSION_COOKIE_AGE = 60 * 15
SESSION_SAVE_EVERY_REQUEST = True
SESSION_COOKIE_SAMESITE = 'Strict'
SESSION_COOKIE_SECURE = True

#------------------------------------------------------------------------------
# Enable administrators to login as other users
#------------------------------------------------------------------------------
if ENV.bool('ENABLE_SU', default=True):
AUTHENTICATION_BACKENDS += ['django_su.backends.SuBackend',]
INSTALLED_APPS.insert(0, 'django_su')
TEMPLATES[0]['OPTIONS']['context_processors'].extend(['django_su.context_processors.is_su', ])
125 changes: 125 additions & 0 deletions coldfront/config/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""
Base Django settings for ColdFront project.
"""
import os
import coldfront
from django.core.management.utils import get_random_secret_key
from coldfront.config.env import ENV, PROJECT_ROOT

#------------------------------------------------------------------------------
# Base Django config for ColdFront
#------------------------------------------------------------------------------
VERSION = coldfront.VERSION
BASE_DIR = PROJECT_ROOT()
ALLOWED_HOSTS = ENV.list('ALLOWED_HOSTS', default=['*'])
DEBUG = ENV.bool('DEBUG', default=False)
WSGI_APPLICATION = 'coldfront.config.wsgi.application'
ROOT_URLCONF = 'coldfront.config.urls'

SECRET_KEY = ENV.str('SECRET_KEY', default='')
if len(SECRET_KEY) == 0:
SECRET_KEY = get_random_secret_key()

#------------------------------------------------------------------------------
# Locale settings
#------------------------------------------------------------------------------
LANGUAGE_CODE = ENV.str('LANGUAGE_CODE', default='en-us')
TIME_ZONE = ENV.str('TIME_ZONE', default='America/New_York')
USE_I18N = True
USE_L10N = True
USE_TZ = True

#------------------------------------------------------------------------------
# Django Apps
#------------------------------------------------------------------------------
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
]

# Additional Apps
INSTALLED_APPS += [
'crispy_forms',
'sslserver',
'django_q',
'simple_history',
]

# ColdFront Apps
INSTALLED_APPS += [
'coldfront.core.user',
'coldfront.core.field_of_science',
'coldfront.core.utils',
'coldfront.core.portal',
'coldfront.core.project',
'coldfront.core.resource',
'coldfront.core.allocation',
'coldfront.core.grant',
'coldfront.core.publication',
'coldfront.core.research_output',
]

#------------------------------------------------------------------------------
# Django Middleware
#------------------------------------------------------------------------------
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'simple_history.middleware.HistoryRequestMiddleware',
]

#------------------------------------------------------------------------------
# Django authentication backend. See auth.py
#------------------------------------------------------------------------------
AUTHENTICATION_BACKENDS = []

#------------------------------------------------------------------------------
# Django template and site settings
#------------------------------------------------------------------------------
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
PROJECT_ROOT('site/templates'),
'/usr/share/coldfront/site/templates',
PROJECT_ROOT('coldfront/templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django_settings_export.settings_export',
],
},
},
]

CRISPY_TEMPLATE_PACK = 'bootstrap4'
SETTINGS_EXPORT = []

STATIC_URL = '/static/'
STATIC_ROOT = PROJECT_ROOT('static_root')
STATICFILES_DIRS = [
PROJECT_ROOT('coldfront/static'),
]

# Add local site static files
if os.path.isdir(PROJECT_ROOT('site/static')):
STATICFILES_DIRS.insert(0, PROJECT_ROOT('site/static'))

# Add system site static files
if os.path.isdir('/usr/share/coldfront/site/static'):
STATICFILES_DIRS.insert(0, '/usr/share/coldfront/site/static')
76 changes: 76 additions & 0 deletions coldfront/config/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from coldfront.config.base import SETTINGS_EXPORT
from coldfront.config.env import ENV

#------------------------------------------------------------------------------
# Advanced ColdFront configurations
#------------------------------------------------------------------------------

#------------------------------------------------------------------------------
# General Center Information
#------------------------------------------------------------------------------
CENTER_NAME = ENV.str('CENTER_NAME', default='HPC Resources')
CENTER_HELP_URL = ENV.str('CENTER_HELP_URL', default='')
CENTER_PROJECT_RENEWAL_HELP_URL = ENV.str('CENTER_PROJECT_RENEWAL_HELP_URL', default='')
CENTER_BASE_URL = ENV.str('CENTER_BASE_URL', default='')

#------------------------------------------------------------------------------
# Enable Project Review
#------------------------------------------------------------------------------
PROJECT_ENABLE_PROJECT_REVIEW = ENV.bool('PROJECT_ENABLE_PROJECT_REVIEW', default=True)

#------------------------------------------------------------------------------
# Allocation related
#------------------------------------------------------------------------------
ALLOCATION_ENABLE_ALLOCATION_RENEWAL = ENV.bool('ALLOCATION_ENABLE_ALLOCATION_RENEWAL', default=True)
ALLOCATION_FUNCS_ON_EXPIRE = ['coldfront.core.allocation.utils.test_allocation_function', ]

# This is in days
ALLOCATION_DEFAULT_ALLOCATION_LENGTH = ENV.int('ALLOCATION_DEFAULT_ALLOCATION_LENGTH', default=365)


#------------------------------------------------------------------------------
# Allow user to select account name for allocation
#------------------------------------------------------------------------------
ALLOCATION_ACCOUNT_ENABLED = ENV.bool('ALLOCATION_ACCOUNT_ENABLED', default=False)
ALLOCATION_ACCOUNT_MAPPING = ENV.dict('ALLOCATION_ACCOUNT_MAPPING', default={})

SETTINGS_EXPORT += [
'ALLOCATION_ACCOUNT_ENABLED'
]

ADMIN_COMMENTS_SHOW_EMPTY = ENV.bool('ADMIN_COMMENTS_SHOW_EMPTY', default=True)

#------------------------------------------------------------------------------
# Enable invoice functionality
#------------------------------------------------------------------------------
INVOICE_ENABLED = ENV.bool('INVOICE_ENABLED', default=True)
# Override default 'Pending Payment' status
INVOICE_DEFAULT_STATUS = ENV.str('INVOICE_DEFAULT_STATUS', default='New')

#------------------------------------------------------------------------------
# Enable Open OnDemand integration
#------------------------------------------------------------------------------
ONDEMAND_URL = ENV.str('ONDEMAND_URL', default=None)

#------------------------------------------------------------------------------
# Default Strings. Override these in local_settings.py
#------------------------------------------------------------------------------
LOGIN_FAIL_MESSAGE = ENV.str('LOGIN_FAIL_MESSAGE', '')

EMAIL_DIRECTOR_PENDING_PROJECT_REVIEW_EMAIL = """
You recently applied for renewal of your account, however, to date you have not entered any publication nor grant info in the ColdFront system. I am reluctant to approve your renewal without understanding why. If there are no relevant publications or grants yet, then please let me know. If there are, then I would appreciate it if you would take the time to enter the data (I have done it myself and it took about 15 minutes). We use this information to help make the case to the university for continued investment in our department and it is therefore important that faculty enter the data when appropriate. Please email xxx-helpexample.com if you need technical assistance.

As always, I am available to discuss any of this.

Best regards
Director


xxx@example.edu
Phone: (xxx) xxx-xxx
"""

ACCOUNT_CREATION_TEXT = '''University faculty can submit a help ticket to request an account.
Please see <a href="#">instructions on our website</a>. Staff, students, and external collaborators must
request an account through a university faculty member.
'''
54 changes: 54 additions & 0 deletions coldfront/config/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
from coldfront.config.env import ENV

#------------------------------------------------------------------------------
# Database settings
#------------------------------------------------------------------------------
# Set this using the DB_URL env variable. Defaults to sqlite.
#
# Examples:
#
# MariaDB:
# DB_URL=mysql://user:password@127.0.0.1:3306/database
#
# Postgresql:
# DB_URL=psql://user:password@127.0.0.1:8458/database
#------------------------------------------------------------------------------
DATABASES = {
'default': ENV.db_url(
var='DB_URL',
default='sqlite:///'+os.path.join(os.getcwd(), 'coldfront.db')
)
}


#------------------------------------------------------------------------------
# Custom Database settings
#------------------------------------------------------------------------------
# You can also override this manually in local_settings.py, for example:
#
# NOTE: For mysql you need to: pip install mysqlclient
#
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': 'coldfront',
# 'USER': '',
# 'PASSWORD': '',
# 'HOST': 'localhost',
# 'PORT': '',
# },
# }
#
# NOTE: For postgresql you need to: pip install psycopg2
#
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': 'coldfront',
# 'USER': '',
# 'PASSWORD': '',
# 'HOST': 'localhost',
# 'PORT': '5432',
# },
# }
23 changes: 23 additions & 0 deletions coldfront/config/email.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from coldfront.config.env import ENV

#------------------------------------------------------------------------------
# Email/Notification settings
#------------------------------------------------------------------------------
EMAIL_ENABLED = ENV.bool('EMAIL_ENABLED', default=False)
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = ENV.str('EMAIL_HOST', default='localhost')
EMAIL_PORT = ENV.int('EMAIL_PORT', default=25)
EMAIL_HOST_USER = ENV.str('EMAIL_HOST_USER', default='')
EMAIL_HOST_PASSWORD = ENV.str('EMAIL_HOST_PASSWORD', default='')
EMAIL_USE_TLS = ENV.bool('EMAIL_USE_TLS', default=False)
EMAIL_TIMEOUT = ENV.int('EMAIL_TIMEOUT', default=3)
EMAIL_SUBJECT_PREFIX = ENV.str('EMAIL_SUBJECT_PREFIX', default='[ColdFront]')
EMAIL_ADMIN_LIST = ENV.list('EMAIL_ADMIN_LIST')
EMAIL_SENDER = ENV.str('EMAIL_SENDER')
EMAIL_TICKET_SYSTEM_ADDRESS = ENV.str('EMAIL_TICKET_SYSTEM_ADDRESS')
EMAIL_DIRECTOR_EMAIL_ADDRESS = ENV.str('EMAIL_DIRECTOR_EMAIL_ADDRESS')
EMAIL_PROJECT_REVIEW_CONTACT = ENV.str('EMAIL_PROJECT_REVIEW_CONTACT')
EMAIL_DEVELOPMENT_EMAIL_LIST = ENV.list('EMAIL_DEVELOPMENT_EMAIL_LIST')
EMAIL_OPT_OUT_INSTRUCTION_URL = ENV.str('EMAIL_OPT_OUT_INSTRUCTION_URL', default='')
EMAIL_ALLOCATION_EXPIRING_NOTIFICATION_DAYS = ENV.list('EMAIL_ALLOCATION_EXPIRING_NOTIFICATION_DAYS', cast=int, default=[7, 14, 30])
EMAIL_SIGNATURE = ENV.str('EMAIL_SIGNATURE', default='', multiline=True)
22 changes: 22 additions & 0 deletions coldfront/config/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import environ

ENV = environ.Env()
PROJECT_ROOT = environ.Path(__file__) - 3

# Default paths to environment files
env_paths = [
PROJECT_ROOT.path('.env'),
environ.Path('/etc/coldfront/coldfront.env'),
]

if ENV.str('COLDFRONT_ENV', default='') != '':
env_paths.insert(0, environ.Path(ENV.str('COLDFRONT_ENV')))

# Read in any environment files
for e in env_paths:
try:
e.file('')
ENV.read_env(e())
except FileNotFoundError:
pass

Loading