diff --git a/mysql/sql/init.sql b/mysql/sql/init.sql index 3ef8be9..39acac4 100644 --- a/mysql/sql/init.sql +++ b/mysql/sql/init.sql @@ -77,7 +77,7 @@ CREATE TABLE tasks ( title VARCHAR(200) NOT NULL, task_description VARCHAR(500), budget INT NOT NULL, - task_status VARCHAR(64) NOT NULL, -- This should be Waiting for delivery, Delivered and waiting for acceptance, Delivery has been accepted, awaiting payment, Payment for delivery is done or Declined delivery, please revise + task_status VARCHAR(64) NOT NULL, -- This should be Waiting for delivery, delivered, accepted and declined delivery feedback VARCHAR(500) NULL, PRIMARY KEY (taskid), FOREIGN KEY (teamid) REFERENCES teams(teamid), diff --git a/src/app/models/project.py b/src/app/models/project.py index c1e082c..ecd492c 100644 --- a/src/app/models/project.py +++ b/src/app/models/project.py @@ -64,6 +64,18 @@ def update_project_status(projectid, status): db.commit() cursor.close() +def get_user_permissions(userid, projectid): + cursor = db.cursor() + query = ("SELECT read_permission, write_permission, modify_permission \ + FROM projects_users WHERE projectid = \"" + projectid + + "\" AND userid = \"" + userid + "\"") + cursor.execute(query) + permissions = cursor.fetchall() + cursor.close() + if len(permissions): + return permissions[0] + return [0,0,0] + def get_projects_by_status_and_category(categoryid, project_status): """ Retrieve all projects from a category with a specific status @@ -145,6 +157,14 @@ def set_task(projectid, task_title, task_description, budget): db.commit() cursor.close +def update_task_status(taskid, status): + cursor = db.cursor() + query = ("UPDATE tasks SET task_status = \"" + status + + "\" WHERE taskid = \"" + taskid + "\"") + cursor.execute(query) + db.commit() + cursor.close() + def get_tasks_by_project_id(projectid): """ Get all tasks belonging to a project diff --git a/src/app/templates/project.html b/src/app/templates/project.html index 74e983c..914c441 100644 --- a/src/app/templates/project.html +++ b/src/app/templates/project.html @@ -1,4 +1,4 @@ -$def with (nav, project, tasks) +$def with (nav, project, tasks, permissions) Beelance2 @@ -33,6 +33,9 @@ $def with (nav, project, tasks)
+ + $if permissions[2]: + diff --git a/src/app/views/project.py b/src/app/views/project.py index f9fb746..e162631 100644 --- a/src/app/views/project.py +++ b/src/app/views/project.py @@ -24,6 +24,9 @@ class Project: nav = get_nav_bar(session) data = web.input(projectid=0) + + permissions = models.project.get_user_permissions(str(session.userid), data.projectid) + if data.projectid: project = models.project.get_project_by_id(data.projectid) tasks = models.project.get_tasks_by_project_id(data.projectid) @@ -31,15 +34,24 @@ class Project: project = [[]] tasks = [[]] render = web.template.render('templates/', globals={'get_task_files':models.project.get_task_files, 'session':session}) - return render.project(nav, project, tasks) + return render.project(nav, project, tasks,permissions) def POST(self): - data = web.input(myfile={}) + # Get session + session = web.ctx.session + + data = web.input(myfile={}, deliver=None) fileitem = data['myfile'] - + + permissions = models.project.get_user_permissions(str(session.userid), data.projectid) + print(data.deliver) # Test if the file was uploaded if fileitem.filename: + if not permissions[1]: + print("Permission denied") + raise web.seeother(('/project?projectid=' + data.projectid)) + data = web.input(projectid=0) fn = fileitem.filename @@ -60,10 +72,12 @@ class Project: open(path + '/' + fn, 'wb').write(fileitem.file.read()) message = 'The file "' + fn + '" was uploaded successfully' models.project.set_task_file(data.taskid, (path + "/" + fn)) + elif data.deliver: + models.project.update_task_status(data.taskid, "delivered") + print(data.taskid) else: message = 'No file was uploaded' - print (message) raise web.seeother(('/project?projectid=' + data.projectid))