Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion conditional/blueprints/cache_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def restart_app():
@cache_bp.route('/clearcache')
def clear_cache():
user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)

if not ldap_is_eval_director(user_name) or not ldap_is_rtp(user_name):
if not ldap_is_eval_director(account) or not ldap_is_rtp(account):
return redirect("/dashboard")

logger.info('api', action='purge system cache')
Expand Down
10 changes: 7 additions & 3 deletions conditional/blueprints/conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def create_conditional():
log.info('api', action='create new conditional')

user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)

if not ldap_is_eval_director(user_name):
if not ldap_is_eval_director(account):
return "must be eval director", 403

post_data = request.get_json()
Expand All @@ -78,8 +79,9 @@ def conditional_review():

# get user data
user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)

if not ldap_is_eval_director(user_name):
if not ldap_is_eval_director(account):
return redirect("/dashboard", code=302)

post_data = request.get_json()
Expand All @@ -106,7 +108,9 @@ def conditional_delete(cid):
log.info('api', action='delete conditional')

user_name = request.headers.get('x-webauth-user')
if ldap_is_eval_director(user_name):
account = ldap_get_member(user_name)

if ldap_is_eval_director(account):
Conditional.query.filter(
Conditional.id == cid
).delete()
Expand Down
6 changes: 3 additions & 3 deletions conditional/blueprints/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from conditional.blueprints.member_management import get_members_info

from conditional.util.housing import get_queue_length, get_queue_position
from conditional.util.housing import get_queue_position
from conditional.util.flask import render_template
from conditional.util.member import get_freshman_data, get_voting_members

Expand Down Expand Up @@ -73,8 +73,8 @@ def display_dashboard():
housing = dict()
housing['points'] = member.housingPoints
housing['room'] = member.roomNumber
if housing['room'] == "":
housing['queue_pos'] = "%s / %s" % (get_queue_position(member.uid), get_queue_length())
if housing['room'] is None:
housing['queue_pos'] = "%s / %s" % get_queue_position(member.uid)
else:
housing['queue_pos'] = "N/A"
else:
Expand Down
40 changes: 35 additions & 5 deletions conditional/blueprints/housing.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import uuid
import structlog

from flask import Blueprint, request
from flask import Blueprint, request, jsonify

from conditional.models.models import FreshmanAccount
from conditional.util.housing import get_queue_with_points
from conditional.util.ldap import ldap_get_onfloor_members
from conditional.models.models import InHousingQueue
from conditional.util.housing import get_housing_queue
from conditional.util.ldap import ldap_get_onfloor_members, ldap_is_eval_director, ldap_get_member
from conditional.util.flask import render_template

from conditional.util.ldap import ldap_get_roomnumber

from conditional import db


logger = structlog.get_logger()

Expand All @@ -23,8 +26,8 @@ def display_housing():
log.info('frontend', action='display housing')

# get user data

user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: not sure if we've used the language account for this before. But I'd prefer something like current account. That way account can be reserved for some kind of interation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was something I choose when transitioning over to the new library. Account is the keyword I chose to denote the passing of the actual object over a string or their username (which we called all sorts of different things [uid, username, user_name, etc]). I am not sure what you mean by integration. Even if we found a better use for the the "account" keyword, having current_account and account being completely different, unrelated possess completely different functionality would be a terrible design choice.


housing = {}
onfloors = [account for account in ldap_get_onfloor_members()]
Expand Down Expand Up @@ -57,6 +60,33 @@ def display_housing():
return render_template(request,
'housing.html',
username=user_name,
queue=get_queue_with_points(),
queue=get_housing_queue(ldap_is_eval_director(account)),
housing=housing,
room_list=sorted(list(room_list)))


@housing_bp.route('/housing/in_queue', methods=['PUT'])
def change_queue_state():
log = logger.new(user_name=request.headers.get("x-webauth-user"),
request_id=str(uuid.uuid4()))
log.info('api', action='add or remove member from housing queue')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(account):
return "must be eval director", 403

post_data = request.get_json()
uid = post_data.get('uid', False)

if uid:
if post_data.get('inQueue', False):
queue_obj = InHousingQueue(uid=uid)
db.session.add(queue_obj)
else:
InHousingQueue.query.filter_by(uid=uid).delete()

db.session.flush()
db.session.commit()
return jsonify({"success": True}), 200
7 changes: 5 additions & 2 deletions conditional/blueprints/major_project_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def major_project_review():

# get user data
user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)

if not ldap_is_eval_director(user_name):
if not ldap_is_eval_director(account):
return redirect("/dashboard", code=302)

post_data = request.get_json()
Expand All @@ -106,12 +107,14 @@ def major_project_delete(pid):

# get user data
user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)

major_project = MajorProject.query.filter(
MajorProject.id == pid
).first()
creator = major_project.uid

if creator == user_name or ldap_is_eval_director(user_name):
if creator == user_name or ldap_is_eval_director(account):
MajorProject.query.filter(
MajorProject.id == pid
).delete()
Expand Down
35 changes: 23 additions & 12 deletions conditional/blueprints/member_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ def display_member_management():
log.info('frontend', action='display member management')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username) and not ldap_is_financial_director(username):
if not ldap_is_eval_director(account) and not ldap_is_financial_director(account):
return "must be eval director", 403

member_list = get_members_info()
Expand Down Expand Up @@ -102,8 +103,9 @@ def member_management_eval():
log.info('api', action='submit site settings')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username):
if not ldap_is_eval_director(account):
return "must be eval director", 403

