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-01-22 17:20:27 -05:00
|
|
|
@teams = UserTeam.scoped
|
2012-09-16 10:56:32 -04:00
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
def show
|
2013-01-22 12:20:39 -05:00
|
|
|
@user_project_relation = project.users_projects.find_by_user_id(member)
|
|
|
|
@events = member.recent_events.in_projects(project).limit(7)
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
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-01-04 01:43:25 -05:00
|
|
|
users = User.where(id: params[:user_ids])
|
|
|
|
|
|
|
|
@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-22 12:20:39 -05:00
|
|
|
@user_project_relation = project.users_projects.find_by_user_id(params[:id])
|
|
|
|
@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"
|
|
|
|
|
|
|
|
redirect_to project_team_members_path(project), notice: notice
|
|
|
|
end
|
2013-01-22 12:20:39 -05:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def member
|
|
|
|
@member ||= User.find(params[:id])
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|