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

Added features #617

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
venv/
*.pyc
__pycache__/
coldfront.db
coldfront.egg-info
.gitignore
script-export-coldfront/
nginx/
docs/
45 changes: 45 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ColdFront config
#DEBUG=True
#DJANGO_SUPERUSER_USERNAME='superuser'
#DJANGO_SUPERUSER_EMAIL='mail@mail.example'
#DJANGO_SUPERUSER_PASSWORD='password'
#SECRET_KEY=klajsfkljasdfkljasdfkljadsfjklads
#CENTER_NAME="BlaBla Cloud"
#CENTER_HELP_URL="https://blabla.it/"
#PLUGIN_SLURM: "True"

#Ldap config:
#PLUGIN_AUTH_LDAP: "True"
#AUTH_LDAP_SERVER_URI: "ldaps://ldapserver"
#AUTH_LDAP_START_TLS: "False"
#AUTH_LDAP_BIND_DN: 'CN=aa,DC=aa,DC=aa'
#AUTH_LDAP_BIND_PASSWORD: 'secretpassword'
#AUTH_LDAP_USER_SEARCH_BASE: 'DC=aa,DC=aa'
#AUTH_LDAP_GROUP_SEARCH_BASE: 'cn=aa,ou=aa,dc=aa,dc=aa'
#AUTH_LDAP_MIRROR_GROUPS: "False"
#AUTH_LDAP_BIND_AS_AUTHENTICATING_USER: "False"

#ONDEMAND_URL: "http://ondemand.hpc"

#Redis config
#REDIS_HOST=127.0.0.1
#REDIS_PORT=6379
#REDIS_DB=0

#Queue configuration
#Q_CLUSTER_NAME=coldfront
#Q_CLUSTER_TIMEOUT=60


# Database configuration for ColdFront service
DATABASE_HOST='coldfront_database'
DATABASE_PORT=3306
DATABASE_NAME='coldfront'
DATABASE_USER='coldfront'
DATABASE_PASSWORD='nomoresecret'

