Skip to content
This repository has been archived by the owner on Feb 3, 2024. It is now read-only.

Commit

Permalink
Add Hiding Capabilities and Viewing
Browse files Browse the repository at this point in the history
  • Loading branch information
jabbate19 committed Nov 10, 2021
1 parent 91bcd7e commit 038b3f2
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 0 deletions.
51 changes: 51 additions & 0 deletions quotefault/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,3 +323,54 @@ def review_submit(report_id, result):
return redirect('/review')
return redirect('/')

@app.route('/hide/<report_id>', methods=['POST'])
@auth.oidc_auth
def hide(report_id):
"""
Hides a quote
"""
metadata = get_metadata()
quote = Quote.query.get(report_id)
if ( metadata['uid'] == quote.speaker
or metadata['uid'] == quote.submitter
or metadata['is_admin'] ):
quote.hidden = True
db.session.commit()
flash("Quote Hidden!")
return redirect('/storage')

@app.route('/unhide/<report_id>', methods=['POST'])
@auth.oidc_auth
def unhide(report_id):
"""
Gives admins power to unhide a hidden quote
"""
metadata = get_metadata()
if metadata['is_admin']:
quote = Quote.query.get(report_id)
quote.hidden = False
db.session.commit()
flash("Quote Unhidden!")
return redirect('/hidden')
return redirect('/')

@app.route('/hidden', methods=['GET'])
@auth.oidc_auth
def hidden():
"""
Presents hidden quotes to qualified users
Users who submitted a hidden quote or were quoted in a hidden quote will see those only
Admins see all hidden quotes
"""
metadata = get_metadata()
if metadata['is_admin']:
quotes = Quote.query.filter( Quote.hidden ).all()
else:
quotes = Quote.query.filter(
(Quote.speaker == metadata['uid']) | (Quote.submitter == metadata['uid'] )
).filter( Quote.hidden ).all()
return render_template(
'bootstrap/hidden.html',
quotes=quotes,
metadata=metadata
)
6 changes: 6 additions & 0 deletions quotefault/templates/bootstrap/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
Storage
</a>
</li>
<li class="nav-item navbar-user dropdown">
<a class="nav-link" href="/hidden">
<i class="fa fa-flag"></i>
Hidden
</a>
</li>
{% if metadata['is_admin'] %}
<li class="nav-item navbar-user dropdown">
<a class="nav-link" href="/review">
Expand Down
100 changes: 100 additions & 0 deletions quotefault/templates/bootstrap/hidden.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{% extends "bootstrap/base.html" %}

{% block styles %}
<link rel="stylesheet" href="/static/css/votes/upvote.css">
{% endblock %}

{% block body %}
<script type="text/javascript">
function unhide(id){
// Get the modal
var modal = document.getElementById(`unhide_${id}`);
modal.style.display = "block";
}
function unhideClose(id){
// Get the modal
var modal = document.getElementById(`unhide_${id}`);
modal.style.display = "none";
}
</script>
<div class="container">
<!-- flash relevant message when submit button is clicked -->
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<script>
switch (category) {
case warning:
category = warning
case error:
category = danger
default:
category = success
}
</script>
<div class="alert alert-{{ category }}" role="alert">
{{ message }}
</div>
{% endfor %}
{% endif %}
{% endwith %}

{% for quote in quotes %}
{% if loop.index0 == 0 and config['PLUG'] == True and metadata.plug != 'False' %}
<div class="card my-3">
<div class="card-body">
<div class="plug-body">
<a href="https://plug.csh.rit.edu" title="Advertisements by CSH: Plug">
<img style="width: 100%" src="https://plug.csh.rit.edu/data"
alt="Advertisements by CSH: Plug">
</a>
</div>
</div>
</div>
{% endif %}

<div class="card m-3">

<div class="card-body">
"{{ quote.quote }}" <b>- {{ get_display_name(quote.speaker) }}</b>
</div>
<div class="card-footer">
Submitted by <a href="https://profiles.csh.rit.edu/user/{{ quote.submitter }}">{{ get_display_name(quote.submitter) }}</a> on {{ quote.quote_time.strftime('%Y-%m-%d %H:%M:%S') }}
{% if metadata['is_admin'] %}
<button type="button" class="btn btn-success btn-sm float-right" onclick="unhide({{quote.id}})" id="unhide_button_{{quote.id}}">Unhide</button>
<div class="modal" id="unhide_{{quote.id}}">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Unhide Quote</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to unhide this quote?</p>
</div>
<div class="modal-footer">
<!-- TODO: Probably should not be using form and buttons and rather be using input. -->
<!-- <a class="btn btn-primary btn-sm" href="/report/{{quote.id}}" id="report::{{quote.id}}" type="button btn-danger">Yes</a> -->
<form method="POST" action="/unhide/{{quote.id}}" id="unhide::{{quote.id}}" method="POST">
<button type="submit" class="btn btn-success">Yes</button>
</form>
<button type="button" class="btn btn-danger" onclick="unhideClose({{quote.id}})" id="unhide_close_{{quote.id}}">No</button>
</div>
</div>
</div>
</div>
{% endif %}

</div>
</div>
{% endfor %}
</div>
{% endblock %}

{% block scripts %}
<script src="{{ url_for('static', filename='js/load_more.js') }}"></script>
<script src="{{ url_for('static', filename='css/votes/upvote.js') }}"></script>
<script src="{{ url_for('static', filename='js/vote.js') }}"></script>
{% endblock %}
37 changes: 37 additions & 0 deletions quotefault/templates/bootstrap/storage.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
var modal = document.getElementById(`report_${id}`);
modal.style.display = "none";
}
function hide(id){
// Get the modal
var modal = document.getElementById(`hide_${id}`);
modal.style.display = "block";
}
function hideClose(id){
// Get the modal
var modal = document.getElementById(`hide_${id}`);
modal.style.display = "none";
}
</script>
<div class="container">
<!-- flash relevant message when submit button is clicked -->
Expand Down Expand Up @@ -100,6 +110,33 @@ <h5 class="modal-title">Report Quote</h5>
</div>
</div>
</div>
{% if metadata['uid'] == quote.submitter or metadata['uid'] == quote.speaker or metadata['is_admin'] %}
<button type="button" class="btn btn-warning btn-sm float-right" onclick="hide({{quote.id}})" id="hide_button_{{quote.id}}">Hide</button>
<div class="modal" id="hide_{{quote.id}}">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Hide Quote</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>Are you sure you want to hide this quote?</p>
</div>
<div class="modal-footer">
<!-- TODO: Probably should not be using form and buttons and rather be using input. -->
<!-- <a class="btn btn-primary btn-sm" href="/report/{{quote.id}}" id="report::{{quote.id}}" type="button btn-danger">Yes</a> -->
<form method="POST" action="/hide/{{quote.id}}" id="hide::{{quote.id}}" method="POST">
<button type="submit" class="btn btn-danger">Yes</button>
</form>
<button type="button" class="btn btn-success" onclick="hideClose({{quote.id}})" id="hide_close_{{quote.id}}">No</button>
</div>
</div>
</div>
</div>
{% endif %}

</div>
</div>
{% endfor %}
Expand Down

0 comments on commit 038b3f2

Please sign in to comment.