Refactor abilities. Added ProjectUpdate context. Fixed few bugs with namespaces
This commit is contained in:
parent
a1ffc673b9
commit
eb1004f789
18 changed files with 127 additions and 53 deletions
|
@ -24,13 +24,9 @@ class Admin::ProjectsController < AdminController
|
|||
end
|
||||
|
||||
def update
|
||||
owner_id = params[:project].delete(:owner_id)
|
||||
status = ProjectUpdateContext.new(project, current_user, params).execute(:admin)
|
||||
|
||||
if owner_id
|
||||
@project.owner = User.find(owner_id)
|
||||
end
|
||||
|
||||
if @project.update_attributes(params[:project], as: :admin)
|
||||
if status
|
||||
redirect_to [:admin, @project], notice: 'Project was successfully updated.'
|
||||
else
|
||||
render action: "edit"
|
||||
|
|
|
@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base
|
|||
before_filter :authenticate_user!
|
||||
before_filter :reject_blocked!
|
||||
before_filter :set_current_user_for_observers
|
||||
before_filter :add_abilities
|
||||
before_filter :dev_tools if Rails.env == 'development'
|
||||
|
||||
protect_from_forgery
|
||||
|
@ -65,11 +66,17 @@ class ApplicationController < ActionController::Base
|
|||
def project
|
||||
id = params[:project_id] || params[:id]
|
||||
|
||||
@project ||= current_user.projects.find_with_namespace(id)
|
||||
@project || render_404
|
||||
@project = Project.find_with_namespace(id)
|
||||
|
||||
if @project and can?(current_user, :read_project, @project)
|
||||
@project
|
||||
else
|
||||
@project = nil
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
def add_project_abilities
|
||||
def add_abilities
|
||||
abilities << Ability
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ class DashboardController < ApplicationController
|
|||
before_filter :event_filter, only: :index
|
||||
|
||||
def index
|
||||
@groups = Group.where(id: current_user.projects.pluck(:namespace_id))
|
||||
@groups = current_user.accessed_groups
|
||||
@projects = @projects.page(params[:page]).per(30)
|
||||
@events = Event.in_projects(current_user.project_ids)
|
||||
@events = @event_filter.apply_filter(@events)
|
||||
|
|
|
@ -4,7 +4,6 @@ class GroupsController < ApplicationController
|
|||
|
||||
before_filter :group
|
||||
before_filter :projects
|
||||
before_filter :add_project_abilities
|
||||
|
||||
def show
|
||||
@events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0)
|
||||
|
@ -45,7 +44,7 @@ class GroupsController < ApplicationController
|
|||
end
|
||||
|
||||
def people
|
||||
@users = group.users.all
|
||||
@users = group.users
|
||||
end
|
||||
|
||||
protected
|
||||
|
@ -55,7 +54,11 @@ class GroupsController < ApplicationController
|
|||
end
|
||||
|
||||
def projects
|
||||
@projects ||= current_user.projects_sorted_by_activity.where(namespace_id: @group.id)
|
||||
@projects ||= if can?(current_user, :manage_group, @group)
|
||||
@group.projects.all
|
||||
else
|
||||
current_user.projects_sorted_by_activity.where(namespace_id: @group.id)
|
||||
end
|
||||
end
|
||||
|
||||
def project_ids
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
class ProjectResourceController < ApplicationController
|
||||
before_filter :project
|
||||
# Authorize
|
||||
before_filter :add_project_abilities
|
||||
end
|
||||
|
|
|
@ -34,20 +34,10 @@ class ProjectsController < ProjectResourceController
|
|||
end
|
||||
|
||||
def update
|
||||
if params[:project].has_key?(:namespace_id)
|
||||
namespace_id = params[:project].delete(:namespace_id)
|
||||
if namespace_id == Namespace.global_id and project.namespace.present?
|
||||
# Transfer to global namespace from anyone
|
||||
project.transfer(nil)
|
||||
elsif namespace_id.present? and namespace_id.to_i != project.namespace_id
|
||||
# Transfer to someone namespace
|
||||
namespace = Namespace.find(namespace_id)
|
||||
project.transfer(namespace)
|
||||
end
|
||||
end
|
||||
status = ProjectUpdateContext.new(project, current_user, params).execute
|
||||
|
||||
respond_to do |format|
|
||||
if project.update_attributes(params[:project])
|
||||
if status
|
||||
flash[:notice] = 'Project was successfully updated.'
|
||||
format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' }
|
||||
format.js
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue