| @@ -14,29 +14,6 @@ CREATE TABLE users ( | |||||
| PRIMARY KEY (userid) | PRIMARY KEY (userid) | ||||
| ); | ); | ||||
| /* | |||||
| * Project tables | |||||
| */ | |||||
| /* | |||||
| CREATE TABLE teams ( | |||||
| teamid INT UNSIGNED AUTO_INCREMENT, | |||||
| team_name VARCHAR(200) NOT NULL, | |||||
| write_permission BOOLEAN, | |||||
| PRIMARY KEY (teamid) | |||||
| ); | |||||
| */ | |||||
| /* | |||||
| CREATE TABLE teams_users ( | |||||
| teamid INT UNSIGNED NOT NULL, | |||||
| userid INT UNSIGNED NOT NULL, | |||||
| PRIMARY KEY (teamid, userid), | |||||
| FOREIGN KEY (teamid) REFERENCES teams(teamid), | |||||
| FOREIGN KEY (userid) REFERENCES users(userid) | |||||
| ); | |||||
| */ | |||||
| CREATE TABLE project_category ( | CREATE TABLE project_category ( | ||||
| categoryid INT UNSIGNED AUTO_INCREMENT, | categoryid INT UNSIGNED AUTO_INCREMENT, | ||||
| category_name VARCHAR(200) UNIQUE NOT NULL, | category_name VARCHAR(200) UNIQUE NOT NULL, | ||||
| @@ -77,14 +54,12 @@ CREATE TABLE projects_users ( | |||||
| CREATE TABLE tasks ( | CREATE TABLE tasks ( | ||||
| taskid INT UNSIGNED AUTO_INCREMENT, | taskid INT UNSIGNED AUTO_INCREMENT, | ||||
| projectid INT UNSIGNED NOT NULL, | projectid INT UNSIGNED NOT NULL, | ||||
| /*teamid INT UNSIGNED,*/ | |||||
| title VARCHAR(200) NOT NULL, | title VARCHAR(200) NOT NULL, | ||||
| task_description VARCHAR(500) NOT NULL, | task_description VARCHAR(500) NOT NULL, | ||||
| budget INT NOT NULL, | budget INT NOT NULL, | ||||
| task_status VARCHAR(64) NOT NULL, -- This should be Waiting for delivery, delivered, accepted and declined delivery | task_status VARCHAR(64) NOT NULL, -- This should be Waiting for delivery, delivered, accepted and declined delivery | ||||
| feedback VARCHAR(500) NULL, | feedback VARCHAR(500) NULL, | ||||
| PRIMARY KEY (taskid), | PRIMARY KEY (taskid), | ||||
| /*FOREIGN KEY (teamid) REFERENCES teams(teamid),*/ | |||||
| FOREIGN KEY (projectid) REFERENCES projects(projectid) | FOREIGN KEY (projectid) REFERENCES projects(projectid) | ||||
| ); | ); | ||||
| @@ -96,35 +71,6 @@ CREATE TABLE task_files ( | |||||
| FOREIGN KEY (taskid) REFERENCES tasks(taskid) | FOREIGN KEY (taskid) REFERENCES tasks(taskid) | ||||
| ); | ); | ||||
| /* | |||||
| CREATE TABLE delivery ( | |||||
| deliveryid INT UNSIGNED AUTO_INCREMENT, | |||||
| taskid INT UNSIGNED NOT NULL, | |||||
| userid INT UNSIGNED NOT NULL, | |||||
| filename VARCHAR(45) NOT NULL, | |||||
| comment VARCHAR(500), | |||||
| delivery_time DATETIME DEFAULT CURRENT_TIMESTAMP, | |||||
| responding_userid INT NOT NULL, | |||||
| responding_time DATETIME, | |||||
| delivery_status VARCHAR(16), -- Should be Accepted, Pending or Declined | |||||
| feedback VARCHAR(500), | |||||
| PRIMARY KEY (deliveryid), | |||||
| FOREIGN KEY (taskid) REFERENCES tasks(taskid), | |||||
| FOREIGN KEY (userid) REFERENCES users(userid) | |||||
| );*/ | |||||
| /* | |||||
| CREATE TABLE task_offer ( | |||||
| offerid INT UNSIGNED AUTO_INCREMENT, | |||||
| taskid INT UNSIGNED NOT NULL, | |||||
| title VARCHAR(200) NOT NULL, | |||||
| price INT, | |||||
| description VARCHAR(500), | |||||
| offer_status VARCHAR(16), -- Should be Accepted, Pending or Declined | |||||
| feedback VARCHAR(500), | |||||
| PRIMARY KEY (offerid), | |||||
| FOREIGN KEY (taskid) REFERENCES tasks(taskid) | |||||
| );*/ | |||||
| /* | /* | ||||
| * Initial data | * Initial data | ||||
| @@ -144,7 +90,3 @@ Create default database user | |||||
| CREATE USER 'root'@'10.5.0.6' IDENTIFIED BY 'root'; | CREATE USER 'root'@'10.5.0.6' IDENTIFIED BY 'root'; | ||||
| GRANT ALL PRIVILEGES ON db.* TO 'root'@'10.5.0.6'; | GRANT ALL PRIVILEGES ON db.* TO 'root'@'10.5.0.6'; | ||||
| /* | |||||
| Can be used to connect local webserver to the database | |||||
| GRANT ALL PRIVILEGES ON db.* TO 'root'@'localhost'; | |||||
| */ | |||||
| @@ -14,6 +14,11 @@ def get_users(): | |||||
| return users | return users | ||||
| def get_user_id_by_name(username): | def get_user_id_by_name(username): | ||||
| """ | |||||
| Get the id of the unique username | |||||
| :param username: Name of the user | |||||
| :return: The id of the user | |||||
| """ | |||||
| db.connect() | db.connect() | ||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("SELECT userid from users WHERE username =\"" + username + "\"") | query = ("SELECT userid from users WHERE username =\"" + username + "\"") | ||||
| @@ -26,6 +31,11 @@ def get_user_id_by_name(username): | |||||
| return userid | return userid | ||||
| def get_user_name_by_id(userid): | def get_user_name_by_id(userid): | ||||
| """ | |||||
| Get username from user id | |||||
| :param userid: The id of the user | |||||
| :return: The name of the user | |||||
| """ | |||||
| db.connect() | db.connect() | ||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("SELECT username from users WHERE userid =\"" + userid + "\"") | query = ("SELECT username from users WHERE userid =\"" + userid + "\"") | ||||
| @@ -45,30 +45,44 @@ def set_project(categoryid, userid, project_title, project_description, project_ | |||||
| def get_project_by_id(projectid): | def get_project_by_id(projectid): | ||||
| """ | """ | ||||
| Retrieve a project by its id | Retrieve a project by its id | ||||
| :param projectid: The project id | :param projectid: The project id | ||||
| :type projectid: str | :type projectid: str | ||||
| :return: The selected project | :return: The selected project | ||||
| """ | """ | ||||
| db.connect() | db.connect() | ||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("SELECT * FROM projects WHERE projectid = \"" + | |||||
| projectid + "\"") | |||||
| query = ("SELECT * FROM projects WHERE projectid = \"" + projectid + "\"") | |||||
| cursor.execute(query) | cursor.execute(query) | ||||
| project = cursor.fetchall() | project = cursor.fetchall() | ||||
| cursor.close() | cursor.close() | ||||
| return project[0] | return project[0] | ||||
| def update_project_status(projectid, status): | def update_project_status(projectid, status): | ||||
| """ | |||||
| Change the status of a selected project | |||||
| :param projectid: The project id | |||||
| :param status: The status to change to, should be either open, in progress or finished | |||||
| :type projectid: str | |||||
| :type status: str | |||||
| """ | |||||
| db.connect() | db.connect() | ||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("UPDATE projects SET project_status = \"" + status + | query = ("UPDATE projects SET project_status = \"" + status + | ||||
| "\" WHERE projectid = \"" + projectid + "\"") | "\" WHERE projectid = \"" + projectid + "\"") | ||||
| print(query) | |||||
| cursor.execute(query) | cursor.execute(query) | ||||
| db.commit() | db.commit() | ||||
| cursor.close() | cursor.close() | ||||
| def get_user_permissions(userid, projectid): | def get_user_permissions(userid, projectid): | ||||
| """ | |||||
| Get permissions for a selected users in a specific project | |||||
| :param userid: The id of the user | |||||
| :param projectid: The id of the project | |||||
| :type userid: str | |||||
| :type projectid: str | |||||
| :return: Permissions as an array of numbers as boolean values | |||||
| """ | |||||
| db.connect() | db.connect() | ||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("SELECT read_permission, write_permission, modify_permission \ | query = ("SELECT read_permission, write_permission, modify_permission \ | ||||
| @@ -101,6 +115,12 @@ def get_projects_by_status_and_category(categoryid, project_status): | |||||
| return projects | return projects | ||||
| def get_projects_by_owner(userid): | def get_projects_by_owner(userid): | ||||
| """ | |||||
| Retrieve all projects created by a specific user | |||||
| :param userid: The id of the user | |||||
| :type userid: str | |||||
| :return: An array of projects | |||||
| """ | |||||
| db.connect() | db.connect() | ||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("SELECT * FROM projects WHERE userid = \"" + userid + "\"") | query = ("SELECT * FROM projects WHERE userid = \"" + userid + "\"") | ||||
| @@ -194,28 +214,51 @@ def get_tasks_by_project_id(projectid): | |||||
| return tasks | return tasks | ||||
| def set_task_file(taskid, filename): | def set_task_file(taskid, filename): | ||||
| """ | |||||
| Register a new task - file relationship | |||||
| :param taskid: The task id | |||||
| :param filename: The name of the file | |||||
| :type taskid: str | |||||
| :type filename: str | |||||
| """ | |||||
| db.connect() | db.connect() | ||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("INSERT INTO task_files (taskid, filename) VALUES (\"" + | query = ("INSERT INTO task_files (taskid, filename) VALUES (\"" + | ||||
| taskid + "\", \"" + filename + "\")") | taskid + "\", \"" + filename + "\")") | ||||
| print(query) | |||||
| cursor.execute(query) | cursor.execute(query) | ||||
| db.commit() | db.commit() | ||||
| cursor.close() | cursor.close() | ||||
| def get_task_files(taskid): | def get_task_files(taskid): | ||||
| """ | |||||
| Retrieve all filenames registered in a task | |||||
| :param taskid: The task id | |||||
| :type taskid: str | |||||
| :return: An array of filenames | |||||
| """ | |||||
| db.connect() | db.connect() | ||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("SELECT filename FROM task_files WHERE taskid = \"" + str(taskid) + "\"") | query = ("SELECT filename FROM task_files WHERE taskid = \"" + str(taskid) + "\"") | ||||
| cursor.execute(query) | cursor.execute(query) | ||||
| filenames = cursor.fetchall() | filenames = cursor.fetchall() | ||||
| print(query) | |||||
| print(filenames) | |||||
| cursor.close | cursor.close | ||||
| return filenames | return filenames | ||||
| def set_projects_user(projectid, userid, read_permission="TRUE", | def set_projects_user(projectid, userid, read_permission="TRUE", | ||||
| write_permission="NULL", modify_permission="NULL"): | write_permission="NULL", modify_permission="NULL"): | ||||
| """ | |||||
| Add a user to a project with specific permissions | |||||
| :param projectid: The project id | |||||
| :param userid: The user id | |||||
| :param read_permission: Describes whether a user can view information about a project | |||||
| :param write_permission: Describes whether a user can add files to tasks | |||||
| :param modify_permission: Describes wheter a user can deliver tasks | |||||
| :type projectid: str | |||||
| :type userid: str | |||||
| :type read_permission: str | |||||
| :type write_permission: str | |||||
| """ | |||||
| db.connect() | db.connect() | ||||
| cursor = db.cursor() | cursor = db.cursor() | ||||
| query = ("INSERT INTO projects_users VALUES (\"" + projectid + "\", \"" + | query = ("INSERT INTO projects_users VALUES (\"" + projectid + "\", \"" + | ||||
| @@ -97,7 +97,7 @@ def get_user_form_elements(identifier=0, user_name="", read_permission=True, wri | |||||
| :return: The form elements to add users to a project | :return: The form elements to add users to a project | ||||
| """ | """ | ||||
| user_form_elements = ( | user_form_elements = ( | ||||
| form.Textbox("user_name_" + str(identifier), description="User", value=user_name), | |||||
| form.Textbox("user_name_" + str(identifier), description="User", value=user_name, placeholder="Leave blank for open project"), | |||||
| form.Checkbox("read_permission_" + str(identifier), description="Read Permission", checked=read_permission, value=True), | form.Checkbox("read_permission_" + str(identifier), description="Read Permission", checked=read_permission, value=True), | ||||
| form.Checkbox("write_permission_" + str(identifier), description="Write Permission", checked=write_permission, value=True), | form.Checkbox("write_permission_" + str(identifier), description="Write Permission", checked=write_permission, value=True), | ||||
| form.Checkbox("modify_permission_" + str(identifier), description="Modify Permission", checked=modify_permission, value=True) | form.Checkbox("modify_permission_" + str(identifier), description="Modify Permission", checked=modify_permission, value=True) | ||||