Skip to content

Commit

Permalink
Merge pull request #148 from ctsit/master
Browse files Browse the repository at this point in the history
Bring Develop up to master
  • Loading branch information
PFWhite committed Apr 27, 2017
2 parents 497170f + 243a041 commit 8812630
Show file tree
Hide file tree
Showing 29 changed files with 707 additions and 150 deletions.
2 changes: 2 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
* Taeber Rapczak <taeber@ufl.edu>
* Kevin S. Hanson <hansonks@gmail.com>
* Christopher P. Barnes <senrabc@gmail.com>
* Patrick White <pfwhite9@gmail.com>
* Samantha Davuluri <samanthadavuluri4444@gmail.com>
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
# Change Log


## [0.2.0] - 2016-10-11

### New Features
* Admin Users can edit existing users.
* Deleter users can delete files that exist.
* The dashboard is easier to search.

### Changed
* Fixes for pagination. (Patrick White)
* Use config to find out where the deleted files are (Patrick White)
* Delete File changes and additions (Patrick White)
* Fixed dashboard presentation. (Patrick White)
* Update README.md (Kevin Hanson)
* deploy/fabfile.py enhancement to allow for easy database upgrades and downgrades (Patrick White)
* Made both the app/fabfile.py and bootstrap_functions.sh apply the most recent database version. (Patrick White)
* Edit user logging (ndavuluri)
* Unit tests and client side edit form changes (Patrick White)
* UserID and Role should be unique, adding an Unique Index for usrID,rolID. (ndavuluri)
* Only Admin User is allowed to create and edit User (ndavuluri)
* Polling for new subject data (Patrick White)
* Filter function for dashboard subject search (Patrick White)
* Initial Changes for Edit User:Adding a new route and updating db and loging (ndavuluri)
* Edit user changes (Patrick White, ndavuluri)


## [0.1.2] - 2016-04-13

### Changed
Expand Down
7 changes: 7 additions & 0 deletions app/db/003/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
These database changes are from the editUser feature branch

This schema change adds a unique constraint on the UserRole table to
prevent duplicate roles for individual users

It also adds a new log type to account for the edit_user api call

14 changes: 14 additions & 0 deletions app/db/003/downgrade.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- temporarily remove foreign keys to remove unique index
ALTER TABLE UserRole DROP FOREIGN KEY fk_User_usrID;
ALTER TABLE UserRole DROP FOREIGN KEY fk_UserRole_rolID;

-- remove unique index from UserRole
ALTER TABLE UserRole DROP INDEX uc_UserIDRoleID;

-- reapply the foreign key constraints
ALTER TABLE UserRole ADD CONSTRAINT fk_User_usrID FOREIGN KEY (usrID) REFERENCES User (usrID) ON DELETE CASCADE;
ALTER TABLE UserRole ADD CONSTRAINT fk_UserRole_rolID FOREIGN KEY (rolID) REFERENCES Role (rolID) ON DELETE CASCADE;

-- remove the log type for the edit user api call
DELETE FROM LogType
WHERE logtType='account_updated';
9 changes: 9 additions & 0 deletions app/db/003/upgrade.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- ensure there will be no duplicates user / user role pairs
ALTER TABLE UserRole
ADD CONSTRAINT uc_UserIDRoleID UNIQUE (usrID, rolID);

-- add the logtype for the edit_user api call
INSERT INTO LogType
(logtType, logtDescription)
VALUES
('account_updated','');
2 changes: 2 additions & 0 deletions app/db/004/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This change is to add the deleter role to the Role table.
The deleter role is able to delete files
7 changes: 7 additions & 0 deletions app/db/004/downgrade.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- remove the deleter permission
DELETE FROM Role
WHERE rolName='deleter';

-- remove the log type for the edit user api call
DELETE FROM LogType
WHERE logtType='file_deleted';
8 changes: 8 additions & 0 deletions app/db/004/upgrade.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- add the deleter permission
INSERT INTO Role (rolName, rolDescription) VALUES ('deleter', 'Can delete files');