post_data = request.get_json()
Expand Down Expand Up @@ -134,8 +136,9 @@ def member_management_adduser():
log.info('api', action='add fid user')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username):
if not ldap_is_eval_director(account):
return "must be eval director", 403

post_data = request.get_json()
Expand All @@ -158,8 +161,9 @@ def member_management_adduser():
@member_management_bp.route('/manage/user/upload', methods=['POST'])
def member_management_uploaduser():
username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username):
if not ldap_is_eval_director(account):
return "must be eval director", 403

f = request.files['file']
Expand Down Expand Up @@ -195,8 +199,9 @@ def member_management_edituser(uid):
log.info('api', action='edit uid user')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username) and not ldap_is_financial_director(username):
if not ldap_is_eval_director(account) and not ldap_is_financial_director(account):
return "must be eval director", 403

post_data = request.get_json()
Expand All @@ -219,7 +224,8 @@ def edit_uid(uid, username, post_data):
onfloor_status = post_data['onfloorStatus']
housing_points = post_data['housingPoints']

if ldap_is_eval_director(username):
current_account = ldap_get_member(username)
if ldap_is_eval_director(current_account):
logger.info('backend', action="edit %s room: %s onfloor: %s housepts %s" %
(uid, post_data['roomNumber'], post_data['onfloorStatus'],
post_data['housingPoints']))
Expand Down Expand Up @@ -296,8 +302,9 @@ def member_management_getuserinfo(uid):
log.info('api', action='retrieve user info')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username) and not ldap_is_financial_director(username):
if not ldap_is_eval_director(account) and not ldap_is_financial_director(account):
return "must be eval or financial director", 403

acct = None
Expand Down Expand Up @@ -341,7 +348,7 @@ def get_hm_date(hm_id):

account = ldap_get_member(uid)

if ldap_is_eval_director(username):
if ldap_is_eval_director(ldap_get_member(username)):
missed_hm = [
{
'date': get_hm_date(hma.meeting_id),
Expand Down Expand Up @@ -382,8 +389,9 @@ def member_management_deleteuser(fid):
log.info('api', action='edit fid user')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username):
if not ldap_is_eval_director(account):
return "must be eval director", 403

if not fid.isdigit():
Expand Down Expand Up @@ -417,8 +425,9 @@ def member_management_upgrade_user():
log.info('api', action='convert fid to uid entry')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username):
if not ldap_is_eval_director(account):
return "must be eval director", 403

post_data = request.get_json()
Expand Down Expand Up @@ -479,8 +488,9 @@ def introductory_project():
log.info('api', action='show introductory project management')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username):
if not ldap_is_eval_director(account):
return "must be eval director", 403

return render_template(request,
Expand All @@ -496,8 +506,9 @@ def introductory_project_submit():
log.info('api', action='submit introductory project results')

username = request.headers.get('x-webauth-user')
account = ldap_get_member(username)

if not ldap_is_eval_director(username):
if not ldap_is_eval_director(account):
return "must be eval director", 403

post_data = request.get_json()
Expand Down
16 changes: 11 additions & 5 deletions conditional/blueprints/slideshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from conditional.blueprints.intro_evals import display_intro_evals
from conditional.blueprints.spring_evals import display_spring_evals

from conditional.util.ldap import ldap_is_eval_director
from conditional.util.ldap import ldap_is_eval_director, ldap_get_member

from conditional.models.models import FreshmanEvalData
from conditional.models.models import SpringEval
Expand All @@ -31,7 +31,9 @@ def slideshow_intro_display():
log.info('frontend', action='display intro slideshow')

user_name = request.headers.get('x-webauth-user')
if not ldap_is_eval_director(user_name):
account = ldap_get_member(user_name)

if not ldap_is_eval_director(account):
return redirect("/dashboard")

return render_template(request,
Expand Down Expand Up @@ -61,8 +63,9 @@ def slideshow_intro_review():

# get user data
user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)

if not ldap_is_eval_director(user_name):
if not ldap_is_eval_director(account):
return redirect("/dashboard", code=302)

post_data = request.get_json()
Expand Down Expand Up @@ -90,7 +93,9 @@ def slideshow_spring_display():
log.info('frontend', action='display membership evaluations slideshow')

user_name = request.headers.get('x-webauth-user')
if not ldap_is_eval_director(user_name):
account = ldap_get_member(user_name)

if not ldap_is_eval_director(account):
return redirect("/dashboard")

return render_template(request,
Expand Down Expand Up @@ -120,8 +125,9 @@ def slideshow_spring_review():

# get user data
user_name = request.headers.get('x-webauth-user')
account = ldap_get_member(user_name)

if not ldap_is_eval_director(user_name):
if not ldap_is_eval_director(account):
return redirect("/dashboard", code=302)

post_data = request.get_json()
Expand Down
5 changes: 5 additions & 0 deletions conditional/models/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ Records the yearly results of member's spring evaluations.
| `date_created` | `TIMESTAMP` | The date of the evaluation.
| `status` | `ENUM` | Result of the evaluation.

## InHousingQueue table ##
Records the yearly results of member's spring evaluations.

| Field | Type | Description |
| ------------- | ------------- | ------------------- |
| `uid` | `VARCHAR(32)` | LDAP uid of the member in the housing queue.


### Member state ###
Expand Down
4 changes: 4 additions & 0 deletions conditional/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ class SpringEval(db.Model):
name="spring_eval_enum"),
nullable=False)

class InHousingQueue(db.Model):
__tablename__ = 'in_housing_queue'
uid = Column(String(32), primary_key=True)

def __init__(self, uid):
self.uid = uid
self.active = True
Expand Down
Loading