Backend Refactoring

This commit is contained in:
Dmitriy Zaporozhets 2012-07-31 08:32:49 +03:00
parent 69e41250d1
commit 5926bbac12
11 changed files with 151 additions and 78 deletions

View file

@ -2,6 +2,7 @@ class Admin::ProjectsController < ApplicationController
layout "admin"
before_filter :authenticate_user!
before_filter :authenticate_admin!
before_filter :admin_project, :only => [:edit, :show, :update, :destroy, :team_update]
def index
@admin_projects = Project.scoped
@ -10,13 +11,9 @@ class Admin::ProjectsController < ApplicationController
end
def show
@admin_project = Project.find_by_code(params[:id])
@users = if @admin_project.users.empty?
User
else
User.not_in_project(@admin_project)
end.all
@users = User.scoped
@users = @users.not_in_project(@admin_project) if @admin_project.users.present?
@users = @users.all
end
def new
@ -24,19 +21,10 @@ class Admin::ProjectsController < ApplicationController
end
def edit
@admin_project = Project.find_by_code(params[:id])
end
def team_update
@admin_project = Project.find_by_code(params[:id])
UsersProject.bulk_import(
@admin_project,
params[:user_ids],
params[:project_access]
)
@admin_project.update_repository
@admin_project.add_users_ids_to_team(params[:user_ids], params[:project_access])
redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
end
@ -53,8 +41,6 @@ class Admin::ProjectsController < ApplicationController
end
def update
@admin_project = Project.find_by_code(params[:id])
owner_id = params[:project].delete(:owner_id)
if owner_id
@ -69,9 +55,14 @@ class Admin::ProjectsController < ApplicationController
end
def destroy
@admin_project = Project.find_by_code(params[:id])
@admin_project.destroy
redirect_to admin_projects_url, notice: 'Project was successfully deleted.'
end
private
def admin_project
@admin_project = Project.find_by_code(params[:id])
end
end

View file

@ -28,10 +28,7 @@ class HooksController < ApplicationController
end
def test
@hook = @project.hooks.find(params[:id])
commits = @project.commits(@project.default_branch, nil, 3)
data = @project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user)
@hook.execute(data)
TestHookContext.new(project, current_user, params).execute
redirect_to :back
end

View file

@ -15,11 +15,7 @@ class NotesController < ApplicationController
end
def create
@note = @project.notes.new(params[:note])
@note.author = current_user
@note.notify = true if params[:notify] == '1'
@note.notify_author = true if params[:notify_author] == '1'
@note.save
@note = Notes::CreateContext.new(project, current_user, params).execute
respond_to do |format|
format.html {redirect_to :back}
@ -40,6 +36,6 @@ class NotesController < ApplicationController
protected
def notes
@notes = NotesLoad.new(project, current_user, params).execute
@notes = Notes::LoadContext.new(project, current_user, params).execute
end
end

View file

@ -1,30 +1,26 @@
class ProfileController < ApplicationController
layout "profile"
before_filter :user
def show
@user = current_user
end
def design
@user = current_user
end
def update
@user = current_user
@user.update_attributes(params[:user])
redirect_to :back
end
def token
@user = current_user
end
def password
@user = current_user
end
def password_update
params[:user].reject!{ |k, v| k != "password" && k != "password_confirmation"}
@user = current_user
if @user.update_attributes(params[:user])
flash[:notice] = "Password was successfully updated. Please login with it"
@ -38,4 +34,10 @@ class ProfileController < ApplicationController
current_user.reset_authentication_token!
redirect_to profile_token_path
end
private
def user
@user = current_user
end
end

View file

@ -1,11 +1,12 @@
class SearchController < ApplicationController
def show
query = params[:search]
if query.blank?
@projects = []
@merge_requests = []
@issues = []
else
@projects = []
@merge_requests = []
@issues = []
if query.present?
@projects = current_user.projects.search(query).limit(10)
@merge_requests = MergeRequest.where(:project_id => current_user.project_ids).search(query).limit(10)
@issues = Issue.where(:project_id => current_user.project_ids).search(query).limit(10)