diff options
| author | Andrey Kumanyaev <me@zzet.org> | 2013-01-23 02:20:27 +0400 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-01-24 22:31:25 +0200 |
| commit | 18bd1c9d30e16783d750c7786cbcc7d350f4d0aa (patch) | |
| tree | 6218758f723e827cf90ea61f7bc4ed639ad6cc54 /app/controllers | |
| parent | 7658f8c151b22680cf594d028e180a8a859fc9b8 (diff) | |
| download | gitlab-ce-18bd1c9d30e16783d750c7786cbcc7d350f4d0aa.tar.gz | |
update all teams code. refactoring and some corrections
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/admin/teams/application_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/admin/teams/members_controller.rb | 18 | ||||
| -rw-r--r-- | app/controllers/admin/teams/projects_controller.rb | 16 | ||||
| -rw-r--r-- | app/controllers/admin/teams_controller.rb | 14 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 9 | ||||
| -rw-r--r-- | app/controllers/team_members_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/teams/application_controller.rb | 6 | ||||
| -rw-r--r-- | app/controllers/teams/members_controller.rb | 59 | ||||
| -rw-r--r-- | app/controllers/teams/projects_controller.rb | 15 | ||||
| -rw-r--r-- | app/controllers/teams_controller.rb | 59 |
10 files changed, 89 insertions, 109 deletions
diff --git a/app/controllers/admin/teams/application_controller.rb b/app/controllers/admin/teams/application_controller.rb index a2920b626b5..8710821454e 100644 --- a/app/controllers/admin/teams/application_controller.rb +++ b/app/controllers/admin/teams/application_controller.rb @@ -2,7 +2,6 @@ # # Automatically sets the layout and ensures an administrator is logged in class Admin::Teams::ApplicationController < Admin::ApplicationController - before_filter :user_team private diff --git a/app/controllers/admin/teams/members_controller.rb b/app/controllers/admin/teams/members_controller.rb index a6dbf6b5049..cdcc96c0aef 100644 --- a/app/controllers/admin/teams/members_controller.rb +++ b/app/controllers/admin/teams/members_controller.rb @@ -1,7 +1,7 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController def new @users = User.active - @users = @users.not_in_team(@team) if @team.members.any? + @users = @users.not_in_team(user_team) if user_team.members.any? @users = UserDecorator.decorate @users end @@ -10,10 +10,10 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController user_ids = params[:user_ids] access = params[:default_project_access] is_admin = params[:group_admin] - @team.add_members(user_ids, access, is_admin) + user_team.add_members(user_ids, access, is_admin) end - redirect_to admin_team_path(@team), notice: 'Members was successfully added.' + redirect_to admin_team_path(user_team), notice: 'Members was successfully added into Team of users.' end def edit @@ -22,24 +22,24 @@ class Admin::Teams::MembersController < Admin::Teams::ApplicationController def update options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} - if @team.update_membership(team_member, options) - redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' + if user_team.update_membership(team_member, options) + redirect_to admin_team_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users." else render :edit end end def destroy - if @team.remove_member(team_member) - redirect_to admin_team_path(@team), notice: "Member was successfully removed from team." + if user_team.remove_member(team_member) + redirect_to admin_team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." else - redirect_to admin_team_members(@team), notice: "Something wrong." + redirect_to admin_team_members(user_team), notice: "Something is wrong." end end protected def team_member - @member ||= @team.members.find(params[:id]) + @member ||= user_team.members.find(params[:id]) end end diff --git a/app/controllers/admin/teams/projects_controller.rb b/app/controllers/admin/teams/projects_controller.rb index f255b8448ab..8584a188b20 100644 --- a/app/controllers/admin/teams/projects_controller.rb +++ b/app/controllers/admin/teams/projects_controller.rb @@ -1,7 +1,7 @@ class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController def new @projects = Project.scoped - @projects = @projects.without_team(@team) if @team.projects.any? + @projects = @projects.without_team(user_team) if user_team.projects.any? #@projects.reject!(&:empty_repo?) end @@ -9,10 +9,10 @@ class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController unless params[:project_ids].blank? project_ids = params[:project_ids] access = params[:greatest_project_access] - @team.assign_to_projects(project_ids, access) + user_team.assign_to_projects(project_ids, access) end - redirect_to admin_team_path(@team), notice: 'Projects was successfully added.' + redirect_to admin_team_path(user_team), notice: 'Team of users was successfully assgned to projects.' end def edit @@ -20,22 +20,22 @@ class Admin::Teams::ProjectsController < Admin::Teams::ApplicationController end def update - if @team.update_project_access(team_project, params[:greatest_project_access]) - redirect_to admin_team_path(@team), notice: 'Membership was successfully updated.' + if user_team.update_project_access(team_project, params[:greatest_project_access]) + redirect_to admin_team_path(user_team), notice: 'Access was successfully updated.' else render :edit end end def destroy - @team.resign_from_project(team_project) - redirect_to admin_team_path(@team), notice: 'Project was successfully removed.' + user_team.resign_from_project(team_project) + redirect_to admin_team_path(user_team), notice: 'Team of users was successfully reassigned from project.' end protected def team_project - @project ||= @team.projects.find_by_path(params[:id]) + @project ||= user_team.projects.find_with_namespace(params[:id]) end end diff --git a/app/controllers/admin/teams_controller.rb b/app/controllers/admin/teams_controller.rb index f42ec10585b..7371f4a446c 100644 --- a/app/controllers/admin/teams_controller.rb +++ b/app/controllers/admin/teams_controller.rb @@ -24,12 +24,12 @@ class Admin::TeamsController < Admin::ApplicationController end def create - user_team = UserTeam.new(params[:user_team]) - user_team.path = user_team.name.dup.parameterize if user_team.name - user_team.owner = current_user + @team = UserTeam.new(params[:user_team]) + @team.path = @team.name.dup.parameterize if @team.name + @team.owner = current_user - if user_team.save - redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully created.' + if @team.save + redirect_to admin_team_path(@team), notice: 'Team of users was successfully created.' else render action: "new" end @@ -44,7 +44,7 @@ class Admin::TeamsController < Admin::ApplicationController end if user_team.update_attributes(user_team_params) - redirect_to admin_team_path(user_team), notice: 'UserTeam was successfully updated.' + redirect_to admin_team_path(user_team), notice: 'Team of users was successfully updated.' else render action: "edit" end @@ -53,7 +53,7 @@ class Admin::TeamsController < Admin::ApplicationController def destroy user_team.destroy - redirect_to admin_user_teams_path, notice: 'UserTeam was successfully deleted.' + redirect_to admin_user_teams_path, notice: 'Team of users was successfully deleted.' end protected diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3457a1ab1b4..f903c7fdd62 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -94,6 +94,14 @@ class ApplicationController < ActionController::Base return access_denied! unless can?(current_user, :download_code, project) end + def authorize_manage_user_team! + return access_denied! unless user_team.present? && can?(current_user, :manage_user_team, user_team) + end + + def authorize_admin_user_team! + return access_denied! unless user_team.present? && can?(current_user, :admin_user_team, user_team) + end + def access_denied! render "errors/access_denied", layout: "errors", status: 404 end @@ -135,4 +143,5 @@ class ApplicationController < ActionController::Base def dev_tools Rack::MiniProfiler.authorize_request end + end diff --git a/app/controllers/team_members_controller.rb b/app/controllers/team_members_controller.rb index 2b48e29ed7d..7e4c8792b50 100644 --- a/app/controllers/team_members_controller.rb +++ b/app/controllers/team_members_controller.rb @@ -4,6 +4,7 @@ class TeamMembersController < ProjectResourceController before_filter :authorize_admin_project!, except: [:index, :show] def index + @teams = UserTeam.scoped end def show diff --git a/app/controllers/teams/application_controller.rb b/app/controllers/teams/application_controller.rb index ff73f6b4eb0..2c1583d943e 100644 --- a/app/controllers/teams/application_controller.rb +++ b/app/controllers/teams/application_controller.rb @@ -5,11 +5,7 @@ class Teams::ApplicationController < ApplicationController protected def user_team - @user_team ||= UserTeam.find_by_path(params[:team_id]) - end - - def authorize_manage_user_team! - return access_denied! unless can?(current_user, :manage_user_team, user_team) + @team ||= UserTeam.find_by_path(params[:team_id]) end end diff --git a/app/controllers/teams/members_controller.rb b/app/controllers/teams/members_controller.rb index 111ad5c2f3d..95b8de1861b 100644 --- a/app/controllers/teams/members_controller.rb +++ b/app/controllers/teams/members_controller.rb @@ -1,58 +1,53 @@ class Teams::MembersController < Teams::ApplicationController - # Authorize + skip_before_filter :authorize_manage_user_team!, only: [:index] def index - @members = @user_team.members - end - - def show - @team_member = @user_team.members.find(params[:id]) - @events = @team_member.recent_events.limit(7) + @members = user_team.members end def new - @team_member = @user_team.members.new + @users = User.active + @users = @users.not_in_team(user_team) if user_team.members.any? + @users = UserDecorator.decorate @users end def create - users = User.where(id: params[:user_ids]) + unless params[:user_ids].blank? + user_ids = params[:user_ids] + access = params[:default_project_access] + is_admin = params[:group_admin] + user_team.add_members(user_ids, access, is_admin) + end - @project.team << [users, params[:default_project_access]] + redirect_to team_path(user_team), notice: 'Members was successfully added into Team of users.' + end - if params[:redirect_to] - redirect_to params[:redirect_to] - else - redirect_to project_team_index_path(@project) - end + def edit + team_member end def update - @team_member = @user_team.members.find(params[:id]) - @team_member.update_attributes(params[:team_member]) - - unless @team_member.valid? - flash[:alert] = "User should have at least one role" + options = {default_projects_access: params[:default_project_access], group_admin: params[:group_admin]} + if user_team.update_membership(team_member, options) + redirect_to team_path(user_team), notice: "Membership for #{team_member.name} was successfully updated in Team of users." + else + render :edit end - redirect_to team_member_path(@project) end def destroy - @team_member = project.users_projects.find(params[:id]) - @team_member.destroy - - respond_to do |format| - format.html { redirect_to project_team_index_path(@project) } - format.js { render nothing: true } + if user_team.remove_member(team_member) + redirect_to team_path(user_team), notice: "Member #{team_member.name} was successfully removed from Team of users." + else + redirect_to team_members(user_team), notice: "Something is wrong." end end - def apply_import - giver = Project.find(params[:source_project_id]) - status = @project.team.import(giver) - notice = status ? "Succesfully imported" : "Import failed" + protected - redirect_to project_team_members_path(project), notice: notice + def team_member + @member ||= user_team.members.find(params[:id]) end end diff --git a/app/controllers/teams/projects_controller.rb b/app/controllers/teams/projects_controller.rb index 6255853f8c9..21ddba865f3 100644 --- a/app/controllers/teams/projects_controller.rb +++ b/app/controllers/teams/projects_controller.rb @@ -8,9 +8,12 @@ class Teams::ProjectsController < Teams::ApplicationController end def new - @projects = Project.scoped - @projects = @projects.without_team(user_team) if user_team.projects.any? + user_team + @avaliable_projects = Project.scoped + @avaliable_projects = @avaliable_projects.without_team(user_team) if user_team.projects.any? #@projects.reject!(&:empty_repo?) + + redirect_to team_projects_path(user_team), notice: "No avalible projects." unless @avaliable_projects.any? end def create @@ -20,7 +23,7 @@ class Teams::ProjectsController < Teams::ApplicationController user_team.assign_to_projects(project_ids, access) end - redirect_to admin_team_path(user_team), notice: 'Projects was successfully added.' + redirect_to team_projects_path(user_team), notice: 'Team of users was successfully assgned to projects.' end def edit @@ -29,7 +32,7 @@ class Teams::ProjectsController < Teams::ApplicationController def update if user_team.update_project_access(team_project, params[:greatest_project_access]) - redirect_to admin_team_path(user_team), notice: 'Membership was successfully updated.' + redirect_to team_projects_path(user_team), notice: 'Access was successfully updated.' else render :edit end @@ -37,13 +40,13 @@ class Teams::ProjectsController < Teams::ApplicationController def destroy user_team.resign_from_project(team_project) - redirect_to admin_team_path(user_team), notice: 'Project was successfully removed.' + redirect_to team_projects_path(user_team), notice: 'Team of users was successfully reassigned from project.' end private def team_project - @project ||= @team.projects.find_by_path(params[:id]) + @project ||= user_team.projects.find_with_namespace(params[:id]) end end diff --git a/app/controllers/teams_controller.rb b/app/controllers/teams_controller.rb index 4e3703d72d4..169ee34f4ec 100644 --- a/app/controllers/teams_controller.rb +++ b/app/controllers/teams_controller.rb @@ -1,30 +1,26 @@ class TeamsController < ApplicationController - respond_to :html - layout 'user_team', only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] + # Authorize + before_filter :authorize_manage_user_team! + before_filter :authorize_admin_user_team! - before_filter :user_team, only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] - before_filter :projects, only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] + # Skip access control on public section + skip_before_filter :authorize_manage_user_team!, only: [:index, :show, :new, :destroy, :create, :search, :issues, :merge_requests] + skip_before_filter :authorize_admin_user_team!, only: [:index, :show, :new, :create, :search, :issues, :merge_requests] - # Authorize - before_filter :authorize_manage_user_team!, only: [:edit, :update] - before_filter :authorize_admin_user_team!, only: [:destroy] + layout 'user_team', only: [:show, :edit, :update, :destroy, :issues, :merge_requests, :search] def index - @teams = UserTeam.all + @teams = UserTeam.order('name ASC') end def show - @events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0) - - respond_to do |format| - format.html - format.js - format.atom { render layout: false } - end + user_team + projects + @events = Event.in_projects(user_team.project_ids).limit(20).offset(params[:offset] || 0) end def edit - + user_team end def update @@ -58,56 +54,37 @@ class TeamsController < ApplicationController # Get authored or assigned open merge requests def merge_requests - @merge_requests = MergeRequest.of_user_team(@user_team) + @merge_requests = MergeRequest.of_user_team(user_team) @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 - @issues = Issue.of_user_team(@user_team) + @issues = Issue.of_user_team(user_team) @issues = FilterContext.new(@issues, params).execute @issues = @issues.recent.page(params[:page]).per(20) @issues = @issues.includes(:author, :project) - - respond_to do |format| - format.html - format.atom { render layout: false } - end end def search - result = SearchContext.new(project_ids, params).execute + result = SearchContext.new(user_team.project_ids, params).execute @projects = result[:projects] @merge_requests = result[:merge_requests] @issues = result[:issues] @wiki_pages = result[:wiki_pages] + @teams = result[:teams] end protected - def user_team - @user_team ||= UserTeam.find_by_path(params[:id]) - end - def projects @projects ||= user_team.projects.sorted_by_activity end - def project_ids - projects.map(&:id) - end - - def authorize_manage_user_team! - unless user_team.present? or can?(current_user, :manage_user_team, user_team) - return render_404 - end + def user_team + @team ||= UserTeam.find_by_path(params[:id]) end - def authorize_admin_user_team! - unless user_team.owner == current_user || current_user.admin? - return render_404 - end - end end |
