Skip to content

Commit

Permalink
Changed it so Groups are accessable for authorized users only
Browse files Browse the repository at this point in the history
  • Loading branch information
SirGankalot committed May 1, 2024
1 parent 4ba7bdf commit 2eaab16
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
23 changes: 23 additions & 0 deletions service/src/FlaskWebsite/website/templates/group_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "base.html" %} {% block title %}Home{% endblock %} {% block content
%}
<h1 align="center">Note Groups</h1>
<ul class="list-group list-group-flush" id="notes">
{% for note in notes %}
<li class="list-group-item">
{{ note.data }}
{% if note.owner_id == user.id %}
<button type="button" class="close" onClick="deleteNote({{ note.id }})">
<span aria-hidden="true">&times;</span>
</button>
{% endif %}
</li>
{% endfor %}
</ul>
<form method="POST">
<textarea name="note" id="note" class="form-control"></textarea>
<br />
<div align="center">
<button type="submit" class="btn btn-primary">Add Note</button>
</div>
</form>
{% endblock %}
7 changes: 1 addition & 6 deletions service/src/FlaskWebsite/website/templates/groups.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ <h1 align="center">Groups</h1>
<ul class="list-group list-group-flush" id="groups">
{% for group in groups %}
<li class="list-group-item">
{{ group.name }}
<!-- {% if group.owner_id == user.id %}
<button type="button" class="close" onClick="deleteNote({{ group.id }})">
<span aria-hidden="true">&times;</span>
</button>
{% endif %} -->
<a href="{{ url_for('views.group_page', group_id=group.id) }}">{{ group.name }}</a>
</li>
{% endfor %}
</ul>
Expand Down
19 changes: 16 additions & 3 deletions service/src/FlaskWebsite/website/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from flask import Blueprint, render_template, request, flash, jsonify
from flask import Blueprint, render_template, request, flash, jsonify, redirect, url_for
from flask_login import login_required, current_user
from .models import Note
from .models import NoteGroup
from . import db
import json



views = Blueprint('views', __name__)


Expand Down Expand Up @@ -42,12 +43,24 @@ def creategroup():
print("here")
# Retrieve all rows from the NoteGroup table
note_groups = db.session.query(NoteGroup).all()
print(note_groups)
# Prepare a list of dictionaries where each dictionary represents a row with column names as keys and values as values
groups = [{column.name: getattr(note_group, column.name) for column in NoteGroup.columns} for note_group in note_groups]
print(groups)
return render_template("groups.html", user=current_user, groups=groups)

@views.route('/creategroup/<int:group_id>', methods=['GET', 'POST'])
@login_required
def group_page(group_id):
group_allusers = db.session.query(NoteGroup).filter_by(id=group_id).all()
if group_allusers:
if any(one_user.UserId == current_user.id for one_user in group_allusers):
# Retrieve all notes associated with the group
notes = db.session.query(Note).filter_by(owner_id=current_user.id).all()
return render_template("group_page.html", user=current_user, group=group_allusers, notes=notes)
else:
flash('You are not authorized to access this group.', category='error')
else:
flash('Group not found.', category='error')
return redirect(url_for('views.home'))

@views.route('/delete-note', methods=['POST'])
def delete_note():
Expand Down

0 comments on commit 2eaab16

Please sign in to comment.