Manual update tool for bfct_trainer
At the moment this is a manual tool to check if a user has a valid BFCT application. If yes, the bfct_trainer role is assigned. If not, the role is removed.
This commit is contained in:
@@ -6,7 +6,7 @@ from application.forms import CommentForm
|
||||
from application.models.users import *
|
||||
from application.models.applications import Application, Skill, ReviewersApplications, Comment
|
||||
|
||||
from flask import render_template, redirect, url_for, request, Blueprint
|
||||
from flask import render_template, redirect, url_for, request, Blueprint, abort
|
||||
from flask.ext.security import login_required, roles_accepted
|
||||
from flask.ext.security.core import current_user
|
||||
|
||||
@@ -113,3 +113,22 @@ def comment(application_id):
|
||||
db.session.commit()
|
||||
return redirect(url_for('.view', id=application_id))
|
||||
|
||||
|
||||
@applications.route('/edit/<int:application_id>/update-bfct-role/')
|
||||
@roles_accepted('bfct_manager', 'admin')
|
||||
def update_bfct_role(application_id):
|
||||
application = Application.query.get_or_404(application_id)
|
||||
user = User.query.get_or_404(application.blender_id)
|
||||
applications = Application.query\
|
||||
.filter_by(blender_id=user.id)\
|
||||
.all()
|
||||
|
||||
for application in applications:
|
||||
if application.status == 'approved':
|
||||
# TODO: additional check to see if application is valid
|
||||
user_datastore.add_role_to_user(user, 'bfct_trainer')
|
||||
db.session.commit()
|
||||
else:
|
||||
user_datastore.remove_role_from_user(user, 'bfct_trainer')
|
||||
db.session.commit()
|
||||
return redirect(url_for('.view', id=application_id))
|
||||
|
@@ -7,7 +7,6 @@ from application import db
|
||||
|
||||
class User(db.Model, UserMixin):
|
||||
__bind_key__ = 'users'
|
||||
__table_args__ = {'schema': 'blender-id'}
|
||||
id = db.Column(db.Integer(), primary_key=True)
|
||||
first_name = db.Column(db.String(255))
|
||||
last_name = db.Column(db.String(255))
|
||||
|
@@ -138,6 +138,14 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<a href="{{url_for('applications.update_bfct_role', application_id=application.id)}}" class="btn btn-default btn-block btn-squishy btn-default">
|
||||
<i class="fa fa-refresh"></i> Update BFCT Role
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<hr>
|
||||
|
Reference in New Issue
Block a user