app/controllers/memberships_controller.rb in artfully_ose-1.1.0 vs app/controllers/memberships_controller.rb in artfully_ose-1.2.0.alpha.1

- old
+ new

@@ -1,57 +1,28 @@ -class MembershipsController < ActionController::Base - def new - @organization = Organization.find(params[:organization_id]) - end +class MembershipsController < ArtfullyOseController + before_filter :load_tags, :only => [:index] - def create - #This should pull from current_organization - @organization = Organization.find(params[:organization_id]) - authorize! :manage, @organization - - with_user do |user| - build_membership(user, @organization) or build_errors(user, @organization) - end - - redirect_to organization_url(@organization) and return + def index + @person = current_organization.people.find(params[:person_id]) + @expired_count = @person.memberships.lapsed.count + @membership_types = current_organization.membership_types end - def destroy - @organization = Organization.find(params[:organization_id]) - @mship = Membership.find(params[:id]) - authorize! :manage, @organization - @mship.destroy - redirect_to organization_url(@organization), :notice => "User has been removed from #{@organization.name}" and return + def bulk_update + @person = current_organization.people.find(params[:person_id]) + extend_memberships(params) + redirect_to person_memberships_path(@person) end private - def build_membership(user, organization) - membership = Membership.find_by_user_id_and_organization_id(user.id, organization.id) - return false unless membership.nil? and !user.memberships.any? - - @membership = organization.memberships.build(:user => user) - if @membership.save - flash[:notice] = "#{user.email} has been added successfully." - else - flash[:error] = "User #{user.email} could not been added." + def extend_memberships(params) + + #I hate how these are tied to the button text + if params[:commit].eql? "Change Expiration" + params[:membership_ids].each do |membership_id| + current_organization.memberships.find(membership_id).adjust_expiration_to(params[:ends_at]) + end + flash[:notice] = "Memberships have been adjusted." end - - return true end - - def build_errors(user, organization) - if user.organizations.first == organization - flash[:alert] = "#{user.email} is already a member of this organization." - else - flash[:error] = "User #{params[:user_email]} is already a member of another organization." - end - end - - def with_user(&block) - flash[:error] = "You must specify an email" and return if params[:user_email].blank? - user = User.find_by_email(params[:user_email]) || User.invite!({:email => params[:user_email]}, current_user) - flash[:error] = "Unable to find or invite a user with \"#{params[:user_email]}\"" unless user.valid? - block.call(user) if user.valid? - end - end \ No newline at end of file