From d2611cd97966eea24c88624101dc0781f6607ff8 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Fri, 7 Nov 2014 12:08:00 +0100 Subject: [PATCH] Server settings for svn commits --- webservice/bam/application/__init__.py | 17 +++++++-- .../bam/application/modules/admin/model.py | 3 +- .../bam/application/modules/projects/admin.py | 17 ++++++++- .../bam/application/modules/projects/model.py | 17 ++++++++- .../versions/52d9e7b917f_project_settings.py | 36 +++++++++++++++++++ webservice/requirements.txt | 4 +-- 6 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 webservice/bam/migrations/versions/52d9e7b917f_project_settings.py diff --git a/webservice/bam/application/__init__.py b/webservice/bam/application/__init__.py index 2f98108..ddce904 100644 --- a/webservice/bam/application/__init__.py +++ b/webservice/bam/application/__init__.py @@ -49,7 +49,7 @@ db = SQLAlchemy(app) from application.modules.admin import backend from application.modules.admin import settings from application.modules.projects import admin -from application.modules.projects.model import Project +from application.modules.projects.model import Project, ProjectSetting @auth.get_password @@ -221,6 +221,15 @@ class FileAPI(Resource): arguments = json.loads(request.args['arguments']) file = request.files['file'] + # Get the value of the first (and only) result for the specified project setting + svn_password = next((setting.value for setting in project.settings if setting.name == 'svn_password')) + svn_default_user = next((setting.value for setting in project.settings if setting.name == 'svn_default_user')) + + # If the setting does not exist, stop here and prevent any other operation + if not svn_password: + return make_response(jsonify( + {'message': 'SVN missing password settings'}), 500) + if file and self.allowed_file(file.filename): os.makedirs(project.upload_path, exist_ok=True) @@ -276,9 +285,13 @@ class FileAPI(Resource): result = local_client.run_command('add', [file_path,]) + # Commit command result = local_client.run_command('commit', - [local_client.info()['entry_path'], '--message', arguments['message']], + [local_client.info()['entry_path'], + '--message', arguments['message'], + '--username', svn_default_user, + '--password', svn_password], combine=True) diff --git a/webservice/bam/application/modules/admin/model.py b/webservice/bam/application/modules/admin/model.py index 83b24b7..093724e 100644 --- a/webservice/bam/application/modules/admin/model.py +++ b/webservice/bam/application/modules/admin/model.py @@ -1,11 +1,12 @@ from application import db + class Setting(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(256), unique=True, nullable=False) description = db.Column(db.Text) value = db.Column(db.String(100), nullable=False) data_type = db.Column(db.String(128), nullable=False) - + def __unicode__(self): return self.name diff --git a/webservice/bam/application/modules/projects/admin.py b/webservice/bam/application/modules/projects/admin.py index 689b463..442935d 100644 --- a/webservice/bam/application/modules/projects/admin.py +++ b/webservice/bam/application/modules/projects/admin.py @@ -1,7 +1,7 @@ from application import app from application import db -from application.modules.projects.model import Project +from application.modules.projects.model import Project, ProjectSetting from application.modules.admin import * from application.modules.admin import _list_thumbnail @@ -12,6 +12,21 @@ class ProjectView(CustomModelView): column_list = ('name', 'picture', 'creation_date') #column_formatters = { 'picture': _list_thumbnail } #form_extra_fields = {'picture': image_upload_field('Header')} + form_overrides = dict( + status=SelectField, + ) + form_args = dict( + status=dict( + label='Status', + choices=[ + ('active', 'Active'), + ('inactive', 'Inactive'), + ('canceled', 'Canceled') + ]), + ) + inline_models = ( + ProjectSetting, + ) # Add views backend.add_view(ProjectView(Project, db.session, name='Projects', url='projects')) diff --git a/webservice/bam/application/modules/projects/model.py b/webservice/bam/application/modules/projects/model.py index f55501e..ce0f887 100644 --- a/webservice/bam/application/modules/projects/model.py +++ b/webservice/bam/application/modules/projects/model.py @@ -1,6 +1,7 @@ import datetime from application import db + class Project(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(255), nullable=False) @@ -8,7 +9,21 @@ class Project(db.Model): upload_path = db.Column(db.Text, nullable=False) picture = db.Column(db.String(80)) creation_date = db.Column(db.DateTime(), default=datetime.datetime.now) - status = db.Column(db.String(80)) #pending #active #inactive + status = db.Column(db.String(80)) #active #inactive + + settings = db.relationship('ProjectSetting', backref='project') def __str__(self): return str(self.name) + + +class ProjectSetting(db.Model): + id = db.Column(db.Integer, primary_key=True) + project_id = db.Column(db.Integer(), db.ForeignKey('project.id'), nullable=False) + name = db.Column(db.String(256), unique=True, nullable=False) + description = db.Column(db.Text) + value = db.Column(db.String(100), nullable=False) + data_type = db.Column(db.String(128), nullable=False) + + def __unicode__(self): + return self.name diff --git a/webservice/bam/migrations/versions/52d9e7b917f_project_settings.py b/webservice/bam/migrations/versions/52d9e7b917f_project_settings.py new file mode 100644 index 0000000..f8e5d90 --- /dev/null +++ b/webservice/bam/migrations/versions/52d9e7b917f_project_settings.py @@ -0,0 +1,36 @@ +"""project_settings + +Revision ID: 52d9e7b917f +Revises: 4918c57ece7 +Create Date: 2014-11-07 11:15:13.057416 + +""" + +# revision identifiers, used by Alembic. +revision = '52d9e7b917f' +down_revision = '4918c57ece7' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.create_table('project_setting', + sa.Column('id', sa.Integer(), nullable=False), + sa.Column('project_id', sa.Integer(), nullable=False), + sa.Column('name', sa.String(length=256), nullable=False), + sa.Column('description', sa.Text(), nullable=True), + sa.Column('value', sa.String(length=100), nullable=False), + sa.Column('data_type', sa.String(length=128), nullable=False), + sa.ForeignKeyConstraint(['project_id'], ['project.id'], ), + sa.PrimaryKeyConstraint('id'), + sa.UniqueConstraint('name') + ) + ### end Alembic commands ### + + +def downgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.drop_table('project_setting') + ### end Alembic commands ### diff --git a/webservice/requirements.txt b/webservice/requirements.txt index 41d262f..0ad8f9c 100644 --- a/webservice/requirements.txt +++ b/webservice/requirements.txt @@ -1,5 +1,5 @@ Flask==0.10.1 -Flask-Admin==1.0.8 +Flask-Admin==1.0.7 Flask-HTTPAuth==2.3.0 Flask-Login==0.2.11 Flask-Mail==0.9.1 @@ -15,7 +15,7 @@ Mako==1.0.0 MarkupSafe==0.23 Pillow==2.6.1 SQLAlchemy==0.9.8 -WTForms==2.0.1 +WTForms==1.0.5 Werkzeug==0.9.6 alembic==0.6.7 aniso8601==0.83