CSC/ECE 517 Fall 2013/oss cmh: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
Line 24: Line 24:


=== Accept Method ===
=== Accept Method ===
<pre>
def accept
    @inv = Invitation.find(params[:inv_id])
    @inv.reply_status = 'A'
    @inv.save
    invited_user_id = Participant.find(params[:student_id]).user_id
   
    #Remove the users previous team since they are accepting an invite for possibly a new team.
    TeamsUser.remove_team(invited_user_id, params[:team_id])
    #Accept the invite and return boolean on whether the add was successful
    add_successful = Invitation.accept_invite(params[:team_id], @inv.from_id, @inv.to_id)
    #If add wasn't successful because team was full display message
    unless add_successful
      flash[:error]= "The team already has the maximum number of members."
    end
    redirect_to :controller => 'student_team', :action => 'view', :id => Participant.find(params[:student_id]).id
end
</pre>


== Bug Fixes ==
== Bug Fixes ==

Revision as of 21:11, 29 October 2013

Introduction

What the invitation controller does and the process advertising, creating invites and accepting invites.

Project Description

Classes: invitation_controller.rb (104 lines) invitation.rb (5 lines)

What it does: Handles invitations to join teams.

What needs to be done: The code is deeply nested and quite confusing. There should be a single method responsible for finding whether a user is already on a team, adding someone onto a waitlist, dropping someone off of a waitlist, changing/updating the topic that the user is assigned to, etc. Some of these methods should be in model classes, such as invitation.rb and signed_up_user.rb. Break the complicated methods into shorter methods with clear names, and place these methods in the most appropriate class, moving a lot of functionality to the model classes.

Currently, after someone joins a team, pending invitations are not removed. There should be a method handling deletion of invitations (including declined invitations) to a user after that user joins a team. This should be a model method.

Though this class is not long, the code looks and reads like it is very complicated. Breaking it down into multiple methods with clear names and proper division of functionality between classes will be a challenge.

Motivation

Briefly talk about why invitation controller needed refactoring.

Design Changes

Create Method

Accept Method

def accept
    @inv = Invitation.find(params[:inv_id])
    @inv.reply_status = 'A'
    @inv.save

    invited_user_id = Participant.find(params[:student_id]).user_id
    
    #Remove the users previous team since they are accepting an invite for possibly a new team.
    TeamsUser.remove_team(invited_user_id, params[:team_id])
    #Accept the invite and return boolean on whether the add was successful
    add_successful = Invitation.accept_invite(params[:team_id], @inv.from_id, @inv.to_id)
    #If add wasn't successful because team was full display message
    unless add_successful
      flash[:error]= "The team already has the maximum number of members."
    end

    redirect_to :controller => 'student_team', :action => 'view', :id => Participant.find(params[:student_id]).id
end

Bug Fixes

Error Messages

Invite Requests

Future Work