-- add the file deleted log type
INSERT INTO LogType
(logtType, logtDescription)
VALUES
('file_deleted','');
62 changes: 60 additions & 2 deletions app/deploy/fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,57 @@ def mysql_list_tables():
result = local(cmd, capture=True)
print(result)

def _is_valid_version(version_number):
"""Checks if the version has the right number of digits"""
version_string = str(version_number)
return len(version_string) <= 3

def _get_version_string(version_number):
"""Produces a three char string that corresponds to the desired db folder"""
version_string = str(version_number)
while len(version_string) < 3:
version_string = '0' + version_string
return version_string

def _step_to_version(version_number, is_upgrade):
"""Step once to the passed version. Must be on adjacent version
Version numbers are given by the number for the folder
in app/db/
"""
require('environment', provided_by=[production, staging])

exists = mysql_check_db_exists()
if not exists:
abort(colors.red("Unable to create tables in database '%(db_name)s'."
"The database does not exist" % env))
if not _is_valid_version(version_number) is True:
abort(colors.red("Unable to upgrade to version {} '%(db_name)s'."
"Please look in app/db for valid versions".format(version_number)
% env))

login_path = _mysql_login_path()
sql_file = 'upgrade.sql' if is_upgrade else 'downgrade.sql'
sql = _get_version_string(version_number) + '/' + sql_file

with lcd('../db/'):
cmd = ("mysql --login-path={} %(db_name)s < {}"
.format(login_path, sql)
% env)
local(cmd)

def mysql_version_upgrade(version_number):
"""Upgrade to the passed version. Must be on adjacent version
Version numbers are given by the number for the folder
in app/db/
"""
_step_to_version(version_number, True)

def mysql_version_downgrade(version_number):
"""Downgrade to the passed version. Must be on adjacent version
Version numbers are given by the number for the folder
in app/db/
"""
_step_to_version(version_number, False)