# Environment variables for the ColdFront Worker service
#DEBUG=True
#INITIAL_SETUP=False
#LOAD_TEST_DATA=False
#REDIS_HOST="coldfront_redis"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ coldfront.db
*.code-workspace
.vscode
db.json
.env
.devcontainer/*
.bin/*
docker-clean.bat
script-export-coldfront/clusters
script-export-coldfront/ldapserver
script-export-coldfront/storage
24 changes: 16 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
FROM python:3.8
FROM python:3.9-slim-bullseye


RUN apt-get update \
&& apt-get install -y --no-install-recommends \
&& apt-get install -y netcat \
&& apt-get install -y default-libmysqlclient-dev build-essential \
&& apt-get install -y libldap2-dev libsasl2-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app
RUN pip3 config --user set global.progress_bar off

WORKDIR /opt
COPY requirements.txt ./
RUN pip3 install -r requirements.txt
RUN pip3 install --upgrade pip
RUN pip3 install -r /opt/requirements.txt
COPY . .
RUN python3 setup.py build
RUN python3 setup.py install
RUN pip3 install /opt
ENV DEBUG="True"

RUN python3 ./manage.py initial_setup
RUN python3 ./manage.py load_test_data
EXPOSE 8000

ENV DEBUG=True

EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
CMD [ "/opt/entrypoint.sh" ]
6 changes: 5 additions & 1 deletion coldfront/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from __future__ import absolute_import, unicode_literals
import os
import sys

__version__ = '1.1.6'

__version__ = '1.1.7'
VERSION = __version__




def manage():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "coldfront.config.settings")
from django.core.management import execute_from_command_line
Expand Down
9 changes: 8 additions & 1 deletion coldfront/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
SECRET_KEY = ENV.str('SECRET_KEY', default='')
if len(SECRET_KEY) == 0:
SECRET_KEY = get_random_secret_key()


SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
#------------------------------------------------------------------------------
# Locale settings
#------------------------------------------------------------------------------
Expand Down Expand Up @@ -98,8 +99,14 @@
# Django Q
#------------------------------------------------------------------------------
Q_CLUSTER = {
'name': ENV.str('Q_CLUSTER_NAME', default='coldfront'),
'timeout': ENV.int('Q_CLUSTER_TIMEOUT', default=120),
'retry': ENV.int('Q_CLUSTER_RETRY', default=120),
'redis': {
'host': ENV.str('REDIS_HOST', default='127.0.0.1'),
'port': ENV.int('REDIS_PORT', default=6379),
'db': ENV.int('REDIS_DB', default=0),
},
}


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

INSTALLED_APPS += [
'coldfront.plugins.storage',
]

#VARIABLE = ENV.str('VARIABLE', default='variable')
1 change: 1 addition & 0 deletions coldfront/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'PLUGIN_AUTH_OIDC': 'plugins/openid.py',
'PLUGIN_AUTH_LDAP': 'plugins/ldap.py',
'PLUGIN_LDAP_USER_SEARCH': 'plugins/ldap_user_search.py',
'PLUGIN_STORAGE': 'plugins/storage.py',
}

# This allows plugins to be enabled via environment variables. Can alternatively
Expand Down
25 changes: 24 additions & 1 deletion coldfront/core/allocation/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import textwrap
from django import forms

from django.contrib import admin
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -113,11 +114,34 @@ def save_formset(self, request, form, formset, change):
class AttributeTypeAdmin(admin.ModelAdmin):
list_display = ('name', )

class AllocationAttributeTypeForm(forms.ModelForm):
class Meta:
model = AllocationAttributeType
fields = '__all__'

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['get_usage_command'].widget = forms.TextInput(attrs={'size': 40})
self.fields['get_usage_command'].required = False


@admin.register(AllocationAttributeType)
class AllocationAttributeTypeAdmin(admin.ModelAdmin):
form = AllocationAttributeTypeForm
list_display = ('pk', 'name', 'attribute_type', 'has_usage', 'is_private')
fields = ('name', 'attribute_type', 'has_usage', 'get_usage_command', 'is_required', 'is_unique', 'is_private', 'is_changeable')

class Media:
js = ('custom/allocation_attribute_type.js',)

def get_fields(self, request, obj=None):
fields = super().get_fields(request, obj)
return fields

def save_model(self, request, obj, form, change):
if obj.has_usage and not obj.get_usage_command:
obj.get_usage_command = '' # Assicurati che questo sia l'effetto desiderato
super().save_model(request, obj, form, change)

class AllocationAttributeUsageInline(admin.TabularInline):
model = AllocationAttributeUsage
Expand Down Expand Up @@ -361,4 +385,3 @@ class AllocationChangeRequestAdmin(admin.ModelAdmin):
@admin.register(AllocationAttributeChangeRequest)
class AllocationChangeStatusChoiceAdmin(admin.ModelAdmin):
list_display = ('pk', 'allocation_change_request', 'allocation_attribute', 'new_value', )

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Generated by Django 4.2.11 on 2024-07-22 14:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('allocation', '0005_auto_20211117_1413'),
]

operations = [
migrations.AlterModelOptions(
name='historicalallocation',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical allocation', 'verbose_name_plural': 'historical allocations'},
),
migrations.AlterModelOptions(
name='historicalallocationattribute',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical allocation attribute', 'verbose_name_plural': 'historical allocation attributes'},
),
migrations.AlterModelOptions(
name='historicalallocationattributechangerequest',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical allocation attribute change request', 'verbose_name_plural': 'historical allocation attribute change requests'},
),
migrations.AlterModelOptions(
name='historicalallocationattributetype',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical allocation attribute type', 'verbose_name_plural': 'historical allocation attribute types'},
),
migrations.AlterModelOptions(
name='historicalallocationattributeusage',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical allocation attribute usage', 'verbose_name_plural': 'historical allocation attribute usages'},
),
migrations.AlterModelOptions(
name='historicalallocationchangerequest',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical allocation change request', 'verbose_name_plural': 'historical allocation change requests'},
),
migrations.AlterModelOptions(
name='historicalallocationuser',
options={'get_latest_by': ('history_date', 'history_id'), 'ordering': ('-history_date', '-history_id'), 'verbose_name': 'historical allocation user', 'verbose_name_plural': 'historical Allocation User Status'},
),
migrations.AddField(
model_name='allocationattributetype',
name='get_usage_command',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='historicalallocationattributetype',
name='get_usage_command',
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name='historicalallocation',
name='history_date',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalallocationattribute',
name='history_date',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalallocationattributechangerequest',
name='history_date',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalallocationattributetype',
name='history_date',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalallocationattributeusage',
name='history_date',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalallocationchangerequest',
name='history_date',
field=models.DateTimeField(db_index=True),
),
migrations.AlterField(
model_name='historicalallocationuser',
name='history_date',
field=models.DateTimeField(db_index=True),
),
]
7 changes: 7 additions & 0 deletions coldfront/core/allocation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,11 @@ class AllocationAttributeType(TimeStampedModel):
is_changeable (bool): indicates whether or not the attribute type is changeable
"""


attribute_type = models.ForeignKey(AttributeType, on_delete=models.CASCADE)
name = models.CharField(max_length=50)
has_usage = models.BooleanField(default=False)
get_usage_command = models.TextField(blank=True, null=True) # Campo aggiornato
is_required = models.BooleanField(default=False)
is_unique = models.BooleanField(default=False)
is_private = models.BooleanField(default=True)
Expand All @@ -416,6 +418,11 @@ class AllocationAttributeType(TimeStampedModel):
def __str__(self):
return '%s' % (self.name)

def clean(self):
super().clean()
if self.has_usage and not self.get_usage_command:
raise ValidationError('Command string is required when has_usage is True.')

class Meta:
ordering = ['name', ]

Expand Down
Loading