more team changes

This commit is contained in:
Michael Zhang 2016-01-16 20:23:34 -06:00
parent 8de7c95718
commit e38ddd1b8c
5 changed files with 110 additions and 3 deletions

View file

@ -73,6 +73,25 @@ class Teams(db.Model):
except ValueError:
return (-1, "--")
def get_invitation_requests(self, frid=None):
if frid is not None:
req = db.session.query(TeamInvitations).filter_by(rtype=1, frid=frid, toid=self.tid).first()
if req is None:
return None
else:
user = db.session.query(Users).filter_by(uid=req.frid).first()
return { "username": user.username, "name": user.name, "uid": user.uid }
result = [ ]
requests = db.session.query(TeamInvitations).filter_by(rtype=1, toid=self.tid).all()
for req in requests:
user = db.session.query(Users).filter_by(uid=req.frid).first()
result.append({
"username": user.username,
"name": user.name,
"uid": user.uid
})
return result
def get_pending_invitations(self, toid=None):
if toid is not None:
invitation = db.session.query(TeamInvitations).filter_by(rtype=0, frid=self.tid, toid=toid).first()

View file

@ -68,6 +68,55 @@ def team_invite():
return { "success": 1, "message": "Success!" }
@blueprint.route("/invite/rescind", methods=["POST"])
@api_wrapper
@login_required
def team_invite_rescind():
params = utils.flat_multi(request.form)
_user = user.get_user().first()
if not user.in_team(_user):
raise WebException("You must be in a team!")
_team = get_team(tid=_user.tid).first()
if _user.uid != _team.owner:
raise WebException("You must be the captain of your team to rescind invitations!")
uid = params.get("uid")
if uid is None:
raise WebException("Please provide a user.")
invitation = TeamInvitations.query.filter_by(rtype=0, frid=_team.tid, toid=uid).first()
if invitation is None:
raise WebException("Invitation doesn't exist.")
with app.app_context():
db.session.delete(invitation)
db.session.commit()
return { "success": 1, "message": "Success!" }
@blueprint.route("/invite/request", methods=["POST"])
@api_wrapper
@login_required
def team_invite_request():
params = utils.flat_multi(request.form)
_user = user.get_user().first()
if user.in_team(_user):
raise WebException("You're already in a team!")
tid = params.get("tid")
_team = get_team(tid=tid).first()
if _team is None:
raise WebException("Team not found.")
if _team.get_invitation_requests(frid=_user.uid) is not None:
raise WebException("You've already requested to join this team!")
req = TeamInvitations(1, _user.uid, _team.tid)
with app.app_context():
db.session.add(req)
db.session.commit()
return { "success": 1, "message": "Success!" }
@blueprint.route("/info", methods=["GET"])
@api_wrapper
def team_info():
@ -95,6 +144,11 @@ def team_info():
teamdata["is_owner"] = owner
if owner:
teamdata["pending_invitations"] = team.get_pending_invitations()
teamdata["invitation_requests"] = team.get_invitation_requests()
else:
if logged_in:
teamdata["invited"] = team.get_pending_invitations(toid=_user.uid) is not None
teamdata["requested"] = team.get_invitation_requests(frid=_user.uid) is not None
return { "success": 1, "team": teamdata }
##################

View file

@ -250,4 +250,24 @@ var add_member = function() {
location.reload(true);
}
});
};
var rescind_invitation = function(uid) {
var input = "#add_member input";
var data = { "uid": uid };
api_call("POST", "/api/team/invite/rescind", data, function(result) {
if (result["success"] == 1) {
location.reload(true);
}
});
};
var request_invitation = function(tid) {
var input = "#add_member input";
var data = { "tid": tid };
api_call("POST", "/api/team/invite/request", data, function(result) {
if (result["success"] == 1) {
location.reload(true);
}
});
};

View file

@ -42,7 +42,7 @@
<table class="table table-bordered">
<tr>
<th>Team Name</th>
<td>{{ user.team['teamname'] }}</td>
<td><a ng-href="/team/{{ user.team['teamname'] }}">{{ user.team['teamname'] }}</a></td>
</tr>
<tr>
<th>School</th>

View file

@ -46,7 +46,7 @@
</div>
</div>
<div class="panel-footer" ng-show="team['is_owner']==true">
<form id="add_member" onsubmit="add_member(); return false;" style="margin:none;">
<form id="add_member" onsubmit="add_member(); return false;" style="margin: 0;">
<div class="row">
<div class="col-xs-12">
<div class="input-group">
@ -62,7 +62,9 @@
<div class="panel-footer" ng-show="team['in_team']!=true && config.navbar['logged_in']==true">
<div class="row">
<div class="col-xs-12">
<a href="javascript:request_invitation();" class="btn btn-primary col-xs-12"><i class="fa fa-fw fa-plus"></i> Join this team</a>
<a ng-href="javascript:request_invitation({{ team['tid'] }});" class="btn btn-primary col-xs-12" ng-show="team['invited']!=true && team['requested']!=true"><i class="fa fa-fw fa-plus"></i> Join this team</a>
<a class="btn btn-primary col-xs-12 disabled" ng-show="team['invited']!=true && team['requested']==true"><i class="fa fa-fw fa-check"></i> Sent Request</a>
<a ng-href="javascript:accept_invitation({{ team['tid'] }});" class="btn btn-success col-xs-12" ng-show="team['invited']==true"><i class="fa fa-fw fa-check"></i> Accept Invitation</a>
</div>
</div>
</div>
@ -79,6 +81,18 @@
</div>
</div>
</div>
<div class="panel panel-default" ng-show="team['is_owner']==true && team['invitation_requests'].length > 0">
<div class="panel-heading">
<h4 class="panel-title">Invitation Requests</h4>
</div>
<div class="list-group">
<div class="list-group-item" ng-repeat="member in team['invitation_requests']">
<a class="badge" ng-href="javascript:accept_invitation_request({{ member['uid'] }});"><i class="fa fa-fw fa-check"></i></a>
<h4 class="list-group-item-heading">{{ member['name'] }}</h4>
<p class="list-group-item-text">@{{ member['username'] }}</p>
</div>
</div>
</div>
</div>
<div class="col-sm-9 col-xs-12">
</div>