2013-01-19 18:32:09 +01:00
|
|
|
class TeamsController < ApplicationController
|
2013-01-22 23:20:27 +01:00
|
|
|
# Authorize
|
2013-01-25 14:42:41 +01:00
|
|
|
before_filter :authorize_create_team!, only: [:new, :create]
|
|
|
|
before_filter :authorize_manage_user_team!, only: [:edit, :update]
|
|
|
|
before_filter :authorize_admin_user_team!, only: [:destroy]
|
2013-01-19 18:32:09 +01:00
|
|
|
|
2013-01-25 14:51:45 +01:00
|
|
|
before_filter :user_team, except: [:new, :create]
|
2013-01-19 18:32:09 +01:00
|
|
|
|
2013-01-25 14:51:45 +01:00
|
|
|
layout 'user_team', except: [:new, :create]
|
2013-01-19 18:32:09 +01:00
|
|
|
|
|
|
|
def show
|
2013-01-22 23:20:27 +01:00
|
|
|
user_team
|
|
|
|
projects
|
|
|
|
@events = Event.in_projects(user_team.project_ids).limit(20).offset(params[:offset] || 0)
|
2013-01-19 18:32:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-01-22 23:20:27 +01:00
|
|
|
user_team
|
2013-01-19 18:32:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if user_team.update_attributes(params[:user_team])
|
|
|
|
redirect_to team_path(user_team)
|
|
|
|
else
|
|
|
|
render action: :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
user_team.destroy
|
2013-01-25 15:18:37 +01:00
|
|
|
redirect_to dashboard_path
|
2013-01-19 18:32:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@team = UserTeam.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@team = UserTeam.new(params[:user_team])
|
|
|
|
@team.owner = current_user unless params[:owner]
|
|
|
|
@team.path = @team.name.dup.parameterize if @team.name
|
|
|
|
|
|
|
|
if @team.save
|
|
|
|
redirect_to team_path(@team)
|
|
|
|
else
|
|
|
|
render action: :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get authored or assigned open merge requests
|
|
|
|
def merge_requests
|
2013-01-23 15:14:53 +01:00
|
|
|
projects
|
2013-01-22 23:20:27 +01:00
|
|
|
@merge_requests = MergeRequest.of_user_team(user_team)
|
2013-01-19 18:32:09 +01:00
|
|
|
@merge_requests = FilterContext.new(@merge_requests, params).execute
|
|
|
|
@merge_requests = @merge_requests.recent.page(params[:page]).per(20)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Get only assigned issues
|
|
|
|
def issues
|
2013-01-23 15:14:53 +01:00
|
|
|
projects
|
2013-01-22 23:20:27 +01:00
|
|
|
@issues = Issue.of_user_team(user_team)
|
2013-01-19 18:32:09 +01:00
|
|
|
@issues = FilterContext.new(@issues, params).execute
|
|
|
|
@issues = @issues.recent.page(params[:page]).per(20)
|
|
|
|
@issues = @issues.includes(:author, :project)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def projects
|
|
|
|
@projects ||= user_team.projects.sorted_by_activity
|
|
|
|
end
|
|
|
|
|
2013-01-22 23:20:27 +01:00
|
|
|
def user_team
|
2013-01-25 14:51:45 +01:00
|
|
|
@team ||= current_user.authorized_teams.find_by_path(params[:id])
|
2013-01-19 18:32:09 +01:00
|
|
|
end
|
|
|
|
end
|