2012-09-27 14:59:42 -04:00
|
|
|
class TeamMembersController < ProjectResourceController
|
2011-10-08 17:36:38 -04:00
|
|
|
# Authorize
|
2011-10-17 06:39:03 -04:00
|
|
|
before_filter :authorize_read_project!
|
2012-09-16 10:56:32 -04:00
|
|
|
before_filter :authorize_admin_project!, except: [:index, :show]
|
|
|
|
|
|
|
|
def index
|
2013-02-18 14:10:49 -05:00
|
|
|
@team = @project.users_projects.scoped
|
|
|
|
@team = @team.send(params[:type]) if %w(masters developers reporters guests).include?(params[:type])
|
|
|
|
@team = @team.sort_by(&:project_access).reverse.group_by(&:project_access)
|
2013-02-18 14:21:24 -05:00
|
|
|
|
|
|
|
@assigned_teams = @project.user_team_project_relationships
|
2012-09-16 10:56:32 -04:00
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
def new
|
2013-01-22 12:20:39 -05:00
|
|
|
@user_project_relation = project.users_projects.new
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2013-03-13 15:42:14 -04:00
|
|
|
users = User.where(id: params[:user_ids].split(','))
|
2013-01-04 01:43:25 -05:00
|
|
|
|
|
|
|
@project.team << [users, params[:project_access]]
|
2012-09-07 02:50:35 -04:00
|
|
|
|
2012-11-29 12:14:05 -05:00
|
|
|
if params[:redirect_to]
|
|
|
|
redirect_to params[:redirect_to]
|
|
|
|
else
|
|
|
|
redirect_to project_team_index_path(@project)
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-01-22 12:20:39 -05:00
|
|
|
@user_project_relation = project.users_projects.find_by_user_id(member)
|
|
|
|
@user_project_relation.update_attributes(params[:team_member])
|
2011-10-08 17:36:38 -04:00
|
|
|
|
2013-01-22 12:20:39 -05:00
|
|
|
unless @user_project_relation.valid?
|
2011-12-06 18:27:07 -05:00
|
|
|
flash[:alert] = "User should have at least one role"
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
2012-09-16 09:21:20 -04:00
|
|
|
redirect_to project_team_index_path(@project)
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2013-01-25 13:34:49 -05:00
|
|
|
@user_project_relation = project.users_projects.find_by_user_id(member)
|
2013-01-22 12:20:39 -05:00
|
|
|
@user_project_relation.destroy
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
respond_to do |format|
|
2012-09-16 09:21:20 -04:00
|
|
|
format.html { redirect_to project_team_index_path(@project) }
|
2012-08-10 18:07:50 -04:00
|
|
|
format.js { render nothing: true }
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
end
|
2012-10-24 07:20:53 -04:00
|
|
|
|
|
|
|
def apply_import
|
|
|
|
giver = Project.find(params[:source_project_id])
|
2013-01-04 01:43:25 -05:00
|
|
|
status = @project.team.import(giver)
|
2012-10-24 07:20:53 -04:00
|
|
|
notice = status ? "Succesfully imported" : "Import failed"
|
|
|
|
|
2013-04-11 02:39:49 -04:00
|
|
|
redirect_to project_team_index_path(project), notice: notice
|
2012-10-24 07:20:53 -04:00
|
|
|
end
|
2013-01-22 12:20:39 -05:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def member
|
2013-01-25 13:34:49 -05:00
|
|
|
@member ||= User.find_by_username(params[:id])
|
2013-01-22 12:20:39 -05:00
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|