def mysql_create_tables():
""" Create the application tables.
Expand All @@ -297,7 +348,11 @@ def mysql_create_tables():
.format(env.environment))

login_path = _mysql_login_path()
files = ['001/upgrade.sql', '002/upgrade.sql', '002/data.sql']
files = ['001/upgrade.sql',
'002/upgrade.sql',
'002/data.sql',
'003/upgrade.sql',
'004/upgrade.sql']

with lcd('../db/'):
for sql in files:
Expand All @@ -322,7 +377,10 @@ def mysql_drop_tables():
abort(colors.red("Unable to drop tables in database '%(db_name)s'."
"The database does not exist" % env))

files = ['002/downgrade.sql', '001/downgrade.sql']
files = ['004/downgrade.sql',
'003/downgrade.sql',
'002/downgrade.sql',
'001/downgrade.sql']

with lcd('../db/'):
for sql in files:
Expand Down
4 changes: 4 additions & 0 deletions app/fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def init_db():
local('sudo mysql ctsi_dropper_s < db/001/upgrade.sql')
local('sudo mysql ctsi_dropper_s < db/002/upgrade.sql')
local('sudo mysql ctsi_dropper_s < db/002/data.sql')
local('sudo mysql ctsi_dropper_s < db/003/upgrade.sql')
local('sudo mysql ctsi_dropper_s < db/004/upgrade.sql')


@task
Expand All @@ -78,6 +80,8 @@ def reset_db():
local('sudo mysql ctsi_dropper_s < db/001/upgrade.sql')
local('sudo mysql ctsi_dropper_s < db/002/upgrade.sql')
local('sudo mysql ctsi_dropper_s < db/002/data.sql')
local('sudo mysql ctsi_dropper_s < db/003/upgrade.sql')
local('sudo mysql ctsi_dropper_s < db/004/upgrade.sql')


@task
Expand Down
6 changes: 1 addition & 5 deletions app/redidropper/database/crud_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,23 @@ def get_by_id(cls, id):
return cls.query.get(int(id))
return None


@classmethod
def create(cls, **kwargs):
""" Helper for session.add() + session.commit() """
instance = cls(**kwargs)
return instance.save()


def update(self, commit=True, **kwargs):
for attr, value in kwargs.iteritems():
setattr(self, attr, value)
return commit and self.save() or self

return self.save() if commit else self

def save(self, commit=True):
db.session.add(self)
if commit:
db.session.commit()
return self


def delete(self, commit=True):
db.session.delete(self)
return commit and db.session.commit()
14 changes: 13 additions & 1 deletion app/redidropper/models/log_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
LOG_TYPE_LOGOUT, \
LOG_TYPE_LOGIN_ERROR, \
LOG_TYPE_FILE_UPLOADED, \
LOG_TYPE_FILE_DELETED, \
LOG_TYPE_FILE_DOWNLOADED, \
LOG_TYPE_ACCOUNT_MODIFIED, \
LOG_TYPE_REDCAP_SUBJECTS_IMPORTED, \
LOG_TYPE_REDCAP_EVENTS_IMPORTED
LOG_TYPE_REDCAP_EVENTS_IMPORTED, \
LOG_TYPE_ACCOUNT_UPDATED


class LogEntity(db.Model, CRUDMixin):
Expand Down Expand Up @@ -92,6 +94,11 @@ def account_created(session_id, details=''):
""" Log account creation """
LogEntity._log(LOG_TYPE_ACCOUNT_CREATED, session_id, details)

@staticmethod
def account_updated(session_id, details=''):
""" Log account updated """
LogEntity._log(LOG_TYPE_ACCOUNT_UPDATED, session_id, details)

@staticmethod
def login(session_id, details=''):
""" Log successful login """
Expand All @@ -112,6 +119,11 @@ def file_uploaded(session_id, details=''):
""" Log file upload """
LogEntity._log(LOG_TYPE_FILE_UPLOADED, session_id, details)

@staticmethod
def file_deleted(session_id, details=''):
""" Log account creation """
LogEntity._log(LOG_TYPE_FILE_DELETED, session_id, details)

@staticmethod
def file_downloaded(session_id, details=''):
""" Log file download """
Expand Down
2 changes: 2 additions & 0 deletions app/redidropper/models/log_type_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
LOG_TYPE_LOGOUT = 'logout'
LOG_TYPE_LOGIN_ERROR = 'login_error'
LOG_TYPE_FILE_UPLOADED = 'file_uploaded'
LOG_TYPE_FILE_DELETED = 'file_deleted'
LOG_TYPE_FILE_DOWNLOADED = 'file_downloaded'
LOG_TYPE_ACCOUNT_MODIFIED = 'account_modified'
LOG_TYPE_REDCAP_SUBJECTS_IMPORTED = 'redcap_subjects_impported'
LOG_TYPE_REDCAP_EVENTS_IMPORTED = 'redcap_events_imported'
LOG_TYPE_ACCOUNT_UPDATED = 'account_updated'
# LOG_TYPE_ = ''


Expand Down
1 change: 1 addition & 0 deletions app/redidropper/models/role_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ROLE_TECHNICIAN = 'technician'
ROLE_RESEARCHER_ONE = 'researcher_one'
ROLE_RESEARCHER_TWO = 'researcher_two'
ROLE_DELETER = 'deleter'


class RoleEntity(db.Model, CRUDMixin): # RoleMixin
Expand Down
1 change: 0 additions & 1 deletion app/redidropper/models/subject_file_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

logger = app.logger


class SubjectFileEntity(db.Model, CRUDMixin):
""" Stores the uploaded file metadata """
__tablename__ = 'SubjectFile'
Expand Down
2 changes: 1 addition & 1 deletion app/redidropper/models/user_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class UserEntity(db.Model, UserMixin, CRUDMixin):
modified_at = db.Column("usrModifiedAt", db.TIMESTAMP, nullable=False)
email_confirmed_at = db.Column("usrEmailConfirmedAt", db.DateTime,
nullable=False,
server_default='0000-00-00 00:00:00')
server_default='1901-10-04 11:17:00')
active = db.Column("usrIsActive", db.Boolean(), nullable=False,
server_default='1')

Expand Down
Loading

0 comments on commit 8812630

Please sign in to comment.