Commit e3cede7e authored by Kacprzak, Izabella's avatar Kacprzak, Izabella
Browse files

Merged in master and modified dashboard styling [IK]

parents 5a0f3dd6 7bdb4d2e
Pipeline #204157 passed with stages
in 2 minutes and 17 seconds
......@@ -8,6 +8,7 @@ test-job:
- apt-get update -qy
- apt-get install -y python3 python3-pip
- pip3 install -r requirements.txt
- export ENV="dev"
- python3 run_tests.py test
heroku-deploy:
......@@ -18,6 +19,7 @@ heroku-deploy:
- apt-get install -y python3 python3-pip
- pip3 install -r requirements.txt
- pip3 install python-dotenv
- export ENV="prod"
- cd backend
- python3 -m flask db upgrade
- cd ..
......
from operator import truediv
from re import T
from flask import Blueprint, request, jsonify
from backend.database_config.database import DB
from backend.models.task_model import AssignedTask
from backend.models.task_model import Task
from backend.models.project_model import Project
from backend.models.user_model import User
assigned_task = Blueprint('assigned_task', __name__)
@assigned_task.route('/assigned_task', methods=['GET'])
def get_all_assignments():
assignments = AssignedTask.query.all()
assignments_list = [{"username": x.username,
"task_id": x.task_id,
"id": x.id} for x in assignments]
return jsonify(assignments_list)
@assigned_task.route('/assigned_task/username/<username>', methods=['GET'])
def get_pending_tasks_for_user(username):
entries = AssignedTask.query.filter_by(username=username)
task_list = [{"description": task.description,
"project_id": task.project_id,
"project_name": Project.query.get(task.project_id).name,
"priority": task.priority,
"due_date": task.due_date,
"id": task.id} for task in (Task.query.get(x.task_id) for x in entries) if not task.completed]
return jsonify(task_list)
@assigned_task.route('/assigned_task/task/<task_id>', methods=['GET'])
def get_users_for_task(task_id):
entries = AssignedTask.query.filter_by(task_id=task_id)
users_list = [{"firstname": user.firstname,
"surname": user.surname,
"username": user.username} for user in (User.query.get(x.username) for x in entries)]
return jsonify(users_list)
@assigned_task.route('/assigned_task', methods=['POST'])
def assign_task_to_user():
username, task_id = (request.json['username'], request.json['task_id'])
entry = AssignedTask(username=username, task_id=task_id)
DB.add(entry)
return ''
......@@ -3,6 +3,7 @@ from flask import Blueprint, request, jsonify
from backend.database_config.database import DB
from backend.models.project_model import Project
from backend.models.task_model import Task
from backend.models.user_model import User_project
project = Blueprint('project', __name__)
......@@ -41,7 +42,7 @@ def upload_project():
request.json['location'], request.json['files'])
entry = Project(name=name, status=status, description=description, tag=tag, location=location, files=files)
DB.add(entry)
return ''
return jsonify(id=entry.id)
@project.route('/projects/<project_id>', methods=['POST'])
def update_project(project_id):
......@@ -63,6 +64,9 @@ def delete_project(project_id):
tasks = Task.query.filter_by(project_id=project_id)
for task in tasks:
DB.delete(task)
assignments = User_project.query.filter_by(project_id=project_id)
for assignment in assignments:
DB.delete(assignment)
entry = Project.query.get(project_id)
DB.delete(entry)
return ''
from re import T
from flask import Blueprint, request, jsonify
from backend.database_config.database import DB
from backend.models.user_model import User_project, User
from backend.models.project_model import Project
user_project = Blueprint('user_project', __name__)
@user_project.route('/user_project', methods=['GET'])
def get_all_assignments():
assignments = User_project.query.all()
assignments_list = [{"username" : x.username,
"project_id" : x.project_id,
"id" : x.id} for x in assignments]
return jsonify(assignments_list)
@user_project.route('/user_project/project/<project_id>', methods=['GET'])
def get_users_for_project(project_id):
entries = User_project.query.filter_by(project_id=project_id)
assignments_list = [{"username" : x.username,
"project_id" : x.project_id,
"id" : x.id} for x in entries]
return jsonify(assignments_list)
@user_project.route('/user_project/project_task/<project_id>', methods=['GET'])
def get_users_for_project_for_tasks(project_id):
entries = User_project.query.filter_by(project_id=project_id)
assigned_users = [{"value" : query.username,
"label" : query.firstname + " " + query.surname}
for query in (User.query.get(x.username) for x in entries)]
return jsonify(assigned_users)
@user_project.route('/user_project/username/<username>', methods=['GET'])
def get_projects_for_user(username):
entries = User_project.query.filter_by(username=username)
project_list = [{"id" : query.id,
"name" : query.name,
"status" : query.status,
"description" : query.description,
"tag" : query.tag,
"location" : query.location,
"files" : query.files} for query in (Project.query.get(x.project_id) for x in entries)]
return jsonify(project_list)
@user_project.route('/user_project', methods=['POST'])
def assign_project_to_user():
username, project_id = (request.json['username'], request.json['project_id'])
entry = User_project(username=username, project_id=project_id)
DB.add(entry)
return ''
\ No newline at end of file
......@@ -2,7 +2,7 @@ from operator import truediv
from re import T
from flask import Blueprint, request, jsonify
from backend.database_config.database import DB
from backend.models.task_model import Task
from backend.models.task_model import AssignedTask, Task
task = Blueprint('task', __name__)
......@@ -18,8 +18,6 @@ def get_project_tasks(project_id):
"id" : x.id} for x in entries]
return jsonify(project_tasks)
@task.route('/projects/<project_id>/tasks', methods=['POST'])
def add_project_task(project_id):
description, due_date, completed, priority = (request.json['description'],
......@@ -31,7 +29,7 @@ def add_project_task(project_id):
is_completed = False
entry = Task(due_date=due_date, priority=priority, description=description, completed=is_completed, project_id=project_id)
DB.add(entry)
return ''
return jsonify(id=entry.id)
@task.route('/projects/<project_id>/tasks/<task_id>', methods=['POST'])
......@@ -50,6 +48,10 @@ def update_task(project_id, task_id):
@task.route('/projects/<project_id>/tasks/<task_id>', methods=['DELETE'])
def delete_task(project_id, task_id):
entries = AssignedTask.query.filter_by(task_id=task_id)
for e in entries:
DB.delete(e)
entry = Task.query.get(task_id)
DB.delete(entry)
return ''
\ No newline at end of file
from flask import Blueprint, request, jsonify, Response
from backend.database_config.database import DB
from backend.models.user_model import User
import json
from backend.models.user_model import User_project
from backend.main import Message
import backend.main
import bcrypt
user = Blueprint('user', __name__)
......@@ -10,12 +13,18 @@ def get_all_users():
user_query = User.query.all()
users_list = [{"firstname" : x.firstname, "surname" : x.surname,
"title" : x.title, "email" : x.email, "bio" : x.bio, "joined" : x.joined,
"title" : x.title, "email" : x.email, "phone_no" : x.phone_no, "bio" : x.bio, "joined" : x.joined,
"location" : x.location, "availability" : x.availability,
"partnership_opportunities" : x.partnership_opportunities,
"interests" : x.interests, "username" : x.username } for x in user_query]
return jsonify(users_list)
@user.route('/users/user_project', methods=['GET'])
def get_all_users_in_value_label_form():
user_query = User.query.all()
users_list = [{"value" : x.username, "label" : x.firstname + " " + x.surname } for x in user_query]
return jsonify(users_list)
@user.route('/users/<username>', methods=['GET'])
def get_id(username):
......@@ -27,6 +36,7 @@ def get_id(username):
password = user.password,
title = user.title,
email = user.email,
phone_no = user.phone_no,
bio = user.bio,
joined = user.joined,
location = user.location,
......@@ -35,19 +45,29 @@ def get_id(username):
interests = user.interests
)
@user.route('/users/name/<username>', methods=['GET'])
def get_name(username):
user = User.query.get(username)
return jsonify(
firstname = user.firstname,
surname = user.surname
)
@user.route('/users', methods=['POST'])
def add_user():
username, firstname, surname, password, title, email, bio, joined, location, availability, partnership_opportunities, interests = (
username, firstname, surname, password, title, email, phone_no, bio, joined, location, availability, partnership_opportunities, interests = (
request.json['username'], request.json['firstname'],
request.json['surname'],
request.json['password'],
request.json['title'],
request.json['email'], request.json['bio'], request.json['joined'],
request.json['email'], request.json['phone_no'], request.json['bio'], request.json['joined'],
request.json['location'],request.json['availability'],
request.json['partnership_opportunities'], request.json['interests'])
entry = User(username = username, firstname = firstname, surname = surname, password = password,
title = title, email = email, bio = bio, joined = joined, location = location,
salt = bcrypt.gensalt()
hash_pswd = bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
entry = User(username = username, firstname = firstname, surname = surname, password = hash_pswd,
title = title, email = email, phone_no = phone_no, bio = bio, joined = joined, location = location,
availability = availability, partnership_opportunities = partnership_opportunities,
interests = interests)
DB.add(entry)
......@@ -57,19 +77,25 @@ def add_user():
@user.route('/users/<username>', methods=['POST'])
def update_user(username):
entry = User.query.get(username)
firstname, surname, password, title, email, bio, joined, location, availability, partnership_opportunities, interests = (
firstname, surname, password, title, email, phone_no, bio, joined, location, availability, partnership_opportunities, interests = (
request.json['firstname'],
request.json['surname'],
request.json['password'],
request.json['title'],
request.json['email'], request.json['bio'], request.json['joined'],
request.json['email'], request.json['phone_no'], request.json['bio'], request.json['joined'],
request.json['location'],request.json['availability'],
request.json['partnership_opportunities'], request.json['interests'])
entry.firstname = firstname
entry.surname = surname
entry.password = password
salt = bcrypt.gensalt()
hash_pswd = bcrypt.hashpw(password.encode('utf-8'), salt)
entry.password = hash_pswd
entry.title = title
entry.email = email
entry.phone_no = phone_no
entry.bio = bio
entry.joined = joined
entry.location = location
......@@ -82,8 +108,67 @@ def update_user(username):
@user.route('/users/<username>', methods=['DELETE'])
def delete_user(username):
if username == "jaimeaguilera":
return ''
entries = User_project.query.filter_by(username=username)
for e in entries:
DB.delete(e)
entry = User.query.get(username)
DB.delete(entry)
return ''
@user.route('/users/login', methods = ['POST'])
def user_login():
username, password = (request.json['username'], request.json['password'])
user = User.query.get(username)
if user == None:
return jsonify(token = "")
if bcrypt.checkpw(password.encode('utf-8'), user.password.encode('utf-8')):
return jsonify(token = username)
else:
return jsonify(token = "")
@user.route('/users/update-password', methods = ['POST'])
def change_user_password():
username, oldPassword, newPassword = (request.json['username'], request.json['oldPassword'],
request.json['newPassword'])
user = User.query.get(username)
if user == None:
return jsonify(status = "False")
if bcrypt.checkpw(oldPassword.encode('utf-8'), user.password.encode('utf-8')):
salt = bcrypt.gensalt()
hash_pswd = bcrypt.hashpw(newPassword.encode('utf-8'), salt)
user.password = hash_pswd.decode('utf-8')
DB.add(user)
return jsonify(status = "True")
else:
return jsonify(status = "False")
@user.route('/users/forgot-password', methods=['POST'])
def send_auth_email():
username, newPassword = (request.json['username'], request.json['newPassword'])
user = User.query.get(username)
if user == None:
return jsonify(status = "False")
msg = Message(subject="Password reset",
sender=backend.main.app.config.get("MAIL_USERNAME"),
recipients=[user.email],
body="Your new password is: " + newPassword)
salt = bcrypt.gensalt()
hash_pswd = bcrypt.hashpw(newPassword.encode('utf-8'), salt)
user.password = hash_pswd.decode('utf-8')
DB.add(user)
backend.main.mail.send(msg)
return jsonify(status = "True")
\ No newline at end of file
import os
from flask import Flask, render_template
from flask_migrate import Migrate
from flask_mail import Mail, Message
from backend.database_config.database import DB
from backend.blueprints.project import project
from backend.blueprints.user import user
from backend.blueprints.todo import todo
from backend.blueprints.task import task
from backend.blueprints.project_to_user import user_project
from backend.blueprints.assigned_task import assigned_task
ENV = os.environ.get("ENV")
app = Flask(__name__)
......@@ -12,10 +18,29 @@ app.register_blueprint(project)
app.register_blueprint(user)
app.register_blueprint(todo)
app.register_blueprint(task)
app.register_blueprint(user_project)
app.register_blueprint(assigned_task)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://g205001034_u:CierkbZMND@db.doc.ic.ac.uk:5432/g205001034_u'
if ENV == 'dev':
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://g205001034_u:CierkbZMND@db.doc.ic.ac.uk:5432/g205001034_u'
else:
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://ozufqkgtnoptrc:42b722a2bf88caa314bc0558abb0098d0971a9d588728a64413576cd62255003@ec2-54-224-120-186.compute-1.amazonaws.com:5432/dfbpe6718mqdmh'
# Mail settings for "forgot password" mail sending
mail_settings = {
"MAIL_SERVER": 'smtp.gmail.com',
"MAIL_PORT": 465,
"MAIL_USE_TLS": False,
"MAIL_USE_SSL": True,
"MAIL_USERNAME": 'inaglobe.authentication@gmail.com',
"MAIL_PASSWORD": '5Q4g>kQ&c'
}
app.config.update(mail_settings)
mail = Mail(app)
db = DB.the_database
db.app = app
......
Generic single-database configuration.
\ No newline at end of file
"""empty message
Revision ID: 8e16378bae7e
Revises: 8aca5c725ce9
Create Date: 2021-06-09 12:17:43.767146
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8e16378bae7e'
down_revision = '8aca5c725ce9'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('assigned_tasks',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('task',
sa.Column('description', sa.String(), nullable=True),
sa.Column('priority', sa.Integer(), nullable=True),
sa.Column('completed', sa.Boolean(), nullable=True),
sa.Column('due_date', sa.Date(), nullable=True),
sa.Column('project_id', sa.Integer(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.ForeignKeyConstraint(['project_id'], ['project.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.drop_table('project_tasks')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('project_tasks',
sa.Column('project_id', sa.INTEGER(), autoincrement=False, nullable=True),
sa.Column('task_id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.PrimaryKeyConstraint('task_id', name='project_tasks_pkey')
)
op.drop_table('task')
op.drop_table('assigned_tasks')
# ### end Alembic commands ###
"""empty message
Revision ID: ca3946ceea1a
Revises: d1228461a0cb
Create Date: 2021-06-10 20:54:00.983912
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'ca3946ceea1a'
down_revision = 'd1228461a0cb'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('todo', sa.Column('due_date', sa.Date(), nullable=True))
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('todo', 'due_date')
# ### end Alembic commands ###
"""empty message
Revision ID: 8aca5c725ce9
Revises: ec68c4b5813f
Create Date: 2021-06-09 11:08:45.680961
Revision ID: cd2b194a323c
Revises:
Create Date: 2021-06-16 16:56:23.129198
"""
from alembic import op
......@@ -10,8 +10,8 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8aca5c725ce9'
down_revision = 'ec68c4b5813f'
revision = 'cd2b194a323c'
down_revision = None
branch_labels = None
depends_on = None
......@@ -28,19 +28,15 @@ def upgrade():
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('project_tasks',
sa.Column('project_id', sa.Integer(), nullable=True),
sa.Column('task_id', sa.Integer(), autoincrement=True, nullable=False),
sa.PrimaryKeyConstraint('task_id')
)
op.create_table('user',
sa.Column('firstname', sa.String(), nullable=True),
sa.Column('surname', sa.String(), nullable=True),
sa.Column('password', sa.String(), nullable=True),
sa.Column('title', sa.String(), nullable=True),
sa.Column('email', sa.String(), nullable=True),
sa.Column('phone_no', sa.String(), nullable=True),
sa.Column('bio', sa.String(), nullable=True),
sa.Column('joined', sa.String(), nullable=True),
sa.Column('joined', sa.Date(), nullable=True),
sa.Column('location', sa.String(), nullable=True),
sa.Column('availability', sa.String(), nullable=True),
sa.Column('partnership_opportunities', sa.String(), nullable=True),
......@@ -48,9 +44,20 @@ def upgrade():
sa.Column('username', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('username')
)
op.create_table('task',
sa.Column('description', sa.String(), nullable=True),
sa.Column('priority', sa.Integer(), nullable=True),
sa.Column('completed', sa.Boolean(), nullable=True),
sa.Column('due_date', sa.Date(), nullable=True),
sa.Column('project_id', sa.Integer(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.ForeignKeyConstraint(['project_id'], ['project.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('todo',
sa.Column('priority', sa.Integer(), nullable=True),
sa.Column('todo_desc', sa.String(), nullable=True),
sa.Column('due_date', sa.Date(), nullable=True),
sa.Column('username', sa.String(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.ForeignKeyConstraint(['username'], ['user.username'], ),
......@@ -64,14 +71,23 @@ def upgrade():
sa.ForeignKeyConstraint(['username'], ['user.username'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('assigned_task',
sa.Column('task_id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(), nullable=False),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.ForeignKeyConstraint(['task_id'], ['task.id'], ),
sa.ForeignKeyConstraint(['username'], ['user.username'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('assigned_task')
op.drop_table('user_project')
op.drop_table('todo')
op.drop_table('task')
op.drop_table('user')
op.drop_table('project_tasks')
op.drop_table('project')
# ### end Alembic commands ###
"""empty message
Revision ID: d1228461a0cb
Revises: 8e16378bae7e
Create Date: 2021-06-10 07:54:01.889263
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'd1228461a0cb'
down_revision = '8e16378bae7e'
branch_labels = None