[#343] use new ruby hash syntax

This commit is contained in:
Alexander Machehin 2014-01-21 10:51:49 +06:00
parent 5954583959
commit 0e39aae1bf
691 changed files with 4611 additions and 4669 deletions

36
Gemfile
View File

@ -1,7 +1,7 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'rails', '3.2.16' #, :git => 'git://github.com/rails/rails.git' gem 'rails', '3.2.16' #, git: 'git://github.com/rails/rails.git'
gem 'redhillonrails_core', :git => 'git://github.com/rosa-abf/redhillonrails_core.git', :branch => 'rails31' # '~> 2.0.0.pre' # deprecated gem 'redhillonrails_core', git: 'git://github.com/rosa-abf/redhillonrails_core.git', branch: 'rails31' # '~> 2.0.0.pre' # deprecated
gem 'pg', '~> 0.14.0' gem 'pg', '~> 0.14.0'
@ -24,10 +24,10 @@ gem 'highline', '~> 1.6.11'
gem 'state_machine' gem 'state_machine'
gem 'redis-rails' gem 'redis-rails'
gem 'grack', :git => 'git://github.com/rosa-abf/grack.git', :require => 'git_http' gem 'grack', git: 'git://github.com/rosa-abf/grack.git', require: 'git_http'
gem 'grit', :git => 'git://github.com/rosa-abf/grit.git' gem 'grit', git: 'git://github.com/rosa-abf/grit.git'
gem 'charlock_holmes', '~> 0.6.9' gem 'charlock_holmes', '~> 0.6.9'
gem 'github-linguist', '~> 2.3.4', :require => 'linguist' gem 'github-linguist', '~> 2.3.4', require: 'linguist'
gem 'diff-display', '~> 0.0.1' gem 'diff-display', '~> 0.0.1'
# Wiki # Wiki
@ -39,17 +39,17 @@ gem 'rdiscount'
gem 'RedCloth' gem 'RedCloth'
gem 'wikicloth' gem 'wikicloth'
# gem 'unicorn', '~> 4.3.1', :platforms => [:mri, :rbx] # gem 'unicorn', '~> 4.3.1', platforms: [:mri, :rbx]
gem 'trinidad', '~> 1.0.2', :platforms => :jruby gem 'trinidad', '~> 1.0.2', platforms: :jruby
gem 'newrelic_rpm' gem 'newrelic_rpm'
# gem 'whenever', '~> 0.7.3', :require => false # gem 'whenever', '~> 0.7.3', require: false
gem 'whenever', '~> 0.9.0', :require => false gem 'whenever', '~> 0.9.0', require: false
gem 'jbuilder', '~> 1.4.2' gem 'jbuilder', '~> 1.4.2'
gem 'rails3-jquery-autocomplete', '~> 1.0.7' gem 'rails3-jquery-autocomplete', '~> 1.0.7'
gem 'will_paginate', '~> 3.0.3' gem 'will_paginate', '~> 3.0.3'
gem 'meta-tags', '~> 1.2.5', :require => 'meta_tags' gem 'meta-tags', '~> 1.2.5', require: 'meta_tags'
gem "haml-rails", '~> 0.3.4' gem "haml-rails", '~> 0.3.4'
gem 'jquery-rails', '~> 2.0.2' gem 'jquery-rails', '~> 2.0.2'
gem 'ruby-haml-js', '~> 0.0.3' gem 'ruby-haml-js', '~> 0.0.3'
@ -81,14 +81,14 @@ group :assets do
gem 'coffee-rails', '~> 3.2.2' gem 'coffee-rails', '~> 3.2.2'
gem 'compass-rails', '~> 1.0.3' gem 'compass-rails', '~> 1.0.3'
gem 'uglifier', '~> 1.2.4' gem 'uglifier', '~> 1.2.4'
gem 'therubyracer', '~> 0.10.2', :platforms => [:mri, :rbx] gem 'therubyracer', '~> 0.10.2', platforms: [:mri, :rbx]
gem 'therubyrhino', '~> 1.73.1', :platforms => :jruby gem 'therubyrhino', '~> 1.73.1', platforms: :jruby
gem 'turbo-sprockets-rails3' gem 'turbo-sprockets-rails3'
end end
group :production do group :production do
gem "airbrake", '~> 3.1.2' gem "airbrake", '~> 3.1.2'
gem 'bluepill', '~> 0.0.60', :require => false gem 'bluepill', '~> 0.0.60', require: false
# gem 'le' # gem 'le'
gem 'logglier' gem 'logglier'
gem 'puma' gem 'puma'
@ -100,10 +100,10 @@ group :development do
gem 'hirb' gem 'hirb'
gem 'shotgun' gem 'shotgun'
# deploy # deploy
gem 'capistrano', :require => false gem 'capistrano', require: false
gem 'rvm-capistrano', :require => false gem 'rvm-capistrano', require: false
gem 'cape', :require => false gem 'cape', require: false
gem 'capistrano_colors', :require => false gem 'capistrano_colors', require: false
# Better Errors & RailsPanel # Better Errors & RailsPanel
gem 'better_errors' gem 'better_errors'
gem 'binding_of_caller' gem 'binding_of_caller'
@ -112,7 +112,7 @@ group :development do
end end
group :test do group :test do
gem 'rspec-rails', '~> 2.11.0', :group => 'development' gem 'rspec-rails', '~> 2.11.0', group: 'development'
gem 'factory_girl_rails', '~> 4.0.0' gem 'factory_girl_rails', '~> 4.0.0'
gem 'rr', '~> 1.0.4' gem 'rr', '~> 1.0.4'
gem 'shoulda' gem 'shoulda'

View File

@ -1,5 +1,5 @@
class Admin::EventLogsController < Admin::BaseController class Admin::EventLogsController < Admin::BaseController
def index def index
@event_logs = EventLog.default_order.eager_loading.paginate :page => params[:page] @event_logs = EventLog.default_order.eager_loading.paginate page: params[:page]
end end
end end

View File

@ -1,10 +1,10 @@
class Admin::FlashNotifiesController < Admin::BaseController class Admin::FlashNotifiesController < Admin::BaseController
def index def index
@flash_notifies = FlashNotify.paginate(:page => params[:page], :per_page => 20) @flash_notifies = FlashNotify.paginate(page: params[:page], per_page: 20)
end end
def new def new
@flash_notify = FlashNotify.new(:published => true) @flash_notify = FlashNotify.new(published: true)
end end
def create def create

View File

@ -1,20 +1,20 @@
class Admin::RegisterRequestsController < Admin::BaseController class Admin::RegisterRequestsController < Admin::BaseController
def index def index
@register_requests = @register_requests.send((params[:scope] || 'unprocessed').to_sym).paginate(:page => params[:page]) @register_requests = @register_requests.send((params[:scope] || 'unprocessed').to_sym).paginate(page: params[:page])
end end
def update def update
RegisterRequest.where(:id => params[:request_ids]).each(&params[:update_type].to_sym) if params[:update_type].present? && params[:request_ids].present? RegisterRequest.where(id: params[:request_ids]).each(&params[:update_type].to_sym) if params[:update_type].present? && params[:request_ids].present?
redirect_to :action => :index redirect_to action: :index
end end
def approve def approve
@register_request.approve @register_request.approve
redirect_to :action => :index redirect_to action: :index
end end
def reject def reject
@register_request.reject @register_request.reject
redirect_to :action => :index redirect_to action: :index
end end
end end

View File

@ -1,7 +1,7 @@
class Admin::UsersController < Admin::BaseController class Admin::UsersController < Admin::BaseController
include AvatarHelper include AvatarHelper
prepend_before_filter :find_user prepend_before_filter :find_user
load_and_authorize_resource :collection => [:system, :list] load_and_authorize_resource collection: [:system, :list]
def index def index
@filter = params[:filter] || 'all' @filter = params[:filter] || 'all'
@ -29,7 +29,7 @@ class Admin::UsersController < Admin::BaseController
flash[:warning] = @user.errors.full_messages.join('. ') flash[:warning] = @user.errors.full_messages.join('. ')
@system = @user.system? @system = @user.system?
render :action => :new render action: :new
end end
end end
@ -45,7 +45,7 @@ class Admin::UsersController < Admin::BaseController
else else
flash[:error] = t('flash.user.save_error') flash[:error] = t('flash.user.save_error')
flash[:warning] = @user.errors.full_messages.join('. ') flash[:warning] = @user.errors.full_messages.join('. ')
render :action => :edit render action: :edit
end end
end end
@ -65,7 +65,7 @@ class Admin::UsersController < Admin::BaseController
sort_dir = params[:sSortDir_0]=="asc" ? 'asc' : 'desc' sort_dir = params[:sSortDir_0]=="asc" ? 'asc' : 'desc'
order = "users.#{colName[sort_col.to_i]} #{sort_dir}" order = "users.#{colName[sort_col.to_i]} #{sort_dir}"
@users = @users.paginate(:page => (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, :per_page => params[:iDisplayLength]) @users = @users.paginate(page: (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, per_page: params[:iDisplayLength])
@total_users = @users.count @total_users = @users.count
if !params[:sSearch].blank? && search = "%#{params[:sSearch]}%" if !params[:sSearch].blank? && search = "%#{params[:sSearch]}%"
@users = @users.where('users.name ILIKE ? or users.uname ILIKE ? or users.email ILIKE ?', search, search, search) @users = @users.where('users.name ILIKE ? or users.uname ILIKE ? or users.email ILIKE ?', search, search, search)
@ -74,7 +74,7 @@ class Admin::UsersController < Admin::BaseController
@users = @users.send(@filter) if ['real', 'admin', 'banned', 'tester'].include? @filter @users = @users.send(@filter) if ['real', 'admin', 'banned', 'tester'].include? @filter
@users = @users.order(order) @users = @users.order(order)
render :partial => 'users_ajax', :layout => false render partial: 'users_ajax', layout: false
end end
def reset_auth_token def reset_auth_token

View File

@ -1,13 +1,13 @@
class AdvisoriesController < ApplicationController class AdvisoriesController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user! if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user! if APP_CONFIG['anonymous_access']
load_resource :find_by => :advisory_id load_resource find_by: :advisory_id
authorize_resource authorize_resource
def index def index
@advisories = @advisories.scoped(:include => :platforms) @advisories = @advisories.scoped(include: :platforms)
@advisories = @advisories.search_by_id(params[:q]) if params[:q] @advisories = @advisories.search_by_id(params[:q]) if params[:q]
@advisories = @advisories.paginate(:page => params[:page]) @advisories = @advisories.paginate(page: params[:page])
respond_to do |format| respond_to do |format|
format.html format.html
format.atom format.atom
@ -21,7 +21,7 @@ class AdvisoriesController < ApplicationController
def search def search
@advisory = Advisory.by_update_type(params[:bl_type]).search_by_id(params[:query]).first @advisory = Advisory.by_update_type(params[:bl_type]).search_by_id(params[:query]).first
if @advisory.nil? if @advisory.nil?
render :nothing => true, :status => 404 render nothing: true, status: 404
else else
# respond_to do |format| # respond_to do |format|
# format.json { render @advisory } # format.json { render @advisory }

View File

@ -1,12 +1,12 @@
class Api::V1::AdvisoriesController < Api::V1::BaseController class Api::V1::AdvisoriesController < Api::V1::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
load_resource :advisory, :find_by => :advisory_id load_resource :advisory, find_by: :advisory_id
before_filter :find_and_authorize_build_list, :only => [:create, :update] before_filter :find_and_authorize_build_list, only: [:create, :update]
authorize_resource :build_list, :only => [:create, :update] authorize_resource :build_list, only: [:create, :update]
def index def index
@advisories = @advisories.scoped(:include => [:platforms, :projects]). @advisories = @advisories.scoped(include: [:platforms, :projects]).
paginate(paginate_params) paginate(paginate_params)
end end

View File

@ -47,7 +47,7 @@ class Api::V1::BaseController < ApplicationController
role = params[:role] role = params[:role]
class_name = subject.class.name.downcase class_name = subject.class.name.downcase
if member.present? && role.present? && subject.respond_to?(:owner) && subject.owner != member && if member.present? && role.present? && subject.respond_to?(:owner) && subject.owner != member &&
subject.send(relation).by_actor(member).update_all(:role => role) subject.send(relation).by_actor(member).update_all(role: role)
render_json_response subject, "Role for #{member.class.name.downcase} '#{member.id} has been updated in #{class_name} successfully" render_json_response subject, "Role for #{member.class.name.downcase} '#{member.id} has been updated in #{class_name} successfully"
else else
render_validation_error subject, "Role for member has not been updated in #{class_name}" render_validation_error subject, "Role for member has not been updated in #{class_name}"
@ -89,12 +89,12 @@ class Api::V1::BaseController < ApplicationController
def render_json_response(subject, message, status = 200) def render_json_response(subject, message, status = 200)
id = status != 200 ? nil : subject.id id = status != 200 ? nil : subject.id
render :json => { render json: {
subject.class.name.underscore.to_sym => { subject.class.name.underscore.to_sym => {
:id => id, id: id,
:message => message message: message
} }
}.to_json, :status => status }.to_json, status: status
end end
def render_validation_error(subject, message) def render_validation_error(subject, message)
@ -103,9 +103,9 @@ class Api::V1::BaseController < ApplicationController
def member_path(subject) def member_path(subject)
if subject.is_a?(User) if subject.is_a?(User)
api_v1_user_path(subject.id, :format => :json) api_v1_user_path(subject.id, format: :json)
else else
api_v1_group_path(subject.id, :format => :json) api_v1_group_path(subject.id, format: :json)
end end
end end
@ -113,7 +113,7 @@ class Api::V1::BaseController < ApplicationController
def member def member
if @member.blank? && %w(User Group).include?(params[:type]) if @member.blank? && %w(User Group).include?(params[:type])
@member = params[:type].constantize.where(:id => params[:member_id]).first @member = params[:type].constantize.where(id: params[:member_id]).first
end end
@member @member
end end

View File

@ -1,20 +1,20 @@
class Api::V1::BuildListsController < Api::V1::BaseController class Api::V1::BuildListsController < Api::V1::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :index] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:show, :index] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :project, :only => :index load_and_authorize_resource :project, only: :index
load_and_authorize_resource :build_list, :only => [:show, :create, :cancel, :publish, :reject_publish, :create_container, :publish_into_testing] load_and_authorize_resource :build_list, only: [:show, :create, :cancel, :publish, :reject_publish, :create_container, :publish_into_testing]
def index def index
filter = BuildList::Filter.new(@project, current_user, current_ability, params[:filter] || {}) filter = BuildList::Filter.new(@project, current_user, current_ability, params[:filter] || {})
@build_lists = filter.find.scoped(:include => [:save_to_platform, :project, :user, :arch]) @build_lists = filter.find.scoped(include: [:save_to_platform, :project, :user, :arch])
@build_lists = @build_lists.recent.paginate(paginate_params) @build_lists = @build_lists.recent.paginate(paginate_params)
end end
def create def create
bl_params = params[:build_list] || {} bl_params = params[:build_list] || {}
save_to_repository = Repository.where(:id => bl_params[:save_to_repository_id]).first save_to_repository = Repository.where(id: bl_params[:save_to_repository_id]).first
if save_to_repository if save_to_repository
bl_params[:save_to_platform_id] = save_to_repository.platform_id bl_params[:save_to_platform_id] = save_to_repository.platform_id

View File

@ -1,7 +1,7 @@
class Api::V1::GroupsController < Api::V1::BaseController class Api::V1::GroupsController < Api::V1::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource load_and_authorize_resource
def index def index

View File

@ -2,11 +2,11 @@ class Api::V1::IssuesController < Api::V1::BaseController
respond_to :json respond_to :json
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :group_index, :show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :group_index, :show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :group, :only => :group_index, :find_by => :id, :parent => false load_and_authorize_resource :group, only: :group_index, find_by: :id, parent: false
load_and_authorize_resource :project load_and_authorize_resource :project
load_and_authorize_resource :issue, :through => :project, :find_by => :serial_id, :only => [:show, :update, :create, :index] load_and_authorize_resource :issue, through: :project, find_by: :serial_id, only: [:show, :update, :create, :index]
def index def index
@issues = @project.issues @issues = @project.issues
@ -15,20 +15,20 @@ class Api::V1::IssuesController < Api::V1::BaseController
def all_index def all_index
project_ids = get_all_project_ids Project.accessible_by(current_ability, :membered).pluck(:id) project_ids = get_all_project_ids Project.accessible_by(current_ability, :membered).pluck(:id)
@issues = Issue.where(:project_id => project_ids) @issues = Issue.where(project_id: project_ids)
render_issues_list render_issues_list
end end
def user_index def user_index
project_ids = get_all_project_ids current_user.projects.pluck(:id) project_ids = get_all_project_ids current_user.projects.pluck(:id)
@issues = Issue.where(:project_id => project_ids) @issues = Issue.where(project_id: project_ids)
render_issues_list render_issues_list
end end
def group_index def group_index
project_ids = @group.projects.pluck(:id) project_ids = @group.projects.pluck(:id)
project_ids = Project.accessible_by(current_ability, :membered).where(:id => project_ids).pluck(:id) project_ids = Project.accessible_by(current_ability, :membered).where(id: project_ids).pluck(:id)
@issues = Issue.where(:project_id => project_ids) @issues = Issue.where(project_id: project_ids)
render_issues_list render_issues_list
end end
@ -70,7 +70,7 @@ class Api::V1::IssuesController < Api::V1::BaseController
if action_name == 'index' && params[:assignee].present? if action_name == 'index' && params[:assignee].present?
case params[:assignee] case params[:assignee]
when 'none' when 'none'
@issues = @issues.where(:assigned_id => nil) @issues = @issues.where(assigned_id: nil)
when '*' when '*'
@issues = @issues.where('issues.assigned_id IS NOT NULL') @issues = @issues.where('issues.assigned_id IS NOT NULL')
else else
@ -81,10 +81,10 @@ class Api::V1::IssuesController < Api::V1::BaseController
if %w[all_index user_index group_index].include?(action_name) if %w[all_index user_index group_index].include?(action_name)
case params[:filter] case params[:filter]
when 'created' when 'created'
@issues = @issues.where(:user_id => current_user) @issues = @issues.where(user_id: current_user)
when 'all' when 'all'
else else
@issues = @issues.where(:assignee_id => current_user) @issues = @issues.where(assignee_id: current_user)
end end
else else
@issues.where('users.uname = ?', params[:creator]) if params[:creator].present? @issues.where('users.uname = ?', params[:creator]) if params[:creator].present?
@ -109,7 +109,7 @@ class Api::V1::IssuesController < Api::V1::BaseController
if ['created', 'all'].include? params[:filter] if ['created', 'all'].include? params[:filter]
# add own issues # add own issues
project_ids = Project.accessible_by(current_ability, :show).joins(:issues). project_ids = Project.accessible_by(current_ability, :show).joins(:issues).
where(:issues => {:user_id => current_user.id}).pluck('projects.id') where(issues: {user_id: current_user.id}).pluck('projects.id')
end end
project_ids |= default_project_ids project_ids |= default_project_ids
end end

View File

@ -15,7 +15,7 @@ class Api::V1::JobsController < Api::V1::BaseController
if current_user.system? if current_user.system?
if task = (Resque.pop('rpm_worker_default') || Resque.pop('rpm_worker')) if task = (Resque.pop('rpm_worker_default') || Resque.pop('rpm_worker'))
@build_list = BuildList.where(:id => task['args'][0]['id']).first @build_list = BuildList.where(id: task['args'][0]['id']).first
end end
end end
@ -37,12 +37,12 @@ class Api::V1::JobsController < Api::V1::BaseController
if @build_list if @build_list
job = { job = {
:worker_queue => @build_list.worker_queue_with_priority, worker_queue: @build_list.worker_queue_with_priority,
:worker_class => @build_list.worker_queue_class, worker_class: @build_list.worker_queue_class,
:worker_args => [@build_list.abf_worker_args] :worker_args => [@build_list.abf_worker_args]
} }
end end
render :json => { :job => job }.to_json render json: { job: job }.to_json
end end
def statistics def statistics
@ -51,25 +51,25 @@ class Api::V1::JobsController < Api::V1::BaseController
:id => params[:uid], :id => params[:uid],
:user_id => current_user.id, :user_id => current_user.id,
:system => current_user.system?, :system => current_user.system?,
:worker_count => params[:worker_count], worker_count: params[:worker_count],
:busy_workers => params[:busy_workers] busy_workers: params[:busy_workers]
) rescue nil ) rescue nil
end end
render :nothing => true render nothing: true
end end
def status def status
render :text => Resque.redis.get(params[:key]) render text: Resque.redis.get(params[:key])
end end
def logs def logs
name = params[:name] name = params[:name]
if name =~ /abfworker::rpm-worker/ if name =~ /abfworker::rpm-worker/
if current_user.system? || current_user.id == BuildList.where(:id => name.gsub(/[^\d]/, '')).first.try(:builder_id) if current_user.system? || current_user.id == BuildList.where(id: name.gsub(/[^\d]/, '')).first.try(:builder_id)
BuildList.log_server.setex name, 15, params[:logs] BuildList.log_server.setex name, 15, params[:logs]
end end
end end
render :nothing => true render nothing: true
end end
def feedback def feedback
@ -77,11 +77,11 @@ class Api::V1::JobsController < Api::V1::BaseController
worker_class = params[:worker_class] worker_class = params[:worker_class]
if QUEUES.include?(worker_queue) && QUEUE_CLASSES.include?(worker_class) if QUEUES.include?(worker_queue) && QUEUE_CLASSES.include?(worker_class)
worker_args = (params[:worker_args] || []).first || {} worker_args = (params[:worker_args] || []).first || {}
worker_args = worker_args.merge(:feedback_from_user => current_user.id) worker_args = worker_args.merge(feedback_from_user: current_user.id)
Resque.push worker_queue, 'class' => worker_class, 'args' => [worker_args] Resque.push worker_queue, 'class' => worker_class, 'args' => [worker_args]
render :nothing => true render nothing: true
else else
render :nothing => true, :status => 403 render nothing: true, status: 403
end end
end end

View File

@ -1,15 +1,15 @@
class Api::V1::PlatformsController < Api::V1::BaseController class Api::V1::PlatformsController < Api::V1::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => :allowed skip_before_filter :authenticate_user!, only: :allowed
skip_before_filter :authenticate_user!, :only => [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:show, :platforms_for_build, :members] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :except => :allowed load_and_authorize_resource except: :allowed
def allowed def allowed
if Platform.allowed?(params[:path] || '', request) if Platform.allowed?(params[:path] || '', request)
render :nothing => true render nothing: true
else else
render :nothing => true, :status => 403 render nothing: true, status: 403
end end
end end
@ -28,14 +28,14 @@ class Api::V1::PlatformsController < Api::V1::BaseController
def create def create
platform_params = params[:platform] || {} platform_params = params[:platform] || {}
owner = User.where(:id => platform_params[:owner_id]).first owner = User.where(id: platform_params[:owner_id]).first
@platform.owner = owner || get_owner @platform.owner = owner || get_owner
create_subject @platform create_subject @platform
end end
def update def update
platform_params = params[:platform] || {} platform_params = params[:platform] || {}
owner = User.where(:id => platform_params[:owner_id]).first owner = User.where(id: platform_params[:owner_id]).first
platform_params[:owner] = owner if owner platform_params[:owner] = owner if owner
update_subject @platform update_subject @platform
end end

View File

@ -1,8 +1,8 @@
class Api::V1::ProductBuildListsController < Api::V1::BaseController class Api::V1::ProductBuildListsController < Api::V1::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :product, :only => :index load_and_authorize_resource :product, only: :index
load_and_authorize_resource load_and_authorize_resource
def index def index
@ -27,7 +27,7 @@ class Api::V1::ProductBuildListsController < Api::V1::BaseController
end end
def update def update
params[:product_build_list] = {:not_delete => (params[:product_build_list] || {})[:not_delete]} params[:product_build_list] = {not_delete: (params[:product_build_list] || {})[:not_delete]}
update_subject @product_build_list update_subject @product_build_list
end end

View File

@ -1,6 +1,6 @@
class Api::V1::ProductsController < Api::V1::BaseController class Api::V1::ProductsController < Api::V1::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource load_and_authorize_resource

View File

@ -1,8 +1,8 @@
class Api::V1::ProjectsController < Api::V1::BaseController class Api::V1::ProjectsController < Api::V1::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:get_id, :show, :refs_list] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:get_id, :show, :refs_list] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :project load_and_authorize_resource :project
def index def index
@ -38,7 +38,7 @@ class Api::V1::ProjectsController < Api::V1::BaseController
owner_type = p_params[:owner_type] owner_type = p_params[:owner_type]
if owner_type.present? && %w(User Group).include?(owner_type) if owner_type.present? && %w(User Group).include?(owner_type)
@project.owner = owner_type.constantize. @project.owner = owner_type.constantize.
where(:id => p_params[:owner_id]).first where(id: p_params[:owner_id]).first
else else
@project.owner = nil @project.owner = nil
end end

View File

@ -2,37 +2,37 @@ class Api::V1::PullRequestsController < Api::V1::BaseController
respond_to :json respond_to :json
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :index, :group_index, :commits, :files] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:show, :index, :group_index, :commits, :files] if APP_CONFIG['anonymous_access']
load_resource :group, :only => :group_index, :find_by => :id, :parent => false load_resource :group, only: :group_index, find_by: :id, parent: false
load_resource :project load_resource :project
load_resource :issue, :through => :project, :find_by => :serial_id, :parent => false, :only => [:show, :index, :commits, :files, :merge, :update] load_resource :issue, through: :project, find_by: :serial_id, parent: false, only: [:show, :index, :commits, :files, :merge, :update]
load_and_authorize_resource :instance_name => :pull, :through => :issue, :singleton => true, :only => [:show, :index, :commits, :files, :merge, :update] load_and_authorize_resource instance_name: :pull, through: :issue, singleton: true, only: [:show, :index, :commits, :files, :merge, :update]
def index def index
@pulls = @project.pull_requests @pulls = @project.pull_requests
@pulls_url = api_v1_project_pull_requests_path(@project, :format => :json) @pulls_url = api_v1_project_pull_requests_path(@project, format: :json)
render_pulls_list render_pulls_list
end end
def all_index def all_index
project_ids = get_all_project_ids Project.accessible_by(current_ability, :membered).pluck(:id) project_ids = get_all_project_ids Project.accessible_by(current_ability, :membered).pluck(:id)
@pulls = PullRequest.where('pull_requests.to_project_id IN (?)', project_ids) @pulls = PullRequest.where('pull_requests.to_project_id IN (?)', project_ids)
@pulls_url = api_v1_pull_requests_path :format => :json @pulls_url = api_v1_pull_requests_path format: :json
render_pulls_list render_pulls_list
end end
def user_index def user_index
project_ids = get_all_project_ids current_user.projects.pluck(:id) project_ids = get_all_project_ids current_user.projects.pluck(:id)
@pulls = PullRequest.where('pull_requests.to_project_id IN (?)', project_ids) @pulls = PullRequest.where('pull_requests.to_project_id IN (?)', project_ids)
@pulls_url = pull_requests_api_v1_user_path :format => :json @pulls_url = pull_requests_api_v1_user_path format: :json
render_pulls_list render_pulls_list
end end
def group_index def group_index
project_ids = @group.projects.pluck(:id) project_ids = @group.projects.pluck(:id)
project_ids = Project.accessible_by(current_ability, :membered).where(:id => project_ids).pluck(:id) project_ids = Project.accessible_by(current_ability, :membered).where(id: project_ids).pluck(:id)
@pulls = PullRequest.where(:to_project_id => project_ids) @pulls = PullRequest.where(to_project_id: project_ids)
@pulls_url = pull_requests_api_v1_group_path @pulls_url = pull_requests_api_v1_group_path
render_pulls_list render_pulls_list
end end
@ -47,7 +47,7 @@ class Api::V1::PullRequestsController < Api::V1::BaseController
authorize! :read, from_project authorize! :read, from_project
@pull = @project.pull_requests.new @pull = @project.pull_requests.new
@pull.build_issue :title => pull_params[:title], :body => pull_params[:body] @pull.build_issue title: pull_params[:title], body: pull_params[:body]
@pull.from_project = @project @pull.from_project = @project
@pull.to_ref, @pull.from_ref = pull_params[:to_ref], pull_params[:from_ref] @pull.to_ref, @pull.from_ref = pull_params[:to_ref], pull_params[:from_ref]
@pull.issue.assignee_id = pull_params[:assignee_id] if can?(:write, @project) @pull.issue.assignee_id = pull_params[:assignee_id] if can?(:write, @project)
@ -59,7 +59,7 @@ class Api::V1::PullRequestsController < Api::V1::BaseController
@pull.check(false) # don't make event transaction @pull.check(false) # don't make event transaction
if @pull.already? if @pull.already?
@pull.destroy @pull.destroy
error_message = I18n.t('projects.pull_requests.up_to_date', :to_ref => @pull.to_ref, :from_ref => @pull.from_ref) error_message = I18n.t('projects.pull_requests.up_to_date', to_ref: @pull.to_ref, from_ref: @pull.from_ref)
render_json_response(@pull, error_message, 422) render_json_response(@pull, error_message, 422)
else else
@pull.send(@pull.status == 'blocked' ? 'block' : @pull.status) @pull.send(@pull.status == 'blocked' ? 'block' : @pull.status)
@ -68,12 +68,12 @@ class Api::V1::PullRequestsController < Api::V1::BaseController
end end
def update def update
@pull = @project.pull_requests.includes(:issue).where(:issues => {:serial_id => params[:id]}).first @pull = @project.pull_requests.includes(:issue).where(issues: {serial_id: params[:id]}).first
authorize! :update, @pull authorize! :update, @pull
if pull_params.present? if pull_params.present?
attrs = pull_params.slice(:title, :body) attrs = pull_params.slice(:title, :body)
attrs.merge!(:assignee_id => pull_params[:assignee_id]) if can?(:write, @project) attrs.merge!(assignee_id: pull_params[:assignee_id]) if can?(:write, @project)
if (action = pull_params[:status]) && %w(close reopen).include?(pull_params[:status]) if (action = pull_params[:status]) && %w(close reopen).include?(pull_params[:status])
if @pull.send("can_#{action}?") if @pull.send("can_#{action}?")
@ -113,7 +113,7 @@ class Api::V1::PullRequestsController < Api::V1::BaseController
private private
def render_pulls_list def render_pulls_list
@pulls = @pulls.includes(:issue => [:user, :assignee]) @pulls = @pulls.includes(issue: [:user, :assignee])
if params[:status] == 'closed' if params[:status] == 'closed'
@pulls = @pulls.closed_or_merged @pulls = @pulls.closed_or_merged
else else
@ -157,7 +157,7 @@ class Api::V1::PullRequestsController < Api::V1::BaseController
if ['created', 'all'].include? params[:filter] if ['created', 'all'].include? params[:filter]
# add own pulls # add own pulls
project_ids = Project.accessible_by(current_ability, :show).joins(:issues). project_ids = Project.accessible_by(current_ability, :show).joins(:issues).
where(:issues => {:user_id => current_user.id}).pluck('projects.id') where(issues: {user_id: current_user.id}).pluck('projects.id')
end end
project_ids |= default_project_ids project_ids |= default_project_ids
end end

View File

@ -1,9 +1,9 @@
class Api::V1::RepositoriesController < Api::V1::BaseController class Api::V1::RepositoriesController < Api::V1::BaseController
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :projects] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :repository, :through => :platform, :shallow => true before_filter :authenticate_user!
skip_before_filter :authenticate_user!, only: [:show, :projects] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :repository, through: :platform, shallow: true
def show def show
end end
@ -73,7 +73,7 @@ class Api::V1::RepositoriesController < Api::V1::BaseController
end end
def add_project def add_project
if project = Project.where(:id => params[:project_id]).first if project = Project.where(id: params[:project_id]).first
if can?(:read, project) if can?(:read, project)
begin begin
@repository.projects << project @repository.projects << project
@ -91,7 +91,7 @@ class Api::V1::RepositoriesController < Api::V1::BaseController
def remove_project def remove_project
project_id = params[:project_id] project_id = params[:project_id]
ProjectToRepository.where(:project_id => project_id, :repository_id => @repository.id).destroy_all ProjectToRepository.where(project_id: project_id, repository_id: @repository.id).destroy_all
render_json_response @repository, "Project '#{project_id}' has been removed from repository successfully" render_json_response @repository, "Project '#{project_id}' has been removed from repository successfully"
end end

View File

@ -1,9 +1,9 @@
class Api::V1::UsersController < Api::V1::BaseController class Api::V1::UsersController < Api::V1::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :user, :only => :show load_and_authorize_resource :user, only: :show
before_filter :set_current_user, :except => :show before_filter :set_current_user, except: :show
def show def show
@user = User.opened.find params[:id] # dont show system users @user = User.opened.find params[:id] # dont show system users

View File

@ -11,24 +11,24 @@ class ApplicationController < ActionController::Base
before_filter :set_locale before_filter :set_locale
before_filter lambda { EventLog.current_controller = self }, before_filter lambda { EventLog.current_controller = self },
:only => [:create, :destroy, :open_id, :cancel, :publish, :change_visibility] # :update only: [:create, :destroy, :open_id, :cancel, :publish, :change_visibility] # :update
after_filter lambda { EventLog.current_controller = nil } after_filter lambda { EventLog.current_controller = nil }
helper_method :get_owner helper_method :get_owner
unless Rails.env.development? unless Rails.env.development?
rescue_from Exception, :with => :render_500 rescue_from Exception, with: :render_500
rescue_from ActiveRecord::RecordNotFound, rescue_from ActiveRecord::RecordNotFound,
# ActionController::RoutingError, # see: config/routes.rb:<last line> # ActionController::RoutingError, # see: config/routes.rb:<last line>
ActionController::UnknownController, ActionController::UnknownController,
AbstractController::ActionNotFound, :with => :render_404 AbstractController::ActionNotFound, with: :render_404
end end
rescue_from CanCan::AccessDenied do |exception| rescue_from CanCan::AccessDenied do |exception|
redirect_to forbidden_url, :alert => t("flash.exception_message") redirect_to forbidden_url, alert: t("flash.exception_message")
end end
rescue_from Grit::NoSuchPathError, :with => :not_found rescue_from Grit::NoSuchPathError, with: :not_found
def render_404 def render_404
@ -47,8 +47,8 @@ class ApplicationController < ActionController::Base
def render_error(status) def render_error(status)
respond_to do |format| respond_to do |format|
format.json { render :json => {:status => status, :message => t("flash.#{status}_message")}.to_json, :status => status } format.json { render json: {status: status, message: t("flash.#{status}_message")}.to_json, status: status }
format.html { redirect_to "/#{status}.html", :alert => t("flash.#{status}_message") } format.html { redirect_to "/#{status}.html", alert: t("flash.#{status}_message") }
end end
end end

View File

@ -1,6 +1,6 @@
class Groups::MembersController < Groups::BaseController class Groups::MembersController < Groups::BaseController
is_related_controller! is_related_controller!
belongs_to :group, :finder => 'find_by_insensitive_uname!', :optional => true belongs_to :group, finder: 'find_by_insensitive_uname!', optional: true
before_filter lambda { authorize! :manage_members, @group } before_filter lambda { authorize! :manage_members, @group }
@ -10,10 +10,10 @@ class Groups::MembersController < Groups::BaseController
def update def update
params['user'].keys.each do |user_id| params['user'].keys.each do |user_id|
role = params['user'][user_id] role = params['user'][user_id]
if relation = parent.actors.where(:actor_id => user_id, :actor_type => 'User') #find_by_actor_id_and_actor_type(user_id, 'User') if relation = parent.actors.where(actor_id: user_id, actor_type: 'User') #find_by_actor_id_and_actor_type(user_id, 'User')
relation.update_all(:role => role) if parent.owner.id.to_s != user_id relation.update_all(role: role) if parent.owner.id.to_s != user_id
else else
relation = parent.actors.build(:actor_id => user_id, :actor_type => 'User', :role => role) relation = parent.actors.build(actor_id: user_id, actor_type: 'User', role: role)
relation.save! relation.save!
end end
end if params['user'] end if params['user']
@ -30,7 +30,7 @@ class Groups::MembersController < Groups::BaseController
params['user_remove'].each do |user_id, remove| params['user_remove'].each do |user_id, remove|
all_user_ids << user_id if remove == ["1"] all_user_ids << user_id if remove == ["1"]
end if params['user_remove'] end if params['user_remove']
User.where(:id => all_user_ids).each do |user| User.where(id: all_user_ids).each do |user|
parent.remove_member(user) parent.remove_member(user)
end end
redirect_to group_members_path(parent) redirect_to group_members_path(parent)
@ -39,7 +39,7 @@ class Groups::MembersController < Groups::BaseController
def add def add
@user = User.find_by_uname(params[:user_uname]) @user = User.find_by_uname(params[:user_uname])
if !@user if !@user
flash[:error] = t("flash.collaborators.wrong_user", :uname => params[:user_uname]) flash[:error] = t("flash.collaborators.wrong_user", uname: params[:user_uname])
elsif parent.add_member(@user, params[:role]) elsif parent.add_member(@user, params[:role])
flash[:notice] = t("flash.members.successfully_added") flash[:notice] = t("flash.members.successfully_added")
else else

View File

@ -1,10 +1,10 @@
class Groups::ProfileController < Groups::BaseController class Groups::ProfileController < Groups::BaseController
include AvatarHelper include AvatarHelper
load_and_authorize_resource :class => Group, :instance_name => 'group' load_and_authorize_resource class: Group, instance_name: 'group'
skip_before_filter :authenticate_user!, :only => :show if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: :show if APP_CONFIG['anonymous_access']
def index def index
@groups = current_user.groups.paginate(:page => params[:group_page]) # accessible_by(current_ability) @groups = current_user.groups.paginate(page: params[:group_page]) # accessible_by(current_ability)
@groups = @groups.search(params[:query]) if params[:query].present? @groups = @groups.search(params[:query]) if params[:query].present?
end end
@ -18,7 +18,7 @@ class Groups::ProfileController < Groups::BaseController
else else
@projects = @projects.by_visibilities('hidden').accessible_by(current_ability, :read) @projects = @projects.by_visibilities('hidden').accessible_by(current_ability, :read)
end end
render :partial => 'shared/profile_projects', :layout => nil, :locals => {:projects => paginate_projects(page)} render partial: 'shared/profile_projects', layout: nil, locals: {projects: paginate_projects(page)}
else else
@projects = paginate_projects(page) @projects = paginate_projects(page)
end end
@ -38,7 +38,7 @@ class Groups::ProfileController < Groups::BaseController
else else
flash[:error] = t('flash.group.save_error') flash[:error] = t('flash.group.save_error')
flash[:warning] = @group.errors.full_messages.join('. ') flash[:warning] = @group.errors.full_messages.join('. ')
render :action => :new render action: :new
end end
end end
@ -49,7 +49,7 @@ class Groups::ProfileController < Groups::BaseController
redirect_to group_path(@group) redirect_to group_path(@group)
else else
flash[:error] = t('flash.group.save_error') flash[:error] = t('flash.group.save_error')
render :action => :edit render action: :edit
end end
end end
@ -67,6 +67,6 @@ class Groups::ProfileController < Groups::BaseController
protected protected
def paginate_projects(page) def paginate_projects(page)
@projects.paginate(:page => (page>0 ? page : nil), :per_page => 24) @projects.paginate(page: (page>0 ? page : nil), per_page: 24)
end end
end end

View File

@ -1,26 +1,26 @@
class HomeController < ApplicationController class HomeController < ApplicationController
before_filter :authenticate_user!, :only => [:activity, :issues, :pull_requests] before_filter :authenticate_user!, only: [:activity, :issues, :pull_requests]
def root def root
render 'pages/tour/abf-tour-project-description-1', :layout => 'tour' render 'pages/tour/abf-tour-project-description-1', layout: 'tour'
end end
def activity def activity
@filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all @filter = t('feed_menu').has_key?(params[:filter].try(:to_sym)) ? params[:filter].to_sym : :all
@activity_feeds = current_user.activity_feeds @activity_feeds = current_user.activity_feeds
@activity_feeds = @activity_feeds.where(:kind => "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all @activity_feeds = @activity_feeds.where(kind: "ActivityFeed::#{@filter.upcase}".constantize) unless @filter == :all
@activity_feeds = @activity_feeds.paginate :page => params[:page] @activity_feeds = @activity_feeds.paginate page: params[:page]
respond_to do |format| respond_to do |format|
format.html { request.xhr? ? render('_list', :layout => false) : render('activity') } format.html { request.xhr? ? render('_list', layout: false) : render('activity') }
format.atom format.atom
end end
end end
def issues def issues
@created_issues = current_user.issues @created_issues = current_user.issues
@assigned_issues = Issue.where(:assignee_id => current_user.id) @assigned_issues = Issue.where(assignee_id: current_user.id)
pr_ids = Project.accessible_by(current_ability, :membered).uniq.pluck(:id) pr_ids = Project.accessible_by(current_ability, :membered).uniq.pluck(:id)
@all_issues = Issue.where(:project_id => pr_ids) @all_issues = Issue.where(project_id: pr_ids)
@created_issues, @assigned_issues, @all_issues = @created_issues, @assigned_issues, @all_issues =
if action_name == 'issues' if action_name == 'issues'
[@created_issues.without_pull_requests, [@created_issues.without_pull_requests,
@ -51,8 +51,8 @@ class HomeController < ApplicationController
@direction = params[:direction] == 'asc' ? :asc : :desc @direction = params[:direction] == 'asc' ? :asc : :desc
@issues = @issues.order("issues.#{@sort}_at #{@direction}") @issues = @issues.order("issues.#{@sort}_at #{@direction}")
.includes(:assignee, :user, :pull_request).uniq .includes(:assignee, :user, :pull_request).uniq
.paginate :per_page => 20, :page => params[:page] .paginate per_page: 20, page: params[:page]
render 'issues', :layout => request.xhr? ? 'with_sidebar' : 'application' render 'issues', layout: request.xhr? ? 'with_sidebar' : 'application'
end end
def pull_requests def pull_requests

View File

@ -9,7 +9,7 @@ class PagesController < ApplicationController
when 'projects' when 'projects'
%w(control git tracker) %w(control git tracker)
end end
render "pages/tour/tour-inside", :layout => 'tour' render "pages/tour/tour-inside", layout: 'tour'
end end
def forbidden def forbidden

View File

@ -1,8 +1,8 @@
class Platforms::KeyPairsController < Platforms::BaseController class Platforms::KeyPairsController < Platforms::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
load_and_authorize_resource :platform, :only => [:index] load_and_authorize_resource :platform, only: [:index]
load_and_authorize_resource :only => [:create, :destroy] load_and_authorize_resource only: [:create, :destroy]
def create def create
@key_pair.user_id = current_user.id @key_pair.user_id = current_user.id

View File

@ -1,12 +1,12 @@
class Platforms::MaintainersController < ApplicationController class Platforms::MaintainersController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :platform load_and_authorize_resource :platform
def index def index
@maintainers = BuildList::Package.includes(:project) @maintainers = BuildList::Package.includes(:project)
.actual.by_platform(@platform) .actual.by_platform(@platform)
.like_name(params[:q]) .like_name(params[:q])
.paginate(:page => params[:page]) .paginate(page: params[:page])
end end
end end

View File

@ -1,11 +1,11 @@
class Platforms::MassBuildsController < Platforms::BaseController class Platforms::MassBuildsController < Platforms::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :get_list] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :get_list] if APP_CONFIG['anonymous_access']
load_resource :platform load_resource :platform
load_and_authorize_resource :through => :platform, :shallow => true load_and_authorize_resource :through => :platform, :shallow => true
def new def new
end end
@ -14,11 +14,11 @@ class Platforms::MassBuildsController < Platforms::BaseController
@mass_build.user, @mass_build.arches = current_user, params[:arches] @mass_build.user, @mass_build.arches = current_user, params[:arches]
if @mass_build.save if @mass_build.save
redirect_to(platform_mass_builds_path(@platform), :notice => t("flash.platform.build_all_success")) redirect_to(platform_mass_builds_path(@platform), notice: t("flash.platform.build_all_success"))
else else
flash[:warning] = @mass_build.errors.full_messages.join('. ') flash[:warning] = @mass_build.errors.full_messages.join('. ')
flash[:error] = t('flash.platform.build_all_error') flash[:error] = t('flash.platform.build_all_error')
render :action => :new render action: :new
end end
end end
@ -28,11 +28,11 @@ class Platforms::MassBuildsController < Platforms::BaseController
else else
@mass_build.publish_success_builds current_user @mass_build.publish_success_builds current_user
end end
redirect_to(platform_mass_builds_path(@mass_build.save_to_platform), :notice => t("flash.platform.publish_success")) redirect_to(platform_mass_builds_path(@mass_build.save_to_platform), notice: t("flash.platform.publish_success"))
end end
def index def index
@mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20) @mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(page: params[:page], per_page: 20)
end end
def cancel def cancel
@ -47,6 +47,6 @@ class Platforms::MassBuildsController < Platforms::BaseController
elsif ['projects_list', 'missed_projects_list'].include? params[:kind] elsif ['projects_list', 'missed_projects_list'].include? params[:kind]
@mass_build.send params[:kind] @mass_build.send params[:kind]
end end
render :text => text render text: text
end end
end end

View File

@ -2,11 +2,11 @@ class Platforms::PlatformsController < Platforms::BaseController
include FileStoreHelper include FileStoreHelper
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:advisories, :members, :show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:advisories, :members, :show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource load_and_authorize_resource
def index def index
@platforms = @platforms.accessible_by(current_ability, :related).order(:name).paginate(:page => params[:page], :per_page => 20) @platforms = @platforms.accessible_by(current_ability, :related).order(:name).paginate(page: params[:page], per_page: 20)
end end
def show def show
@ -34,7 +34,7 @@ class Platforms::PlatformsController < Platforms::BaseController
else else
flash[:error] = I18n.t("flash.platform.create_error") flash[:error] = I18n.t("flash.platform.create_error")
flash[:warning] = @platform.errors.full_messages.join('. ') flash[:warning] = @platform.errors.full_messages.join('. ')
render :action => :new render action: :new
end end
end end
@ -52,7 +52,7 @@ class Platforms::PlatformsController < Platforms::BaseController
else else
flash[:error] = I18n.t("flash.platform.save_error") flash[:error] = I18n.t("flash.platform.save_error")
flash[:warning] = @platform.errors.full_messages.join('. ') flash[:warning] = @platform.errors.full_messages.join('. ')
render :action => :edit render action: :edit
end end
end end
@ -72,7 +72,7 @@ class Platforms::PlatformsController < Platforms::BaseController
else else
flash[:error] = I18n.t("flash.platform.save_error") flash[:error] = I18n.t("flash.platform.save_error")
flash[:warning] = @platform.errors.full_messages.join('. ') flash[:warning] = @platform.errors.full_messages.join('. ')
render :action => :edit render action: :edit
end end
end end
@ -83,7 +83,7 @@ class Platforms::PlatformsController < Platforms::BaseController
end end
def make_clone def make_clone
@cloned = @platform.full_clone params[:platform].merge(:owner => current_user) @cloned = @platform.full_clone params[:platform].merge(owner: current_user)
if @cloned.persisted? if @cloned.persisted?
flash[:notice] = I18n.t("flash.platform.clone_success") flash[:notice] = I18n.t("flash.platform.clone_success")
redirect_to @cloned redirect_to @cloned
@ -106,29 +106,29 @@ class Platforms::PlatformsController < Platforms::BaseController
def remove_members def remove_members
user_ids = params[:user_remove] ? user_ids = params[:user_remove] ?
params[:user_remove].map{ |k, v| k if v.first == '1' }.compact : [] params[:user_remove].map{ |k, v| k if v.first == '1' }.compact : []
User.where(:id => user_ids).each{ |user| @platform.remove_member(user) } User.where(id: user_ids).each{ |user| @platform.remove_member(user) }
redirect_to members_platform_path(@platform) redirect_to members_platform_path(@platform)
end end
def remove_member def remove_member
User.where(:id => params[:member_id]).each{ |user| @platform.remove_member(user) } User.where(id: params[:member_id]).each{ |user| @platform.remove_member(user) }
redirect_to members_platform_path(@platform) redirect_to members_platform_path(@platform)
end end
def add_member def add_member
member = User.where(:id => params[:member_id]).first member = User.where(id: params[:member_id]).first
if !member if !member
flash[:error] = t("flash.collaborators.wrong_user", :uname => params[:member_id]) flash[:error] = t("flash.collaborators.wrong_user", uname: params[:member_id])
elsif @platform.add_member(member) elsif @platform.add_member(member)
flash[:notice] = t('flash.platform.members.successfully_added', :name => member.uname) flash[:notice] = t('flash.platform.members.successfully_added', name: member.uname)
else else
flash[:error] = t('flash.platform.members.error_in_adding', :name => member.uname) flash[:error] = t('flash.platform.members.error_in_adding', name: member.uname)
end end
redirect_to members_platform_url(@platform) redirect_to members_platform_url(@platform)
end end
def advisories def advisories
@advisories = @platform.advisories.paginate(:page => params[:page]) @advisories = @platform.advisories.paginate(page: params[:page])
end end
def clear def clear

View File

@ -10,10 +10,10 @@ class Platforms::PrivateUsersController < Platforms::BaseController
def create def create
old_pair = PrivateUser.find_by_platform_id_and_user_id(params[:platform_id], current_user.id) old_pair = PrivateUser.find_by_platform_id_and_user_id(params[:platform_id], current_user.id)
old_pair.destroy if old_pair old_pair.destroy if old_pair
@pair = PrivateUser.generate_pair(params[:platform_id], current_user.id) @pair = PrivateUser.generate_pair(params[:platform_id], current_user.id)
@urpmi_list = @platform.urpmi_list(request.host, @pair) @urpmi_list = @platform.urpmi_list(request.host, @pair)
redirect_to platform_private_users_path(params[:platform_id]), :notice => I18n.t('flash.private_users', :login => @pair[:login], :password => @pair[:pass]) redirect_to platform_private_users_path(params[:platform_id]), notice: I18n.t('flash.private_users', login: @pair[:login], password: @pair[:pass])
end end
#def destroy #def destroy
@ -21,11 +21,11 @@ class Platforms::PrivateUsersController < Platforms::BaseController
# user.destroy # user.destroy
# redirect_to platform_private_users_path(params[:platform_id]) # redirect_to platform_private_users_path(params[:platform_id])
#end #end
protected protected
def find_platform_and_private_users def find_platform_and_private_users
@private_users = PrivateUser.where(:platform_id => params[:platform_id]).paginate :page => params[:page] @private_users = PrivateUser.where(platform_id: params[:platform_id]).paginate page: params[:page]
@platform = Platform.find(params[:platform_id]) @platform = Platform.find(params[:platform_id])
end end
end end

View File

@ -8,9 +8,9 @@ class Platforms::PrivatesController < Platforms::BaseController
file_name = "#{APP_CONFIG['root_path']}/platforms/#{params[:platform_name]}/#{params[:file_path]}" file_name = "#{APP_CONFIG['root_path']}/platforms/#{params[:platform_name]}/#{params[:file_path]}"
if File.directory?(file_name) || !File.exists?(file_name) if File.directory?(file_name) || !File.exists?(file_name)
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 render file: "#{Rails.root}/public/404.html", layout: false, status: 404
else else
send_file file_name send_file file_name
end end
end end
@ -19,9 +19,9 @@ class Platforms::PrivatesController < Platforms::BaseController
def authenticate def authenticate
authenticate_or_request_with_http_basic do |username, password| authenticate_or_request_with_http_basic do |username, password|
PrivateUser.exists?( PrivateUser.exists?(
:login => username, login: username,
:password => Digest::SHA2.new.hexdigest(password), password: Digest::SHA2.new.hexdigest(password),
:platform_id => @platform.try(:id) platform_id: @platform.try(:id)
) )
end end
end end

View File

@ -2,12 +2,12 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
include FileStoreHelper include FileStoreHelper
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :show, :log] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :show, :log] if APP_CONFIG['anonymous_access']
before_filter :redirect_to_full_path_if_short_url, :only => :show before_filter :redirect_to_full_path_if_short_url, only: :show
load_and_authorize_resource :platform, :except => :index load_and_authorize_resource :platform, except: :index
load_and_authorize_resource :product, :through => :platform, :except => :index load_and_authorize_resource :product, through: :platform, except: :index
load_and_authorize_resource :product_build_list, :through => :product, :except => :index load_and_authorize_resource :product_build_list, through: :product, except: :index
load_and_authorize_resource :only => [:index, :show, :log, :cancel, :update] load_and_authorize_resource only: [:index, :show, :log, :cancel, :update]
def new def new
product = @product_build_list.product product = @product_build_list.product
@ -25,7 +25,7 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
end end
def update def update
if @product_build_list.update_attributes(:not_delete => (params[:product_build_list] || {})[:not_delete]) if @product_build_list.update_attributes(not_delete: (params[:product_build_list] || {})[:not_delete])
flash[:notice] = t('flash.product_build_list.updated') flash[:notice] = t('flash.product_build_list.updated')
else else
flash[:error] = t('flash.product_build_list.update_error') flash[:error] = t('flash.product_build_list.update_error')
@ -40,13 +40,13 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
else else
notice = t('layout.build_lists.cancel_fail') notice = t('layout.build_lists.cancel_fail')
end end
redirect_to :back, :notice => notice redirect_to :back, notice: notice
end end
def log def log
render :json => { render json: {
:log => @product_build_list.abf_worker_log, log: @product_build_list.abf_worker_log,
:building => @product_build_list.build_started? building: @product_build_list.build_started?
} }
end end
@ -62,7 +62,7 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
else else
flash[:error] = t('flash.product.build_error') flash[:error] = t('flash.product.build_error')
flash[:warning] = pbl.errors.full_messages.join('. ') flash[:warning] = pbl.errors.full_messages.join('. ')
render :action => :new render action: :new
end end
end end
@ -71,18 +71,18 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
flash[:notice] = t('flash.product_build_list.delete') flash[:notice] = t('flash.product_build_list.delete')
else else
flash[:error] = t('flash.product_build_list.delete_error') flash[:error] = t('flash.product_build_list.delete_error')
end end
redirect_to [@platform, @product] redirect_to [@platform, @product]
end end
def index def index
if params[:product_id].present? if params[:product_id].present?
@product_build_lists = @product_build_lists.where(:id => params[:product_id]) @product_build_lists = @product_build_lists.where(id: params[:product_id])
else else
@product_build_lists = @product_build_lists.scoped_to_product_name(params[:product_name]) if params[:product_name].present? @product_build_lists = @product_build_lists.scoped_to_product_name(params[:product_name]) if params[:product_name].present?
@product_build_lists = @product_build_lists.for_status(params[:status]) if params[:status].present? @product_build_lists = @product_build_lists.for_status(params[:status]) if params[:status].present?
end end
@product_build_lists = @product_build_lists.recent.paginate :page => params[:page] @product_build_lists = @product_build_lists.recent.paginate page: params[:page]
@build_server_status = AbfWorker::StatusInspector.products_status @build_server_status = AbfWorker::StatusInspector.products_status
end end

View File

@ -1,14 +1,14 @@
class Platforms::ProductsController < Platforms::BaseController class Platforms::ProductsController < Platforms::BaseController
include GitHelper include GitHelper
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :platform load_and_authorize_resource :platform
load_and_authorize_resource :product, :through => :platform, :except => :autocomplete_project load_and_authorize_resource :product, through: :platform, except: :autocomplete_project
before_filter :set_project, :only => [:create, :update] before_filter :set_project, only: [:create, :update]
def index def index
@products = @products.paginate(:page => params[:page]) @products = @products.paginate(page: params[:page])
end end
def new def new
@ -21,12 +21,12 @@ class Platforms::ProductsController < Platforms::BaseController
def create def create
if @product.save if @product.save
flash[:notice] = t('flash.product.saved') flash[:notice] = t('flash.product.saved')
redirect_to platform_product_path(@platform, @product) redirect_to platform_product_path(@platform, @product)
else else
flash[:error] = t('flash.product.save_error') flash[:error] = t('flash.product.save_error')
flash[:warning] = @product.errors.full_messages.join('. ') flash[:warning] = @product.errors.full_messages.join('. ')
render :action => :new render action: :new
end end
end end
@ -37,7 +37,7 @@ class Platforms::ProductsController < Platforms::BaseController
else else
flash[:error] = t('flash.product.save_error') flash[:error] = t('flash.product.save_error')
flash[:warning] = @product.errors.full_messages.join('. ') flash[:warning] = @product.errors.full_messages.join('. ')
render :action => "edit" render action: "edit"
end end
end end
@ -54,12 +54,12 @@ class Platforms::ProductsController < Platforms::BaseController
items = Project.accessible_by(current_ability, :membered) items = Project.accessible_by(current_ability, :membered)
.search(params[:term]).limit(20) .search(params[:term]).limit(20)
#items.select! {|e| e.repo.branches.count > 0} #items.select! {|e| e.repo.branches.count > 0}
render :json => items.map{ |p| render json: items.map{ |p|
{ {
:id => p.id, id: p.id,
:label => p.name_with_owner, label: p.name_with_owner,
:value => p.name_with_owner, value: p.name_with_owner,
:project_versions => versions_for_group_select(p) project_versions: versions_for_group_select(p)
} }
} }
end end

View File

@ -2,53 +2,53 @@ class Platforms::RepositoriesController < Platforms::BaseController
include FileStoreHelper include FileStoreHelper
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :show, :projects_list] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :show, :projects_list] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :platform load_and_authorize_resource :platform
load_and_authorize_resource :repository, :through => :platform, :shallow => true load_and_authorize_resource :repository, through: :platform, shallow: true
before_filter :set_members, :only => [:edit, :update] before_filter :set_members, only: [:edit, :update]
def index def index
@repositories = Repository.custom_sort(@repositories).paginate(:page => params[:page]) @repositories = Repository.custom_sort(@repositories).paginate(page: params[:page])
end end
def show def show
@projects = @repository.projects.recent.search(params[:query]) @projects = @repository.projects.recent.search(params[:query])
.paginate(:page => params[:project_page], :per_page => 30) .paginate(page: params[:project_page], per_page: 30)
end end
def edit def edit
end end
def update def update
if @repository.update_attributes params[:repository].slice(:description, :synchronizing_publications).merge(:publish_without_qa => (params[:repository][:publish_without_qa] || @repository.publish_without_qa)) if @repository.update_attributes params[:repository].slice(:description, :synchronizing_publications).merge(publish_without_qa: (params[:repository][:publish_without_qa] || @repository.publish_without_qa))
flash[:notice] = I18n.t("flash.repository.updated") flash[:notice] = I18n.t("flash.repository.updated")
redirect_to platform_repository_path(@platform, @repository) redirect_to platform_repository_path(@platform, @repository)
else else
flash[:error] = I18n.t("flash.repository.update_error") flash[:error] = I18n.t("flash.repository.update_error")
flash[:warning] = @repository.errors.full_messages.join('. ') flash[:warning] = @repository.errors.full_messages.join('. ')
render :action => :edit render action: :edit
end end
end end
def remove_members def remove_members
user_ids = params[:user_remove] ? user_ids = params[:user_remove] ?
params[:user_remove].map{ |k, v| k if v.first == '1' }.compact : [] params[:user_remove].map{ |k, v| k if v.first == '1' }.compact : []
User.where(:id => user_ids).each{ |user| @repository.remove_member(user) } User.where(id: user_ids).each{ |user| @repository.remove_member(user) }
redirect_to edit_platform_repository_path(@platform, @repository) redirect_to edit_platform_repository_path(@platform, @repository)
end end
def remove_member def remove_member
User.where(:id => params[:member_id]).each{ |user| @repository.remove_member(user) } User.where(id: params[:member_id]).each{ |user| @repository.remove_member(user) }
redirect_to edit_platform_repository_path(@platform, @repository) redirect_to edit_platform_repository_path(@platform, @repository)
end end
def add_member def add_member
if member = User.where(:id => params[:member_id]).first if member = User.where(id: params[:member_id]).first
if @repository.add_member(member) if @repository.add_member(member)
flash[:notice] = t('flash.repository.members.successfully_added', :name => member.uname) flash[:notice] = t('flash.repository.members.successfully_added', name: member.uname)
else else
flash[:error] = t('flash.repository.members.error_in_adding', :name => member.uname) flash[:error] = t('flash.repository.members.error_in_adding', name: member.uname)
end end
end end
redirect_to edit_platform_repository_path(@platform, @repository) redirect_to edit_platform_repository_path(@platform, @repository)
@ -74,14 +74,14 @@ class Platforms::RepositoriesController < Platforms::BaseController
else else
flash[:error] = t('flash.repository.save_error') flash[:error] = t('flash.repository.save_error')
flash[:warning] = @repository.errors.full_messages.join('. ') flash[:warning] = @repository.errors.full_messages.join('. ')
render :action => :new render action: :new
end end
end end
def add_project def add_project
if projects_list = params.try(:[], :repository).try(:[], :projects_list) if projects_list = params.try(:[], :repository).try(:[], :projects_list)
@repository.add_projects projects_list, current_user @repository.add_projects projects_list, current_user
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.projects_will_be_added') redirect_to platform_repository_path(@platform, @repository), notice: t('flash.repository.projects_will_be_added')
return return
end end
if params[:project_id].present? if params[:project_id].present?
@ -103,7 +103,7 @@ class Platforms::RepositoriesController < Platforms::BaseController
end end
def projects_list def projects_list
render(:text => @repository.projects.map(&:name).join("\n")) && return if params[:text] == 'true' render(text: @repository.projects.map(&:name).join("\n")) && return if params[:text] == 'true'
owner_subquery = " owner_subquery = "
INNER JOIN ( INNER JOIN (
@ -126,8 +126,8 @@ class Platforms::RepositoriesController < Platforms::BaseController
@projects = @projects.opened if @repository.platform.main? && !@repository.platform.hidden? @projects = @projects.opened if @repository.platform.main? && !@repository.platform.hidden?
end end
@projects = @projects.paginate( @projects = @projects.paginate(
:page => (params[:iDisplayStart].to_i/(params[:iDisplayLength].present? ? params[:iDisplayLength] : 25).to_i).to_i + 1, page: (params[:iDisplayStart].to_i/(params[:iDisplayLength].present? ? params[:iDisplayLength] : 25).to_i).to_i + 1,
:per_page => params[:iDisplayLength].present? ? params[:iDisplayLength] : 25 per_page: params[:iDisplayLength].present? ? params[:iDisplayLength] : 25
) )
@total_projects = @projects.count @total_projects = @projects.count
@ -135,7 +135,7 @@ class Platforms::RepositoriesController < Platforms::BaseController
respond_to do |format| respond_to do |format|
format.json { format.json {
render :partial => (params[:added] == "true") ? 'project' : 'proj_ajax', :layout => false render partial: (params[:added] == "true") ? 'project' : 'proj_ajax', layout: false
} }
end end
end end
@ -143,11 +143,11 @@ class Platforms::RepositoriesController < Platforms::BaseController
def remove_project def remove_project
if projects_list = params.try(:[], :repository).try(:[], :projects_list) if projects_list = params.try(:[], :repository).try(:[], :projects_list)
@repository.remove_projects projects_list @repository.remove_projects projects_list
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.projects_will_be_removed') redirect_to platform_repository_path(@platform, @repository), notice: t('flash.repository.projects_will_be_removed')
end end
if params[:project_id].present? if params[:project_id].present?
ProjectToRepository.where(:project_id => params[:project_id], :repository_id => @repository.id).destroy_all ProjectToRepository.where(project_id: params[:project_id], repository_id: @repository.id).destroy_all
redirect_to platform_repository_path(@platform, @repository), :notice => t('flash.repository.project_removed') redirect_to platform_repository_path(@platform, @repository), notice: t('flash.repository.project_removed')
end end
end end

View File

@ -7,19 +7,19 @@ class Platforms::TokensController < Platforms::BaseController
def index def index
authorize! :local_admin_manage, @platform authorize! :local_admin_manage, @platform
@tokens = @platform.tokens.includes(:creator, :updater) @tokens = @platform.tokens.includes(:creator, :updater)
.paginate(:per_page => 20, :page => params[:page]) .paginate(per_page: 20, page: params[:page])
end end
def show def show
end end
def withdraw def withdraw
if @token.block if @token.block
@token.updater = current_user @token.updater = current_user
@token.save @token.save
redirect_to :back, :notice => t('flash.tokens.withdraw_success') redirect_to :back, notice: t('flash.tokens.withdraw_success')
else else
redirect_to :back, :notice => t('flash.tokens.withdraw_fail') redirect_to :back, notice: t('flash.tokens.withdraw_fail')
end end
end end

View File

@ -6,7 +6,7 @@ class Projects::BaseController < ApplicationController
def find_collaborators def find_collaborators
search = "%#{params[:search_user]}%" search = "%#{params[:search_user]}%"
users = User.joins(:groups => :projects).where(:projects => {:id => @project.id}).where("users.uname ILIKE ?", search) users = User.joins(groups: :projects).where(projects: {id: @project.id}).where("users.uname ILIKE ?", search)
users2 = @project.collaborators.where("users.uname ILIKE ?", search) users2 = @project.collaborators.where("users.uname ILIKE ?", search)
@users = (users + users2).uniq.sort {|x,y| x.uname <=> y.uname}.first(10) @users = (users + users2).uniq.sort {|x,y| x.uname <=> y.uname}.first(10)
end end

View File

@ -4,15 +4,15 @@ class Projects::BuildListsController < Projects::BaseController
NESTED_ACTIONS = [:index, :new, :create] NESTED_ACTIONS = [:index, :new, :create]
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :index, :log] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:show, :index, :log] if APP_CONFIG['anonymous_access']
before_filter :find_build_list, :only => [:show, :publish, :cancel, :update, :log, :create_container] before_filter :find_build_list, only: [:show, :publish, :cancel, :update, :log, :create_container]
load_and_authorize_resource :project, :only => NESTED_ACTIONS load_and_authorize_resource :project, only: NESTED_ACTIONS
load_and_authorize_resource :build_list, :through => :project, :only => NESTED_ACTIONS, :shallow => true load_and_authorize_resource :build_list, through: :project, only: NESTED_ACTIONS, shallow: true
load_and_authorize_resource :except => NESTED_ACTIONS load_and_authorize_resource except: NESTED_ACTIONS
before_filter :create_from_build_list, :only => :new before_filter :create_from_build_list, only: :new
def index def index
params[:filter].each{|k,v| params[:filter].delete(k) if v.blank? } if params[:filter] params[:filter].each{|k,v| params[:filter].delete(k) if v.blank? } if params[:filter]
@ -24,16 +24,16 @@ class Projects::BuildListsController < Projects::BaseController
@bls = @filter.find.recent @bls = @filter.find.recent
.paginate( .paginate(
:page => (params[:page].to_i == 0 ? nil : params[:page]), :page => (params[:page].to_i == 0 ? nil : params[:page]),
:per_page => BuildList::Filter::PER_PAGE.include?(params[:per_page].to_i) ? params[:per_page].to_i : 25 per_page: BuildList::Filter::PER_PAGE.include?(params[:per_page].to_i) ? params[:per_page].to_i : 25
) )
@build_lists = BuildList.where(:id => @bls.pluck(:id)).recent @build_lists = BuildList.where(id: @bls.pluck(:id)).recent
.includes( .includes(
:save_to_platform, :save_to_platform,
:save_to_repository, :save_to_repository,
:build_for_platform, :build_for_platform,
:user, :user,
:source_packages, :source_packages,
:project => :project_statistics project: :project_statistics
) )
@build_server_status = AbfWorker::StatusInspector.projects_status @build_server_status = AbfWorker::StatusInspector.projects_status
@ -43,7 +43,7 @@ class Projects::BuildListsController < Projects::BaseController
def new def new
if params[:show] == 'inline' && params[:build_list_id].present? if params[:show] == 'inline' && params[:build_list_id].present?
render '_new_form', :layout => false, :locals => {:project => @project, :build_list => @build_list} render '_new_form', layout: false, locals: {project: @project, build_list: @build_list}
else else
render :new render :new
end end
@ -59,17 +59,17 @@ class Projects::BuildListsController < Projects::BaseController
params[:build_list][:auto_publish] = false unless @repository.publish_without_qa? params[:build_list][:auto_publish] = false unless @repository.publish_without_qa?
build_for_platforms = Repository.select(:platform_id). build_for_platforms = Repository.select(:platform_id).
where(:id => params[:build_list][:include_repos]).group(:platform_id).map(&:platform_id) where(id: params[:build_list][:include_repos]).group(:platform_id).map(&:platform_id)
build_lists = [] build_lists = []
Arch.where(:id => params[:arches]).each do |arch| Arch.where(id: params[:arches]).each do |arch|
Platform.main.where(:id => build_for_platforms).each do |build_for_platform| Platform.main.where(id: build_for_platforms).each do |build_for_platform|
@build_list = @project.build_lists.build(params[:build_list]) @build_list = @project.build_lists.build(params[:build_list])
@build_list.build_for_platform = build_for_platform; @build_list.arch = arch; @build_list.user = current_user @build_list.build_for_platform = build_for_platform; @build_list.arch = arch; @build_list.user = current_user
@build_list.include_repos = @build_list.include_repos.select {|ir| @build_list.build_for_platform.repository_ids.include? ir.to_i} @build_list.include_repos = @build_list.include_repos.select {|ir| @build_list.build_for_platform.repository_ids.include? ir.to_i}
@build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority @build_list.priority = current_user.build_priority # User builds more priority than mass rebuild with zero priority
flash_options = {:project_version => @build_list.project_version, :arch => arch.name, :build_for_platform => build_for_platform.name} flash_options = {project_version: @build_list.project_version, arch: arch.name, build_for_platform: build_for_platform.name}
if authorize!(:create, @build_list) && @build_list.save if authorize!(:create, @build_list) && @build_list.save
build_lists << @build_list build_lists << @build_list
notices << t("flash.build_list.saved", flash_options) notices << t("flash.build_list.saved", flash_options)
@ -82,9 +82,9 @@ class Projects::BuildListsController < Projects::BaseController
if errors.present? if errors.present?
@build_list ||= BuildList.new @build_list ||= BuildList.new
flash[:error] = errors.join('<br>').html_safe flash[:error] = errors.join('<br>').html_safe
render :action => :new render action: :new
else else
BuildList.where(:id => build_lists.map(&:id)).update_all(:group_id => build_lists[0].id) if build_lists.size > 1 BuildList.where(id: build_lists.map(&:id)).update_all(group_id: build_lists[0].id) if build_lists.size > 1
flash[:notice] = notices.join('<br>').html_safe flash[:notice] = notices.join('<br>').html_safe
redirect_to project_build_lists_path(@project) redirect_to project_build_lists_path(@project)
end end
@ -100,54 +100,54 @@ class Projects::BuildListsController < Projects::BaseController
if params[:attach_advisory].present? and params[:attach_advisory] != 'no' and !@build_list.advisory if params[:attach_advisory].present? and params[:attach_advisory] != 'no' and !@build_list.advisory
unless @build_list.update_type.in? BuildList::RELEASE_UPDATE_TYPES unless @build_list.update_type.in? BuildList::RELEASE_UPDATE_TYPES
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return redirect_to :back, notice: t('layout.build_lists.publish_fail') and return
end end
if params[:attach_advisory] == 'new' if params[:attach_advisory] == 'new'
# create new advisory # create new advisory
unless @build_list.associate_and_create_advisory(params[:build_list][:advisory]) unless @build_list.associate_and_create_advisory(params[:build_list][:advisory])
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return redirect_to :back, notice: t('layout.build_lists.publish_fail') and return
end end
else else
# attach existing advisory # attach existing advisory
a = Advisory.where(:advisory_id => params[:attach_advisory]).first a = Advisory.where(advisory_id: params[:attach_advisory]).first
unless (a && a.attach_build_list(@build_list)) unless (a && a.attach_build_list(@build_list))
redirect_to :back, :notice => t('layout.build_lists.publish_fail') and return redirect_to :back, notice: t('layout.build_lists.publish_fail') and return
end end
end end
end end
@build_list.publisher = current_user @build_list.publisher = current_user
message = @build_list.publish ? 'success' : 'fail' message = @build_list.publish ? 'success' : 'fail'
redirect_to :back, :notice => t("layout.build_lists.publish_#{message}") redirect_to :back, notice: t("layout.build_lists.publish_#{message}")
end end
def publish_into_testing def publish_into_testing
@build_list.publisher = current_user @build_list.publisher = current_user
message = @build_list.publish_into_testing ? 'success' : 'fail' message = @build_list.publish_into_testing ? 'success' : 'fail'
redirect_to :back, :notice => t("layout.build_lists.publish_#{message}") redirect_to :back, notice: t("layout.build_lists.publish_#{message}")
end end
def reject_publish def reject_publish
@build_list.publisher = current_user @build_list.publisher = current_user
message = @build_list.reject_publish ? 'success' : 'fail' message = @build_list.reject_publish ? 'success' : 'fail'
redirect_to :back, :notice => t("layout.build_lists.reject_publish_#{message}") redirect_to :back, notice: t("layout.build_lists.reject_publish_#{message}")
end end
def create_container def create_container
message = @build_list.publish_container ? 'success' : 'fail' message = @build_list.publish_container ? 'success' : 'fail'
redirect_to :back, :notice => t("layout.build_lists.create_container_#{message}") redirect_to :back, notice: t("layout.build_lists.create_container_#{message}")
end end
def cancel def cancel
message = @build_list.cancel ? 'will_be_canceled' : 'cancel_fail' message = @build_list.cancel ? 'will_be_canceled' : 'cancel_fail'
redirect_to :back, :notice => t("layout.build_lists.#{message}") redirect_to :back, notice: t("layout.build_lists.#{message}")
end end
def log def log
render :json => { render json: {
:log => @build_list.log(params[:load_lines]), log: @build_list.log(params[:load_lines]),
:building => @build_list.build_started? building: @build_list.build_started?
} }
end end
@ -157,13 +157,13 @@ class Projects::BuildListsController < Projects::BaseController
sort_dir = params[:sSortDir_0] == 'asc' ? 'asc' : 'desc' sort_dir = params[:sSortDir_0] == 'asc' ? 'asc' : 'desc'
order = "build_lists.updated_at #{sort_dir}" order = "build_lists.updated_at #{sort_dir}"
@build_lists = @build_lists.paginate(:page => (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, :per_page => params[:iDisplayLength]) @build_lists = @build_lists.paginate(page: (params[:iDisplayStart].to_i/params[:iDisplayLength].to_i).to_i + 1, per_page: params[:iDisplayLength])
@total_build_lists = @build_lists.count @total_build_lists = @build_lists.count
@build_lists = @build_lists.where(:user_id => current_user) if params[:owner_filter] == 'true' @build_lists = @build_lists.where(user_id: current_user) if params[:owner_filter] == 'true'
@build_lists = @build_lists.where(:status => [BuildList::BUILD_ERROR, BuildList::FAILED_PUBLISH, BuildList::REJECTED_PUBLISH]) if params[:status_filter] == 'true' @build_lists = @build_lists.where(status: [BuildList::BUILD_ERROR, BuildList::FAILED_PUBLISH, BuildList::REJECTED_PUBLISH]) if params[:status_filter] == 'true'
@build_lists = @build_lists.order(order) @build_lists = @build_lists.order(order)
render :partial => 'build_lists_ajax', :layout => false render partial: 'build_lists_ajax', layout: false
end end

View File

@ -20,7 +20,7 @@ class Projects::CollaboratorsController < Projects::BaseController
users = users.search(params[:term]) users = users.search(params[:term])
groups = groups.search(params[:term]) groups = groups.search(params[:term])
end end
@collaborators = (users | groups).map{|act| Collaborator.new(:actor => act, :project => @project)} @collaborators = (users | groups).map{|act| Collaborator.new(actor: act, project: @project)}
respond_with @collaborators do |format| respond_with @collaborators do |format|
format.json { render 'index' } format.json { render 'index' }
end end
@ -31,7 +31,7 @@ class Projects::CollaboratorsController < Projects::BaseController
@collaborator.project = @project @collaborator.project = @project
if @collaborator.save if @collaborator.save
respond_with @collaborator do |format| respond_with @collaborator do |format|
format.json { render :partial => 'collaborator', :locals => {:collaborator => @collaborator} } format.json { render partial: 'collaborator', locals: {collaborator: @collaborator} }
end end
else else
raise raise

View File

@ -3,7 +3,7 @@ class Projects::CommentsController < Projects::BaseController
load_and_authorize_resource :project load_and_authorize_resource :project
before_filter :find_commentable before_filter :find_commentable
before_filter :find_or_build_comment before_filter :find_or_build_comment
load_and_authorize_resource :new => :new_line load_and_authorize_resource new: :new_line
include CommentsHelper include CommentsHelper
@ -30,7 +30,7 @@ class Projects::CommentsController < Projects::BaseController
else else
[400, view_context.local_alert(@comment.errors.full_messages.join('. '))] [400, view_context.local_alert(@comment.errors.full_messages.join('. '))]
end end
render :inline => message, :status => status render inline: message, status: status
end end
def destroy def destroy
@ -41,7 +41,7 @@ class Projects::CommentsController < Projects::BaseController
def new_line def new_line
@path = view_context.project_commentable_comments_path(@project, @commentable) @path = view_context.project_commentable_comments_path(@project, @commentable)
render :layout => false render layout: false
end end
protected protected
@ -52,7 +52,7 @@ class Projects::CommentsController < Projects::BaseController
end end
def find_or_build_comment def find_or_build_comment
@comment = params[:id].present? && Comment.where(:automatic => false).find(params[:id]) || @comment = params[:id].present? && Comment.where(automatic: false).find(params[:id]) ||
current_user.comments.build(params[:comment]) {|c| c.commentable = @commentable; c.project = @project} current_user.comments.build(params[:comment]) {|c| c.commentable = @commentable; c.project = @project}
end end
end end

View File

@ -25,6 +25,6 @@ class Projects::CommitSubscribesController < Projects::BaseController
def find_commit def find_commit
@commit = @project.repo.commit(params[:commit_id]) @commit = @project.repo.commit(params[:commit_id])
@options = {:project_id => @project.id, :subscribeable_id => @commit.id.hex, :subscribeable_type => @commit.class.name, :user_id => current_user.id} @options = {project_id: @project.id, subscribeable_id: @commit.id.hex, subscribeable_type: @commit.class.name, user_id: current_user.id}
end end
end end

View File

@ -1,6 +1,6 @@
class Projects::Git::BaseController < Projects::BaseController class Projects::Git::BaseController < Projects::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :index, :blame, :raw, :archive, :diff, :tags, :branches] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:show, :index, :blame, :raw, :archive, :diff, :tags, :branches] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :project load_and_authorize_resource :project
before_filter :set_treeish_and_path before_filter :set_treeish_and_path

View File

@ -1,6 +1,6 @@
class Projects::Git::BlobsController < Projects::Git::BaseController class Projects::Git::BlobsController < Projects::Git::BaseController
before_filter :set_blob before_filter :set_blob
before_filter lambda {authorize! :write, @project}, :only => [:edit, :update] before_filter lambda {authorize! :write, @project}, only: [:edit, :update]
def show def show
end end
@ -10,12 +10,12 @@ class Projects::Git::BlobsController < Projects::Git::BaseController
def update def update
if @project.update_file(params[:path], params[:content].gsub("\r", ''), if @project.update_file(params[:path], params[:content].gsub("\r", ''),
:message => params[:message].gsub("\r", ''), :actor => current_user, :head => @treeish) message: params[:message].gsub("\r", ''), actor: current_user, head: @treeish)
flash[:notice] = t("flash.blob.successfully_updated", :name => params[:path]) flash[:notice] = t("flash.blob.successfully_updated", name: params[:path])
else else
flash[:notice] = t("flash.blob.updating_error", :name => params[:path]) flash[:notice] = t("flash.blob.updating_error", name: params[:path])
end end
redirect_to :action => :show redirect_to action: :show
end end
def blame def blame
@ -25,14 +25,14 @@ class Projects::Git::BlobsController < Projects::Git::BaseController
def raw def raw
repo = Grit::GitRuby::Repository.new(@project.repo.path) repo = Grit::GitRuby::Repository.new(@project.repo.path)
raw = repo.get_raw_object_by_sha1(@blob.id) raw = repo.get_raw_object_by_sha1(@blob.id)
send_data raw.content, :type => @blob.content_type, :disposition => @blob.disposition send_data raw.content, type: @blob.content_type, disposition: @blob.disposition
end end
protected protected
def set_blob def set_blob
@blob = @tree / @path or raise Grit::NoSuchPathError @blob = @tree / @path or raise Grit::NoSuchPathError
redirect_to tree_path(@project, :treeish => @treeish, :path => @path) if @blob.is_a? Grit::Tree redirect_to tree_path(@project, treeish: @treeish, path: @path) if @blob.is_a? Grit::Tree
@commit = @project.repo.log(@treeish, @path, :max_count => 1).first @commit = @project.repo.log(@treeish, @path, max_count: 1).first
end end
end end

View File

@ -3,7 +3,7 @@ class Projects::Git::CommitsController < Projects::Git::BaseController
if @path.present? if @path.present?
@commits = @project.repo.log(@treeish, @path) @commits = @project.repo.log(@treeish, @path)
else else
@commits, @page, @last_page = @project.paginate_commits(@treeish, :page => params[:page]) @commits, @page, @last_page = @project.paginate_commits(@treeish, page: params[:page])
end end
end end
@ -13,8 +13,8 @@ class Projects::Git::CommitsController < Projects::Git::BaseController
respond_to do |format| respond_to do |format|
format.html format.html
format.diff { render :text => (@commit.diffs.map(&:diff).join("\n") rescue ''), :content_type => "text/plain" } format.diff { render text: (@commit.diffs.map(&:diff).join("\n") rescue ''), content_type: "text/plain" }
format.patch { render :text => (@commit.to_patch rescue ''), :content_type => "text/plain" } format.patch { render text: (@commit.to_patch rescue ''), content_type: "text/plain" }
end end
end end

View File

@ -1,16 +1,16 @@
class Projects::Git::TreesController < Projects::Git::BaseController class Projects::Git::TreesController < Projects::Git::BaseController
before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, :only => :show before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, only: :show
skip_before_filter :set_branch_and_tree, :set_treeish_and_path, :only => :archive skip_before_filter :set_branch_and_tree, :set_treeish_and_path, only: :archive
before_filter lambda { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, :only => [:branch, :destroy] before_filter lambda { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, only: [:branch, :destroy]
skip_authorize_resource :project, :only => [:destroy, :restore_branch, :create] skip_authorize_resource :project, only: [:destroy, :restore_branch, :create]
before_filter lambda { authorize!(:write, @project) }, :only => [:destroy, :restore_branch, :create] before_filter lambda { authorize!(:write, @project) }, only: [:destroy, :restore_branch, :create]
def show def show
unless request.xhr? unless request.xhr?
render('empty') and return if @project.is_empty? render('empty') and return if @project.is_empty?
@tree = @tree / @path if @path.present? @tree = @tree / @path if @path.present?
@commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, :max_count => 1).first @commit = @branch.present? ? @branch.commit() : @project.repo.log(@treeish, @path, max_count: 1).first
raise Grit::NoSuchPathError unless @commit raise Grit::NoSuchPathError unless @commit
end end
end end
@ -28,7 +28,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController
redirect_to "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}" redirect_to "#{APP_CONFIG['file_store_url']}/api/v1/file_stores/#{sha1}"
else else
archive = @project.archive_by_treeish_and_format @treeish, format archive = @project.archive_by_treeish_and_format @treeish, format
send_file archive[:path], :disposition => 'attachment', :type => "application/#{format == 'zip' ? 'zip' : 'x-tar-gz'}", :filename => archive[:fullname] send_file archive[:path], disposition: 'attachment', type: "application/#{format == 'zip' ? 'zip' : 'x-tar-gz'}", filename: archive[:fullname]
end end
end end
@ -38,7 +38,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController
render :refs_list render :refs_list
else else
respond_to do |format| respond_to do |format|
format.json { render :nothing => true, :status => 422 } format.json { render nothing: true, status: 422 }
format.html format.html
end end
end end
@ -46,17 +46,17 @@ class Projects::Git::TreesController < Projects::Git::BaseController
def restore_branch def restore_branch
status = @project.create_branch(@treeish, params[:sha], current_user) ? 200 : 422 status = @project.create_branch(@treeish, params[:sha], current_user) ? 200 : 422
render :nothing => true, :status => status render nothing: true, status: status
end end
def create def create
status = @project.create_branch(params[:new_ref], params[:from_ref], current_user) ? 200 : 422 status = @project.create_branch(params[:new_ref], params[:from_ref], current_user) ? 200 : 422
render :nothing => true, :status => status render nothing: true, status: status
end end
def destroy def destroy
status = @branch && @project.delete_branch(@branch, current_user) ? 200 : 422 status = @branch && @project.delete_branch(@branch, current_user) ? 200 : 422
render :nothing => true, :status => status render nothing: true, status: status
end end
def branches def branches
@ -65,7 +65,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController
render :refs_list render :refs_list
else else
respond_to do |format| respond_to do |format|
format.json { render :nothing => true, :status => 422 } format.json { render nothing: true, status: 422 }
format.html format.html
end end
end end

View File

@ -1,7 +1,7 @@
class Projects::HooksController < Projects::BaseController class Projects::HooksController < Projects::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
load_and_authorize_resource :project load_and_authorize_resource :project
load_and_authorize_resource :hook, :through => :project load_and_authorize_resource :hook, through: :project
def index def index
@ -19,7 +19,7 @@ class Projects::HooksController < Projects::BaseController
def create def create
if @hook.save if @hook.save
redirect_to project_hooks_path(@project, :name => @hook.name), :notice => t('flash.hook.created') redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.created')
else else
flash[:error] = t('flash.hook.save_error') flash[:error] = t('flash.hook.save_error')
flash[:warning] = @hook.errors.full_messages.join('. ') flash[:warning] = @hook.errors.full_messages.join('. ')
@ -29,7 +29,7 @@ class Projects::HooksController < Projects::BaseController
def update def update
if @hook.update_attributes(params[:hook]) if @hook.update_attributes(params[:hook])
redirect_to project_hooks_path(@project, :name => @hook.name), :notice => t('flash.hook.updated') redirect_to project_hooks_path(@project, name: @hook.name), notice: t('flash.hook.updated')
else else
flash[:error] = t('flash.hook.save_error') flash[:error] = t('flash.hook.save_error')
flash[:warning] = @hook.errors.full_messages.join('. ') flash[:warning] = @hook.errors.full_messages.join('. ')
@ -39,7 +39,7 @@ class Projects::HooksController < Projects::BaseController
def destroy def destroy
@hook.destroy @hook.destroy
redirect_to project_hooks_path(@project, :name => @hook.name) redirect_to project_hooks_path(@project, name: @hook.name)
end end
end end

View File

@ -1,19 +1,19 @@
class Projects::IssuesController < Projects::BaseController class Projects::IssuesController < Projects::BaseController
NON_RESTFUL_ACTION = [:create_label, :update_label, :destroy_label] NON_RESTFUL_ACTION = [:create_label, :update_label, :destroy_label]
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
load_resource :project load_resource :project
load_and_authorize_resource :issue, :through => :project, :find_by => :serial_id, :only => [:show, :edit, :update, :destroy, :new, :create, :index] load_and_authorize_resource :issue, through: :project, find_by: :serial_id, only: [:show, :edit, :update, :destroy, :new, :create, :index]
before_filter :load_and_authorize_label, :only => NON_RESTFUL_ACTION before_filter :load_and_authorize_label, only: NON_RESTFUL_ACTION
before_filter :find_collaborators, :only => [:new, :create, :show, :search_collaborators] before_filter :find_collaborators, only: [:new, :create, :show, :search_collaborators]
layout false, :only => [:update, :search_collaborators] layout false, only: [:update, :search_collaborators]
def index(status = 200) def index(status = 200)
@labels = params[:labels] || [] @labels = params[:labels] || []
@issues = @project.issues.without_pull_requests @issues = @project.issues.without_pull_requests
@issues = @issues.where(:assignee_id => current_user.id) if @is_assigned_to_me = params[:filter] == 'assigned' @issues = @issues.where(assignee_id: current_user.id) if @is_assigned_to_me = params[:filter] == 'assigned'
@issues = @issues.joins(:labels).where(:labels => {:name => @labels}) unless @labels == [] @issues = @issues.joins(:labels).where(labels: {name: @labels}) unless @labels == []
# Using mb_chars for correct transform to lowercase ('Русский Текст'.downcase => "Русский Текст") # Using mb_chars for correct transform to lowercase ('Русский Текст'.downcase => "Русский Текст")
@issues = @issues.search(params[:search_issue]) if params[:search_issue] !~ /#{t('layout.issues.search')}/ @issues = @issues.search(params[:search_issue]) if params[:search_issue] !~ /#{t('layout.issues.search')}/
@ -25,11 +25,11 @@ class Projects::IssuesController < Projects::BaseController
@direction = params[:direction] == 'asc' ? :asc : :desc @direction = params[:direction] == 'asc' ? :asc : :desc
@issues = @issues.order("issues.#{@sort}_at #{@direction}") @issues = @issues.order("issues.#{@sort}_at #{@direction}")
@issues = @issues.includes(:assignee, :user, :pull_request).uniq @issues = @issues.includes(:assignee, :user, :pull_request).uniq
.paginate :per_page => 20, :page => params[:page] .paginate per_page: 20, page: params[:page]
if status == 200 if status == 200
render 'index', :layout => request.xhr? ? 'with_sidebar' : 'application' render 'index', layout: request.xhr? ? 'with_sidebar' : 'application'
else else
render :status => status, :nothing => true render status: status, nothing: true
end end
end end
@ -49,7 +49,7 @@ class Projects::IssuesController < Projects::BaseController
redirect_to project_issues_path(@project) redirect_to project_issues_path(@project)
else else
flash[:error] = I18n.t("flash.issue.save_error") flash[:error] = I18n.t("flash.issue.save_error")
render :action => :new render action: :new
end end
end end
@ -68,16 +68,16 @@ class Projects::IssuesController < Projects::BaseController
if params[:issue] && status = params[:issue][:status] if params[:issue] && status = params[:issue][:status]
@issue.set_close(current_user) if status == 'closed' @issue.set_close(current_user) if status == 'closed'
@issue.set_open if status == 'open' @issue.set_open if status == 'open'
render :partial => 'status', :status => (@issue.save ? 200 : 400) render partial: 'status', status: (@issue.save ? 200 : 400)
elsif params[:issue] elsif params[:issue]
status, message = if @issue.update_attributes(params[:issue]) status, message = if @issue.update_attributes(params[:issue])
[200, view_context.markdown(@issue.body)] [200, view_context.markdown(@issue.body)]
else else
[400, view_context.local_alert(@issue.errors.full_messages.join('. '))] [400, view_context.local_alert(@issue.errors.full_messages.join('. '))]
end end
render :inline => message, :status => status render inline: message, status: status
else else
render :nothing => true, :status => 200 render nothing: true, status: 200
end end
end end
@ -88,11 +88,11 @@ class Projects::IssuesController < Projects::BaseController
end end
def create_label def create_label
index(@project.labels.create!(:name => params[:name], :color => params[:color]) ? 200 : 500) index(@project.labels.create!(name: params[:name], color: params[:color]) ? 200 : 500)
end end
def update_label def update_label
index(@label.update_attributes(:name => params[:name], :color => params[:color]) ? 200 : 500) index(@label.update_attributes(name: params[:name], color: params[:color]) ? 200 : 500)
end end
def destroy_label def destroy_label
@ -100,7 +100,7 @@ class Projects::IssuesController < Projects::BaseController
end end
def search_collaborators def search_collaborators
render :partial => 'search_collaborators' render partial: 'search_collaborators'
end end
private private

View File

@ -1,8 +1,8 @@
class Projects::ProjectsController < Projects::BaseController class Projects::ProjectsController < Projects::BaseController
include ProjectsHelper include ProjectsHelper
before_filter :authenticate_user! before_filter :authenticate_user!
load_and_authorize_resource :id_param => :project_name # to force member actions load load_and_authorize_resource id_param: :project_name # to force member actions load
before_filter :who_owns, :only => [:new, :create, :mass_import, :run_mass_import] before_filter :who_owns, only: [:new, :create, :mass_import, :run_mass_import]
def index def index
@projects = Project.accessible_by(current_ability, :membered) @projects = Project.accessible_by(current_ability, :membered)
@ -11,8 +11,8 @@ class Projects::ProjectsController < Projects::BaseController
format.html { format.html {
@all_projects = @projects @all_projects = @projects
@groups = current_user.groups @groups = current_user.groups
@owners = User.where(:id => @projects.where(:owner_type => 'User').uniq.pluck(:owner_id)) @owners = User.where(id: @projects.where(owner_type: 'User').uniq.pluck(:owner_id))
@projects = @projects.recent.paginate(:page => params[:page], :per_page => 25) @projects = @projects.recent.paginate(page: params[:page], per_page: 25)
} }
format.json { format.json {
selected_groups = params[:groups] || [] selected_groups = params[:groups] || []
@ -27,7 +27,7 @@ class Projects::ProjectsController < Projects::BaseController
end end
def mass_import def mass_import
@project = Project.new(:mass_import => true) @project = Project.new(mass_import: true)
end end
def run_mass_import def run_mass_import
@ -61,7 +61,7 @@ class Projects::ProjectsController < Projects::BaseController
else else
flash[:error] = t('flash.project.save_error') flash[:error] = t('flash.project.save_error')
flash[:warning] = @project.errors.full_messages.join('. ') flash[:warning] = @project.errors.full_messages.join('. ')
render :action => :new render action: :new
end end
end end
@ -74,7 +74,7 @@ class Projects::ProjectsController < Projects::BaseController
@project.save @project.save
flash[:error] = t('flash.project.save_error') flash[:error] = t('flash.project.save_error')
flash[:warning] = @project.errors.full_messages.join('. ') flash[:warning] = @project.errors.full_messages.join('. ')
render :action => :edit render action: :edit
end end
end end
@ -88,7 +88,7 @@ class Projects::ProjectsController < Projects::BaseController
owner = (Group.find params[:group] if params[:group].present?) || current_user owner = (Group.find params[:group] if params[:group].present?) || current_user
authorize! :write, owner if owner.class == Group authorize! :write, owner if owner.class == Group
if forked = @project.fork(owner, params[:fork_name]) and forked.valid? if forked = @project.fork(owner, params[:fork_name]) and forked.valid?
redirect_to forked, :notice => t("flash.project.forked") redirect_to forked, notice: t("flash.project.forked")
else else
flash[:warning] = t("flash.project.fork_error") flash[:warning] = t("flash.project.fork_error")
flash[:error] = forked.errors.full_messages.join("\n") flash[:error] = forked.errors.full_messages.join("\n")
@ -97,8 +97,8 @@ class Projects::ProjectsController < Projects::BaseController
end end
def possible_forks def possible_forks
render :partial => 'projects/git/base/forks', :layout => false, render partial: 'projects/git/base/forks', layout: false,
:locals => { :owner => current_user, :name => (params[:name].presence || @project.name) } locals: { owner: current_user, name: (params[:name].presence || @project.name) }
end end
def sections def sections
@ -123,18 +123,18 @@ class Projects::ProjectsController < Projects::BaseController
term, limit = params[:term], params[:limit] || 10 term, limit = params[:term], params[:limit] || 10
items = User.member_of_project(@project) items = User.member_of_project(@project)
.where("users.name ILIKE ? OR users.uname ILIKE ?", "%#{term}%", "%#{term}%") .where("users.name ILIKE ? OR users.uname ILIKE ?", "%#{term}%", "%#{term}%")
.limit(limit).map { |u| {:value => u.fullname, :label => u.fullname, :id => u.id} } .limit(limit).map { |u| {value: u.fullname, label: u.fullname, id: u.id} }
render :json => items render json: items
end end
def preview def preview
render :inline => view_context.markdown(params[:text] || ''), :layout => false render inline: view_context.markdown(params[:text] || ''), layout: false
end end
def refs_list def refs_list
refs = @project.repo.branches_and_tags.map(&:name) refs = @project.repo.branches_and_tags.map(&:name)
@selected = (refs.include? params[:selected]) ? params[:selected] : @project.default_branch @selected = (refs.include? params[:selected]) ? params[:selected] : @project.default_branch
render :layout => false render layout: false
end end
protected protected
@ -167,7 +167,7 @@ class Projects::ProjectsController < Projects::BaseController
length = params[:iDisplayLength].to_i length = params[:iDisplayLength].to_i
page = start/length + 1 page = start/length + 1
projects.paginate(:page => page, :per_page => length) projects.paginate(page: page, per_page: length)
else else
projects projects
end end

View File

@ -1,11 +1,11 @@
class Projects::PullRequestsController < Projects::BaseController class Projects::PullRequestsController < Projects::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:index, :show] if APP_CONFIG['anonymous_access']
load_and_authorize_resource :project load_and_authorize_resource :project
load_resource :issue, :through => :project, :find_by => :serial_id, :parent => false, :except => [:index, :autocomplete_to_project] load_resource :issue, through: :project, find_by: :serial_id, parent: false, except: [:index, :autocomplete_to_project]
load_and_authorize_resource :instance_name => :pull, :through => :issue, :singleton => true, :except => [:index, :autocomplete_to_project] load_and_authorize_resource instance_name: :pull, through: :issue, singleton: true, except: [:index, :autocomplete_to_project]
before_filter :find_collaborators, :only => [:new, :create, :show] before_filter :find_collaborators, only: [:new, :create, :show]
def new def new
to_project = find_destination_project(false) to_project = find_destination_project(false)
@ -21,7 +21,7 @@ class Projects::PullRequestsController < Projects::BaseController
@pull.check(false) # don't make event transaction @pull.check(false) # don't make event transaction
if @pull.already? if @pull.already?
@pull.destroy @pull.destroy
flash.now[:warning] = I18n.t('projects.pull_requests.up_to_date', :to_ref => @pull.to_ref, :from_ref => @pull.from_ref) flash.now[:warning] = I18n.t('projects.pull_requests.up_to_date', to_ref: @pull.to_ref, from_ref: @pull.from_ref)
else else
load_diff_commits_data load_diff_commits_data
end end
@ -48,7 +48,7 @@ class Projects::PullRequestsController < Projects::BaseController
@pull.check(false) # don't make event transaction @pull.check(false) # don't make event transaction
if @pull.already? if @pull.already?
@pull.destroy @pull.destroy
flash.now[:error] = I18n.t('projects.pull_requests.up_to_date', :to_ref => @pull.to_ref, :from_ref => @pull.from_ref) flash.now[:error] = I18n.t('projects.pull_requests.up_to_date', to_ref: @pull.to_ref, from_ref: @pull.from_ref)
render :new render :new
else else
@pull.send(@pull.status == 'blocked' ? 'block' : @pull.status) @pull.send(@pull.status == 'blocked' ? 'block' : @pull.status)
@ -68,7 +68,7 @@ class Projects::PullRequestsController < Projects::BaseController
def merge def merge
status = @pull.merge!(current_user) ? 200 : 422 status = @pull.merge!(current_user) ? 200 : 422
render :nothing => true, :status => status render nothing: true, status: status
end end
def update def update
@ -81,7 +81,7 @@ class Projects::PullRequestsController < Projects::BaseController
status = 200 status = 200
end end
end end
render :nothing => true, :status => status render nothing: true, status: status
end end
def show def show
@ -96,7 +96,7 @@ class Projects::PullRequestsController < Projects::BaseController
def index(status = 200) def index(status = 200)
@issues_with_pull_request = @project.issues.joins(:pull_request) @issues_with_pull_request = @project.issues.joins(:pull_request)
@issues_with_pull_request = @issues_with_pull_request.where(:assignee_id => current_user.id) if @is_assigned_to_me = params[:filter] == 'to_me' @issues_with_pull_request = @issues_with_pull_request.where(assignee_id: current_user.id) if @is_assigned_to_me = params[:filter] == 'to_me'
@issues_with_pull_request = @issues_with_pull_request.search(params[:search_pull_request]) if params[:search_pull_request] !~ /#{t('layout.pull_requests.search')}/ @issues_with_pull_request = @issues_with_pull_request.search(params[:search_pull_request]) if params[:search_pull_request] !~ /#{t('layout.pull_requests.search')}/
@opened_issues, @closed_issues = @issues_with_pull_request.not_closed_or_merged.count, @issues_with_pull_request.closed_or_merged.count @opened_issues, @closed_issues = @issues_with_pull_request.not_closed_or_merged.count, @issues_with_pull_request.closed_or_merged.count
@ -110,11 +110,11 @@ class Projects::PullRequestsController < Projects::BaseController
@issues_with_pull_request = @issues_with_pull_request. @issues_with_pull_request = @issues_with_pull_request.
includes(:assignee, :user, :pull_request).uniq. includes(:assignee, :user, :pull_request).uniq.
paginate :per_page => 20, :page => params[:page] paginate per_page: 20, page: params[:page]
if status == 200 if status == 200
render 'index', :layout => request.xhr? ? 'with_sidebar' : 'application' render 'index', layout: request.xhr? ? 'with_sidebar' : 'application'
else else
render :status => status, :nothing => true render status: status, nothing: true
end end
end end
@ -125,7 +125,7 @@ class Projects::PullRequestsController < Projects::BaseController
items.concat p.by_owner_and_name(term) items.concat p.by_owner_and_name(term)
end end
items = items.uniq{|i| i.id}.select{|e| e.repo.branches.count > 0} items = items.uniq{|i| i.id}.select{|e| e.repo.branches.count > 0}
render :json => json_for_autocomplete_base(items) render json: json_for_autocomplete_base(items)
end end
protected protected
@ -136,7 +136,7 @@ class Projects::PullRequestsController < Projects::BaseController
def json_for_autocomplete_base items def json_for_autocomplete_base items
items.collect do |project| items.collect do |project|
hash = {:id => project.id.to_s, :label => project.name_with_owner, :value => project.name_with_owner} hash = {id: project.id.to_s, label: project.name_with_owner, value: project.name_with_owner}
hash[:get_refs_url] = project_refs_list_path(project) hash[:get_refs_url] = project_refs_list_path(project)
hash hash
end end

View File

@ -2,11 +2,11 @@ class Projects::SubscribesController < Projects::BaseController
before_filter :authenticate_user! before_filter :authenticate_user!
load_and_authorize_resource :project load_and_authorize_resource :project
load_and_authorize_resource :issue, :through => :project, :find_by => :serial_id load_and_authorize_resource :issue, through: :project, find_by: :serial_id
load_and_authorize_resource :subscribe, :through => :issue, :find_by => :user_id load_and_authorize_resource :subscribe, through: :issue, find_by: :user_id
def create def create
@subscribe = @issue.subscribes.build(:user_id => current_user.id) @subscribe = @issue.subscribes.build(user_id: current_user.id)
if @subscribe.save if @subscribe.save
flash[:notice] = I18n.t("flash.subscribe.saved") flash[:notice] = I18n.t("flash.subscribe.saved")
redirect_to :back redirect_to :back

View File

@ -5,11 +5,11 @@ class Projects::WikiController < Projects::BaseController
WIKI_OPTIONS = {} WIKI_OPTIONS = {}
before_filter :authenticate_user! before_filter :authenticate_user!
skip_before_filter :authenticate_user!, :only => [:show, :index, :git, :compare, :compare_wiki, :history, :wiki_history, :search, :pages] if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: [:show, :index, :git, :compare, :compare_wiki, :history, :wiki_history, :search, :pages] if APP_CONFIG['anonymous_access']
load_resource :project load_resource :project
before_filter :authorize_read_actions, :only => [:index, :show, :git, :compare, :compare_wiki, :history, :wiki_history, :search, :pages] before_filter :authorize_read_actions, only: [:index, :show, :git, :compare, :compare_wiki, :history, :wiki_history, :search, :pages]
before_filter :authorize_write_actions, :only => [:edit, :update, :new, :create, :destroy, :revert, :revert_wiki, :preview] before_filter :authorize_write_actions, only: [:edit, :update, :new, :create, :destroy, :revert, :revert_wiki, :preview]
before_filter :get_wiki before_filter :get_wiki
def index def index
@ -49,13 +49,13 @@ class Projects::WikiController < Projects::BaseController
@page = @wiki.page(@name) @page = @wiki.page(@name)
name = params[:rename] || @name name = params[:rename] || @name
update_wiki_page(@wiki, @page, params[:content], {:committer => committer}, name, params[:format]) update_wiki_page(@wiki, @page, params[:content], {committer: committer}, name, params[:format])
update_wiki_page(@wiki, @page.footer, params[:footer], {:committer => committer}) if params[:footer] update_wiki_page(@wiki, @page.footer, params[:footer], {committer: committer}) if params[:footer]
update_wiki_page(@wiki, @page.sidebar, params[:sidebar], {:committer => committer}) if params[:sidebar] update_wiki_page(@wiki, @page.sidebar, params[:sidebar], {committer: committer}) if params[:sidebar]
committer.commit committer.commit
flash[:notice] = t('flash.wiki.successfully_updated', :name => @name) flash[:notice] = t('flash.wiki.successfully_updated', name: @name)
redirect_to project_wiki_path(@project, CGI.escape(@name)) redirect_to project_wiki_path(@project, CGI.escape(@name))
end end
@ -67,11 +67,11 @@ class Projects::WikiController < Projects::BaseController
@name = CGI.unescape(params['page']) @name = CGI.unescape(params['page'])
format = params['format'].intern format = params['format'].intern
begin begin
@wiki.write_page(@name, format, params['content'] || '', {:committer => committer}).commit @wiki.write_page(@name, format, params['content'] || '', {committer: committer}).commit
redirect_to project_wiki_path(@project, CGI.escape(@name)) redirect_to project_wiki_path(@project, CGI.escape(@name))
rescue Gollum::DuplicatePageError => e rescue Gollum:DuplicatePageError: e
flash[:error] = t("flash.wiki.duplicate_page", :name => @name) flash[:error] = t("flash.wiki.duplicate_page", name: @name)
render :action => :new render action: :new
end end
end end
@ -79,10 +79,10 @@ class Projects::WikiController < Projects::BaseController
@name = CGI.unescape(params[:id]) @name = CGI.unescape(params[:id])
page = @wiki.page(@name) page = @wiki.page(@name)
if page if page
@wiki.delete_page(page, {:committer => committer}).commit @wiki.delete_page(page, {committer: committer}).commit
flash[:notice] = t("flash.wiki.page_successfully_removed") flash[:notice] = t("flash.wiki.page_successfully_removed")
else else
flash[:notice] = t("flash.wiki.page_not_found", :name => params[:id]) flash[:notice] = t("flash.wiki.page_not_found", name: params[:id])
end end
redirect_to project_wiki_index_path(@project) redirect_to project_wiki_index_path(@project)
end end
@ -149,12 +149,12 @@ class Projects::WikiController < Projects::BaseController
sha2 = params[:sha2] sha2 = params[:sha2]
sha2 = nil if params[:sha2] == 'prev' sha2 = nil if params[:sha2] == 'prev'
if c = @wiki.revert_page(@page, sha1, sha2, {:committer => committer}) and c.commit if c = @wiki.revert_page(@page, sha1, sha2, {committer: committer}) and c.commit
flash[:notice] = t("flash.wiki.revert_success") flash[:notice] = t("flash.wiki.revert_success")
redirect_to project_wiki_path(@project, CGI.escape(@name)) redirect_to project_wiki_path(@project, CGI.escape(@name))
else else
# if revert wasn't successful then redirect back to comparsion. # if revert wasn't successful then redirect back to comparsion.
# if second commit version is missed, then second version is # if second commit version is missed, then second version is
# params[:sha1] and first version is parent of params[:sha1] # params[:sha1] and first version is parent of params[:sha1]
# (see Gollum::Wiki#revert_page) # (see Gollum::Wiki#revert_page)
sha2, sha1 = sha1, "#{sha1}^" if !sha2 sha2, sha1 = sha1, "#{sha1}^" if !sha2
@ -170,7 +170,7 @@ class Projects::WikiController < Projects::BaseController
sha1 = params[:sha1] sha1 = params[:sha1]
sha2 = params[:sha2] sha2 = params[:sha2]
sha2 = nil if sha2 == 'prev' sha2 = nil if sha2 == 'prev'
if c = @wiki.revert_commit(sha1, sha2, {:committer => committer}) and c.commit if c = @wiki.revert_commit(sha1, sha2, {committer: committer}) and c.commit
flash[:notice] = t("flash.wiki.revert_success") flash[:notice] = t("flash.wiki.revert_success")
redirect_to project_wiki_index_path(@project) redirect_to project_wiki_index_path(@project)
else else
@ -218,14 +218,14 @@ class Projects::WikiController < Projects::BaseController
def get_wiki def get_wiki
@wiki = Gollum::Wiki.new(@project.wiki_path, @wiki = Gollum::Wiki.new(@project.wiki_path,
WIKI_OPTIONS.merge(:base_path => project_wiki_index_path(@project))) WIKI_OPTIONS.merge(base_path: project_wiki_index_path(@project)))
end end
# This method was grabbed from sinatra application, shipped with Gollum gem. # This method was grabbed from sinatra application, shipped with Gollum gem.
# See Gollum gem and Gollum License if you have any questions about license notes. # See Gollum gem and Gollum License if you have any questions about license notes.
# https://github.com/github/gollum https://github.com/github/gollum/blob/master/LICENSE # https://github.com/github/gollum https://github.com/github/gollum/blob/master/LICENSE
def update_wiki_page(wiki, page, content, commit_msg, name = nil, format = nil) def update_wiki_page(wiki, page, content, commit_msg, name = nil, format = nil)
return if !page || return if !page ||
((!content || page.raw_data == content) && page.format == format) ((!content || page.raw_data == content) && page.format == format)
name ||= page.name name ||= page.name
format = (format || page.format).to_sym format = (format || page.format).to_sym
@ -247,14 +247,14 @@ class Projects::WikiController < Projects::BaseController
msg << " (#{params['format']})" if params['format'] msg << " (#{params['format']})" if params['format']
end end
msg = 'Unhandled action' if !msg || msg.empty? msg = 'Unhandled action' if !msg || msg.empty?
{ :message => msg } { message: msg }
end end
def committer def committer
unless @committer unless @committer
p = commit_message.merge({:name => current_user.uname, :email => current_user.email}) p = commit_message.merge({name: current_user.uname, email: current_user.email})
@committer = Gollum::Committer.new(@wiki, p) @committer = Gollum::Committer.new(@wiki, p)
GitHook.perform_later!(:notification, :process, {:project_id => @project.id, :actor_name => @committer.actor.name, :commit_sha => @committer.commit}) GitHook.perform_later!(:notification, :process, {project_id: @project.id, actor_name: @committer.actor.name, commit_sha: @committer.commit})
end end
@committer @committer
end end
@ -265,12 +265,12 @@ class Projects::WikiController < Projects::BaseController
@editable = can?(:write, @project) @editable = can?(:write, @project)
render :show render :show
elsif file = @wiki.file(@name) elsif file = @wiki.file(@name)
render :text => file.raw_data, :content_type => file.mime_type render text: file.raw_data, content_type: file.mime_type
elsif can? :write, @project elsif can? :write, @project
@new = true @new = true
render :new render :new
else else
redirect_to :action => :index #forbidden_path redirect_to action: :index #forbidden_path
end end
end end

View File

@ -8,7 +8,7 @@ class SearchController < ApplicationController
Search.by_term_and_type( Search.by_term_and_type(
@query, @query,
@type, @type,
{:page => params[:page]} {page: params[:page]}
).each do |k, v| ).each do |k, v|
var = :"@#{k}" var = :"@#{k}"
instance_variable_set var, v unless instance_variable_defined?(var) instance_variable_set var, v unless instance_variable_defined?(var)

View File

@ -13,23 +13,23 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
end end
def passthru def passthru
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false render file: "#{Rails.root}/public/404.html", status: 404, layout: false
end end
private private
def oauthorize(kind) def oauthorize(kind)
provider = kind.downcase provider = kind.downcase
@user = find_for_ouath(env["omniauth.auth"], current_user) @user = find_for_ouath(env["omniauth.auth"], current_user)
if @user && @user.persisted? if @user && @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => action_name.classify flash[:notice] = I18n.t "devise.omniauth_callbacks.success", kind: action_name.classify
sign_in_and_redirect @user, :event => :authentication sign_in_and_redirect @user, event: :authentication
else else
session["devise.#{provider}_data"] = env["omniauth.auth"] session["devise.#{provider}_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url redirect_to new_user_registration_url
end end
end end
def find_for_ouath(auth, resource=nil) def find_for_ouath(auth, resource=nil)
provider, uid = auth['provider'], auth['uid'] provider, uid = auth['provider'], auth['uid']
authentication = Authentication.find_or_initialize_by_provider_and_uid(provider, uid) authentication = Authentication.find_or_initialize_by_provider_and_uid(provider, uid)
@ -59,5 +59,5 @@ class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
end end
return authentication.user return authentication.user
end end
end end

View File

@ -1,5 +1,5 @@
class Users::ProfileController < Users::BaseController class Users::ProfileController < Users::BaseController
skip_before_filter :authenticate_user!, :only => :show if APP_CONFIG['anonymous_access'] skip_before_filter :authenticate_user!, only: :show if APP_CONFIG['anonymous_access']
def show def show
@path, page = user_path, params[:page].to_i @path, page = user_path, params[:page].to_i
@ -11,7 +11,7 @@ class Users::ProfileController < Users::BaseController
else else
@projects = @projects.by_visibilities('hidden').accessible_by(current_ability, :read) @projects = @projects.by_visibilities('hidden').accessible_by(current_ability, :read)
end end
render :partial => 'shared/profile_projects', :layout => nil, :locals => {:projects => paginate_projects(page)} render partial: 'shared/profile_projects', layout: nil, locals: {projects: paginate_projects(page)}
else else
@projects = paginate_projects(page) @projects = paginate_projects(page)
end end
@ -20,6 +20,6 @@ class Users::ProfileController < Users::BaseController
protected protected
def paginate_projects(page) def paginate_projects(page)
@projects.paginate(:page => (page>0 ? page : nil), :per_page => 24) @projects.paginate(page: (page>0 ? page : nil), per_page: 24)
end end
end end

View File

@ -3,7 +3,7 @@ class Users::RegistrationsController < Devise::RegistrationsController
def create def create
# Try stop bots # Try stop bots
if params[:recaptcha_response_field].present? if params[:recaptcha_response_field].present?
respond_with(resource, :location => after_inactive_sign_up_path_for(resource)) respond_with(resource, location: after_inactive_sign_up_path_for(resource))
return return
end end
super super

View File

@ -34,7 +34,7 @@ class Users::SettingsController < Users::BaseController
else else
flash[:error] = t('flash.user.save_error') flash[:error] = t('flash.user.save_error')
flash[:warning] = @user.errors.full_messages.join('. ') flash[:warning] = @user.errors.full_messages.join('. ')
render(:action => :private) render(action: :private)
end end
end end
end end

View File

@ -1,6 +1,6 @@
class Users::UsersController < Users::BaseController class Users::UsersController < Users::BaseController
skip_before_filter :authenticate_user!, :only => [:allowed, :check, :discover] skip_before_filter :authenticate_user!, only: [:allowed, :check, :discover]
before_filter :find_user_by_key, :only => [:allowed, :discover] before_filter :find_user_by_key, only: [:allowed, :discover]
def allowed def allowed
owner_name, project_name = params[:project].split '/' owner_name, project_name = params[:project].split '/'
@ -11,15 +11,15 @@ class Users::UsersController < Users::BaseController
when 'git-receive-pack' when 'git-receive-pack'
then :write then :write
end end
render :inline => (!@user.access_locked? && Ability.new(@user).can?(action, project)).to_s render inline: (!@user.access_locked? && Ability.new(@user).can?(action, project)).to_s
end end
def check def check
render :nothing => true render nothing: true
end end
def discover def discover
render :json => {:name => @user.name}.to_json render json: {name: @user.name}.to_json
end end
protected protected

View File

@ -1,6 +1,6 @@
module ActivityFeedsHelper module ActivityFeedsHelper
def render_activity_feed(activity_feed) def render_activity_feed(activity_feed)
render activity_feed.partial, activity_feed.data.merge(:activity_feed => activity_feed) render activity_feed.partial, activity_feed.data.merge(activity_feed: activity_feed)
end end
def get_feed_title_from_content(content) def get_feed_title_from_content(content)

View File

@ -1,12 +1,12 @@
module AdvisoriesHelper module AdvisoriesHelper
def advisories_select_options(advisories, opts = {:class => 'popoverable'}) def advisories_select_options(advisories, opts = {class: 'popoverable'})
def_values = [[t("layout.advisories.no_"), 'no'], [t("layout.advisories.new"), 'new'], [t("layout.advisories.existing"), 'existing', {:class => 'advisory_id'}]] def_values = [[t("layout.advisories.no_"), 'no'], [t("layout.advisories.new"), 'new'], [t("layout.advisories.existing"), 'existing', {class: 'advisory_id'}]]
options_for_select(def_values, def_values.first) options_for_select(def_values, def_values.first)
end end
def advisory_id_for_hint def advisory_id_for_hint
sprintf(Advisory::ID_STRING_TEMPLATE, :type => "{#{Advisory::TYPES.values.join(',')}}", sprintf(Advisory::ID_STRING_TEMPLATE, type: "{#{Advisory::TYPES.values.join(',')}}",
:year => 'YYYY', :id => 'XXXX') year: 'YYYY', id: 'XXXX')
end end
def construct_ref_link(ref) def construct_ref_link(ref)

View File

@ -39,18 +39,18 @@ module ApplicationHelper
def local_alert(text, type = 'error') def local_alert(text, type = 'error')
html = "<div class='flash'><div class='alert #{type}'> #{text}" html = "<div class='flash'><div class='alert #{type}'> #{text}"
html << link_to('×', '#', :class => 'close close-alert', 'data-dismiss' => 'alert') html << link_to('×', '#', class: 'close close-alert', 'data-dismiss' => 'alert')
html << '</div></div>' html << '</div></div>'
end end
# Why 42? Because it is the Answer! # Why 42? Because it is the Answer!
def short_message(message, length = 42) def short_message(message, length = 42)
truncate(message, :length => length, :omission => '…') truncate(message, length: length, omission: '…')
end end
def datetime_moment(date, options = {}) def datetime_moment(date, options = {})
tag = options[:tag] || :div tag = options[:tag] || :div
klass = "datetime_moment #{options[:class]}" klass = "datetime_moment #{options[:class]}"
content_tag(tag, nil, :class => klass, :title => date.strftime('%Y-%m-%d %H:%M:%S UTC'), :origin_datetime => date.to_i) content_tag(tag, nil, class: klass, title: date.strftime('%Y-%m-%d %H:%M:%S UTC'), origin_datetime: date.to_i)
end end
end end

View File

@ -26,9 +26,9 @@ module BuildListsHelper
"#{r.platform.name}/#{r.name}", "#{r.platform.name}/#{r.name}",
r.id, r.id,
{ {
:publish_without_qa => r.publish_without_qa? ? 1 : 0, publish_without_qa: r.publish_without_qa? ? 1 : 0,
:platform_id => r.platform.id, platform_id: r.platform.id,
:default_arches => (r.platform.platform_arch_settings.by_default.pluck(:arch_id).presence || Arch.where(:name => Arch::DEFAULT).pluck(:id)).join(' ') default_arches: (r.platform.platform_arch_settings.by_default.pluck(:arch_id).presence || Arch.where(name: Arch::DEFAULT).pluck(:id)).join(' ')
} }
] ]
end.sort_by { |col| col[0] } end.sort_by { |col| col[0] }
@ -68,10 +68,10 @@ module BuildListsHelper
def build_list_classified_update_types def build_list_classified_update_types
advisoriable = BuildList::RELEASE_UPDATE_TYPES.map do |el| advisoriable = BuildList::RELEASE_UPDATE_TYPES.map do |el|
[el, {:class => 'advisoriable'}] [el, {class: 'advisoriable'}]
end end
nonadvisoriable = (BuildList::UPDATE_TYPES - BuildList::RELEASE_UPDATE_TYPES).map do |el| nonadvisoriable = (BuildList::UPDATE_TYPES - BuildList::RELEASE_UPDATE_TYPES).map do |el|
[el, {:class => 'nonadvisoriable'}] [el, {class: 'nonadvisoriable'}]
end end
return advisoriable + nonadvisoriable return advisoriable + nonadvisoriable
@ -82,8 +82,8 @@ module BuildListsHelper
if item.version =~ /^[\da-z]+$/ && item.name == item.build_list.project.name if item.version =~ /^[\da-z]+$/ && item.name == item.build_list.project.name
bl = item.build_list bl = item.build_list
{ {
:text => str_version ? "#{shortest_hash_id item.version, hash_size}" : shortest_hash_id(item.version, hash_size), text: str_version ? "#{shortest_hash_id item.version, hash_size}" : shortest_hash_id(item.version, hash_size),
:href => commit_path(bl.project.owner, bl.project, item.version) href: commit_path(bl.project.owner, bl.project, item.version)
} }
else else
{} {}

View File

@ -6,11 +6,11 @@ module CommitHelper
res << "<tr>" res << "<tr>"
res << "<td><a href='#diff-#{ind}'>#{h(filename.rtruncate 120)}</a></td>" res << "<td><a href='#diff-#{ind}'>#{h(filename.rtruncate 120)}</a></td>"
res << "<td class='diffstat'>" res << "<td class='diffstat'>"
res << I18n.t("layout.projects.inline_changes_count", :count => total).strip + res << I18n.t("layout.projects.inline_changes_count", count: total).strip +
" (" + " (" +
I18n.t("layout.projects.inline_additions_count", :count => adds).strip + I18n.t("layout.projects.inline_additions_count", count: adds).strip +
", " + ", " +
I18n.t("layout.projects.inline_deletions_count", :count => deletes).strip + I18n.t("layout.projects.inline_deletions_count", count: deletes).strip +
")" ")"
res << "</td>" res << "</td>"
ind +=1 ind +=1
@ -25,7 +25,7 @@ module CommitHelper
# end # end
def commit_date(date) def commit_date(date)
I18n.localize(date, { :format => "%d %B %Y" }) I18n.localize(date, { format: "%d %B %Y" })
end end
def short_hash_id(id) def short_hash_id(id)
@ -39,7 +39,7 @@ module CommitHelper
def commit_author_link(author) def commit_author_link(author)
name = author.name name = author.name
email = author.email email = author.email
u = User.where(:email => email).first u = User.where(email: email).first
u.present? ? link_to(name, user_path(u)) : mail_to(email, name) u.present? ? link_to(name, user_path(u)) : mail_to(email, name)
end end

View File

@ -8,9 +8,9 @@ module ContentsHelper
compound_path = '' compound_path = ''
paths.map do |p| paths.map do |p|
compound_path << p << '/' if p != '/' compound_path << p << '/' if p != '/'
link_to(platform_content_path(platform, compound_path), {:remote => true}) do link_to(platform_content_path(platform, compound_path), {remote: true}) do
content_tag(:span, p, {:class => 'text'}) + content_tag(:span, p, {class: 'text'}) +
content_tag(:span, '', {:class => 'arrow-right'}) content_tag(:span, '', {class: 'arrow-right'})
end end
end.join.html_safe end.join.html_safe
end end

View File

@ -6,11 +6,11 @@ module DiffHelper
res << "<tr>" res << "<tr>"
res << "<td>#{link_to stat.filename.rtruncate(120), "#{path}#diff-#{ind}"}</td>" res << "<td>#{link_to stat.filename.rtruncate(120), "#{path}#diff-#{ind}"}</td>"
res << "<td class='diffstat'>" res << "<td class='diffstat'>"
res << I18n.t("layout.projects.inline_changes_count", :count => stat.additions + stat.deletions).strip + res << I18n.t("layout.projects.inline_changes_count", count: stat.additions + stat.deletions).strip +
" (" + " (" +
I18n.t("layout.projects.inline_additions_count", :count => stat.additions).strip + I18n.t("layout.projects.inline_additions_count", count: stat.additions).strip +
", " + ", " +
I18n.t("layout.projects.inline_deletions_count", :count => stat.deletions).strip + I18n.t("layout.projects.inline_deletions_count", count: stat.deletions).strip +
")" ")"
res << "</td>" res << "</td>"
end end
@ -34,7 +34,7 @@ module DiffHelper
elsif @commit elsif @commit
commit_path @project, @commit commit_path @project, @commit
end end
prepare(args.merge({:filepath => filepath, :comments => comments, :in_discussion => in_discussion})) prepare(args.merge({filepath: filepath, comments: comments, in_discussion: in_discussion}))
res = '<table class="diff inline" cellspacing="0" cellpadding="0" ng-non-bindable>' res = '<table class="diff inline" cellspacing="0" cellpadding="0" ng-non-bindable>'
res << '<tbody>' res << '<tbody>'
@ -228,7 +228,7 @@ module DiffHelper
def line_comment def line_comment
return if @no_commit_comment || (@in_discussion && @add_reply_id && @line_comments[0].data[:line].to_i != @num_line) return if @no_commit_comment || (@in_discussion && @add_reply_id && @line_comments[0].data[:line].to_i != @num_line)
link_to image_tag('line_comment.png', :alt => t('layout.comments.new_header')), new_comment_path, :class => 'add_line-comment' if current_user link_to image_tag('line_comment.png', alt: t('layout.comments.new_header')), new_comment_path, class: 'add_line-comment' if current_user
end end
def render_line_comments def render_line_comments
@ -251,17 +251,17 @@ module DiffHelper
<td>" <td>"
comments.each do |comment| comments.each do |comment|
res << "<div class='line-comments'> res << "<div class='line-comments'>
#{render 'projects/comments/comment', :comment => comment, :data => {:project => @project, :commentable => @commentable, :add_anchor => 'inline', :in_discussion => @in_discussion}} #{render 'projects/comments/comment', comment: comment, data: {project: @project, commentable: @commentable, add_anchor: 'inline', in_discussion: @in_discussion}}
</div>" </div>"
end end
res << link_to(t('layout.comments.new_inline'), new_comment_path, :class => 'new_inline_comment button') if current_user res << link_to(t('layout.comments.new_inline'), new_comment_path, class: 'new_inline_comment button') if current_user
res << "</td></tr>" res << "</td></tr>"
end end
def new_comment_path def new_comment_path
hash = {:path => @filepath, :line => @num_line} hash = {path: @filepath, line: @num_line}
if @commentable.is_a? Issue if @commentable.is_a? Issue
project_new_line_pull_comment_path(@project, @commentable, hash.merge({:in_reply => @add_reply_id})) project_new_line_pull_comment_path(@project, @commentable, hash.merge({in_reply: @add_reply_id}))
elsif @commentable.is_a? Grit::Commit elsif @commentable.is_a? Grit::Commit
new_line_commit_comment_path(@project, @commentable, hash) new_line_commit_comment_path(@project, @commentable, hash)
end end

View File

@ -69,19 +69,19 @@ module GitHelper
def branch_selector_options(project) def branch_selector_options(project)
p, tag_enabled = params.dup, !(controller_name == 'trees' && action_name == 'branches') p, tag_enabled = params.dup, !(controller_name == 'trees' && action_name == 'branches')
p.delete(:path) if p[:path].present? # to root path p.delete(:path) if p[:path].present? # to root path
p.merge!(:project_id => project.id, :treeish => project.default_branch).delete(:id) unless p[:treeish].present? p.merge!(project_id: project.id, treeish: project.default_branch).delete(:id) unless p[:treeish].present?
current = url_for(p).split('?', 2).first current = url_for(p).split('?', 2).first
res = [] res = []
if params[:treeish].present? && !project.repo.branches_and_tags.map(&:name).include?(params[:treeish]) if params[:treeish].present? && !project.repo.branches_and_tags.map(&:name).include?(params[:treeish])
res << [I18n.t('layout.git.repositories.commits'), [params[:treeish].truncate(20)]] res << [I18n.t('layout.git.repositories.commits'), [params[:treeish].truncate(20)]]
end end
linking = Proc.new {|name| [name.truncate(20), url_for(p.merge :treeish => name).split('?', 2).first]} linking = Proc.new {|name| [name.truncate(20), url_for(p.merge treeish: name).split('?', 2).first]}
res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&:name).sort.map(&linking)] res << [I18n.t('layout.git.repositories.branches'), project.repo.branches.map(&:name).sort.map(&linking)]
if tag_enabled if tag_enabled
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&:name).sort.map(&linking)] res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&:name).sort.map(&linking)]
else else
res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&:name).sort.map {|name| [name.truncate(20), {:disabled => true}]}] res << [I18n.t('layout.git.repositories.tags'), project.repo.tags.map(&:name).sort.map {|name| [name.truncate(20), {disabled: true}]}]
end end
grouped_options_for_select(res, current) grouped_options_for_select(res, current)
end end

View File

@ -1,7 +1,7 @@
module MassBuildHelper module MassBuildHelper
def link_to_list platform, mass_build, which def link_to_list platform, mass_build, which
link_to t("layout.mass_builds.#{which}"), link_to t("layout.mass_builds.#{which}"),
get_list_platform_mass_build_path(@platform, mass_build, :kind => which, :format => :txt), get_list_platform_mass_build_path(@platform, mass_build, kind: which, format: :txt),
:target => "_blank" if can?(:get_list, mass_build) target: "_blank" if can?(:get_list, mass_build)
end end
end end

View File

@ -6,7 +6,7 @@ module PaginateHelper
per_page = 100 if per_page >100 per_page = 100 if per_page >100
page = params[:page].to_i page = params[:page].to_i
page = nil if page == 0 page = nil if page == 0
{:page => page, :per_page => per_page} {page: page, per_page: per_page}
end end
def angularjs_will_paginate(collection_or_options = nil, options = {}) def angularjs_will_paginate(collection_or_options = nil, options = {})

View File

@ -1,20 +1,20 @@
module ProjectsHelper module ProjectsHelper
def options_for_filters(all_projects, groups, owners) def options_for_filters(all_projects, groups, owners)
projects_count_by_groups = all_projects.where(:owner_id => groups, :owner_type => 'Group'). projects_count_by_groups = all_projects.where(owner_id: groups, owner_type: 'Group').
group(:owner_id).count group(:owner_id).count
projects_count_by_owners = all_projects.where(:owner_id => owners, :owner_type => 'User'). projects_count_by_owners = all_projects.where(owner_id: owners, owner_type: 'User').
group(:owner_id).count group(:owner_id).count
(groups + owners).map do |o| (groups + owners).map do |o|
class_name = o.class.name class_name = o.class.name
{ {
:id => "#{class_name.downcase}-#{o.id}", id: "#{class_name.downcase}-#{o.id}",
:color => '0054a6', color: '0054a6',
:selected => false, selected: false,
:check_box_name => class_name.downcase.pluralize, check_box_name: class_name.downcase.pluralize,
:check_box_value => o.id, check_box_value: o.id,
:name => content_tag(:div, content_tag(:span, o.uname, :class => class_name.downcase)), name: content_tag(:div, content_tag(:span, o.uname, class: class_name.downcase)),
:uname => o.uname, # only for sorting uname: o.uname, # only for sorting
:count => o.is_a?(User) ? projects_count_by_owners[o.id] : projects_count_by_groups[o.id] count: o.is_a?(User) ? projects_count_by_owners[o.id] : projects_count_by_groups[o.id]
} }
end.sort_by{ |f| f[:uname] } end.sort_by{ |f| f[:uname] }
end end

View File

@ -9,13 +9,13 @@ module PullRequestHelper
def pull_status_label pull_status, options = {} def pull_status_label pull_status, options = {}
statuses = {'ready' => 'success', 'closed' => 'important', 'merged' => 'important', 'blocked' => 'warning'} statuses = {'ready' => 'success', 'closed' => 'important', 'merged' => 'important', 'blocked' => 'warning'}
content_tag :span, t("projects.pull_requests.statuses.#{pull_status}"), options.merge(:class => "state label-bootstrap label-#{statuses[pull_status]}") content_tag :span, t("projects.pull_requests.statuses.#{pull_status}"), options.merge(class: "state label-bootstrap label-#{statuses[pull_status]}")
end end
def pull_status pull def pull_status pull
if %w(blocked merged closed ready open).include? pull.status if %w(blocked merged closed ready open).include? pull.status
t("projects.pull_requests.#{pull.status}", :user => pull.issue.closer.try(:uname), :to_ref => show_ref(pull, 'to'), t("projects.pull_requests.#{pull.status}", user: pull.issue.closer.try(:uname), to_ref: show_ref(pull, 'to'),
:from_ref => show_ref(pull, 'from'), :time => pull.issue.closed_at).html_safe from_ref: show_ref(pull, 'from'), time: pull.issue.closed_at).html_safe
else else
raise "pull id (#{pull.id}) wrong status #{pull.status} " raise "pull id (#{pull.id}) wrong status #{pull.status} "
end end

View File

@ -1,7 +1,7 @@
module UsersHelper module UsersHelper
def avatar_url_by_email(email, size = :small) def avatar_url_by_email(email, size = :small)
avatar_url(User.where(:email => email).first || User.new(:email => email), size) avatar_url(User.where(email: email).first || User.new(email: email), size)
end end
def avatar_url(subject, size = :small) def avatar_url(subject, size = :small)

View File

@ -22,9 +22,9 @@ module WikiHelper
def editor_path(project, name) def editor_path(project, name)
if @new if @new
url_for(:controller => :wiki, :action => :create, :project_id => project.id) url_for(controller: :wiki, action: :create, project_id: project.id)
else else
url_for(:controller => :wiki, :action => :update, :project_id => project.id, :id => name) url_for(controller: :wiki, action: :update, project_id: project.id, id: name)
end end
end end

View File

@ -1,10 +1,10 @@
class FeedbackMailer < ActionMailer::Base class FeedbackMailer < ActionMailer::Base
FBM_CONFIG = APP_CONFIG['feedback'] FBM_CONFIG = APP_CONFIG['feedback']
default :to => FBM_CONFIG['email'], default to: FBM_CONFIG['email'],
:cc => FBM_CONFIG['cc'], cc: FBM_CONFIG['cc'],
:bcc => FBM_CONFIG['bcc'] bcc: FBM_CONFIG['bcc']
default_url_options.merge!(:protocol => 'https') if APP_CONFIG['mailer_https_url'] default_url_options.merge!(protocol: 'https') if APP_CONFIG['mailer_https_url']
include Resque::Mailer # send email async include Resque::Mailer # send email async
@ -14,7 +14,7 @@ class FeedbackMailer < ActionMailer::Base
from = "#{@data.name} <#{@data.email}>" from = "#{@data.name} <#{@data.email}>"
subj = prepare_subject(@data.subject) subj = prepare_subject(@data.subject)
mail :from => from, :subject => subj mail from: from, subject: subj
end end
protected protected
@ -31,5 +31,4 @@ class FeedbackMailer < ActionMailer::Base
def affix(affixes) def affix(affixes)
' %s ' % Array(affixes).map{|e| "[#{e}]"}.join ' %s ' % Array(affixes).map{|e| "[#{e}]"}.join
end end
end end

View File

@ -2,17 +2,17 @@ class UserMailer < ActionMailer::Base
add_template_helper ActivityFeedsHelper add_template_helper ActivityFeedsHelper
add_template_helper CommitHelper add_template_helper CommitHelper
default :from => "\"#{APP_CONFIG['project_name']}\" <#{APP_CONFIG['do-not-reply-email']}>" default from: "\"#{APP_CONFIG['project_name']}\" <#{APP_CONFIG['do-not-reply-email']}>"
default_url_options.merge!(:protocol => 'https') if APP_CONFIG['mailer_https_url'] default_url_options.merge!(protocol: 'https') if APP_CONFIG['mailer_https_url']
include Resque::Mailer # send email async include Resque::Mailer # send email async
def new_user_notification(user) def new_user_notification(user)
@user = user @user = user
mail( mail(
:to => email_with_name(user, user.email), to: email_with_name(user, user.email),
:subject => I18n.t("notifications.subjects.new_user_notification", subject: I18n.t("notifications.subjects.new_user_notification",
:project_name => APP_CONFIG['project_name']) project_name: APP_CONFIG['project_name'])
) do |format| ) do |format|
format.html format.html
end end
@ -23,9 +23,9 @@ class UserMailer < ActionMailer::Base
subject = @comment.issue_comment? ? subject_for_issue(@comment.commentable) : subject = @comment.issue_comment? ? subject_for_issue(@comment.commentable) :
I18n.t('notifications.subjects.new_commit_comment_notification') I18n.t('notifications.subjects.new_commit_comment_notification')
mail( mail(
:to => email_with_name(user, user.email), to: email_with_name(user, user.email),
:subject => subject, subject: subject,
:from => email_with_name(comment.user) from: email_with_name(comment.user)
) do |format| ) do |format|
format.html format.html
end end
@ -34,9 +34,9 @@ class UserMailer < ActionMailer::Base
def new_issue_notification(issue, user) def new_issue_notification(issue, user)
@user, @issue = user, issue @user, @issue = user, issue
mail( mail(
:to => email_with_name(user, user.email), to: email_with_name(user, user.email),
:subject => subject_for_issue(issue, true), subject: subject_for_issue(issue, true),
:from => email_with_name(issue.user) from: email_with_name(issue.user)
) do |format| ) do |format|
format.html format.html
end end
@ -45,8 +45,8 @@ class UserMailer < ActionMailer::Base
def issue_assign_notification(issue, user) def issue_assign_notification(issue, user)
@issue = issue @issue = issue
mail( mail(
:to => email_with_name(user, user.email), to: email_with_name(user, user.email),
:subject => subject_for_issue(@issue) subject: subject_for_issue(@issue)
) do |format| ) do |format|
format.html format.html
end end
@ -59,11 +59,11 @@ class UserMailer < ActionMailer::Base
subject = "[№ #{build_list.id}] " subject = "[№ #{build_list.id}] "
subject << (build_list.project ? build_list.project.name_with_owner : t("layout.projects.unexisted_project")) subject << (build_list.project ? build_list.project.name_with_owner : t("layout.projects.unexisted_project"))
subject << " - #{build_list.human_status} " subject << " - #{build_list.human_status} "
subject << I18n.t("notifications.subjects.for_arch", :arch => @build_list.arch.name) subject << I18n.t("notifications.subjects.for_arch", arch: @build_list.arch.name)
mail( mail(
:to => email_with_name(user, user.email), to: email_with_name(user, user.email),
:subject => subject, subject: subject,
:from => email_with_name(build_list.publisher || build_list.user) from: email_with_name(build_list.publisher || build_list.user)
) do |format| ) do |format|
format.html format.html
end end
@ -73,8 +73,8 @@ class UserMailer < ActionMailer::Base
set_locale register_request set_locale register_request
@register_request = register_request @register_request = register_request
mail( mail(
:to => register_request.email, to: register_request.email,
:subject => I18n.t("notifications.subjects.invite_approve_notification") subject: I18n.t("notifications.subjects.invite_approve_notification")
) do |format| ) do |format|
format.html format.html
end end
@ -83,20 +83,20 @@ class UserMailer < ActionMailer::Base
def git_delete_branch_notification(user, options) def git_delete_branch_notification(user, options)
set_locale user set_locale user
mail( mail(
:to => user.email, to: user.email,
:subject => I18n.t('notifications.subjects.update_code', :project_name => "#{options[:project_owner]}/#{options[:project_name]}") subject: I18n.t('notifications.subjects.update_code', project_name: "#{options[:project_owner]}/#{options[:project_name]}")
) do |format| ) do |format|
format.html { render 'git_delete_branch_notification', :locals => options } format.html { render 'git_delete_branch_notification', locals: options }
end end
end end
def git_new_push_notification(user, options) def git_new_push_notification(user, options)
set_locale user set_locale user
mail( mail(
:to => user.email, to: user.email,
:subject => I18n.t('notifications.subjects.update_code', :project_name => "#{options[:project_owner]}/#{options[:project_name]}") subject: I18n.t('notifications.subjects.update_code', project_name: "#{options[:project_owner]}/#{options[:project_name]}")
) do |format| ) do |format|
format.html { render 'git_new_push_notification', :locals => options } format.html { render 'git_new_push_notification', locals: options }
end end
end end

View File

@ -12,21 +12,21 @@ class Ability
@user = user @user = user
# Shared rights between guests and registered users # Shared rights between guests and registered users
can [:show, :archive], Project, :visibility => 'open' can [:show, :archive], Project, visibility: 'open'
can :get_id, Project, :visibility => 'open' # api can :get_id, Project, visibility: 'open' # api
can(:refs_list, Project) {|project| can? :show, project} can(:refs_list, Project) {|project| can? :show, project}
can :read, Issue, :project => {:visibility => 'open'} can :read, Issue, project: {visibility: 'open'}
can [:read, :commits, :files], PullRequest, :to_project => {:visibility => 'open'} can [:read, :commits, :files], PullRequest, to_project: {visibility: 'open'}
can [:read, :log, :everything], BuildList, :project => {:visibility => 'open'} can [:read, :log, :everything], BuildList, project: {visibility: 'open'}
can [:read, :log], ProductBuildList#, :product => {:platform => {:visibility => 'open'}} # double nested hash don't work can [:read, :log], ProductBuildList#, product: {platform: {visibility: 'open'}} # double nested hash don't work
can [:read, :search], Advisory can [:read, :search], Advisory
# Platforms block # Platforms block
can [:show, :members, :advisories], Platform, :visibility => 'open' can [:show, :members, :advisories], Platform, visibility: 'open'
can :platforms_for_build, Platform, :visibility => 'open', :platform_type => 'main' can :platforms_for_build, Platform, visibility: 'open', platform_type: 'main'
can([:read, :get_list], MassBuild) {|mass_build| can?(:show, mass_build.save_to_platform) } can([:read, :get_list], MassBuild) {|mass_build| can?(:show, mass_build.save_to_platform) }
can [:read, :projects_list, :projects], Repository, :platform => {:visibility => 'open'} can [:read, :projects_list, :projects], Repository, platform: {visibility: 'open'}
can :read, Product, :platform => {:visibility => 'open'} can :read, Product, platform: {visibility: 'open'}
can :show, Group can :show, Group
can :show, User can :show, User
@ -38,32 +38,32 @@ class Ability
if user.admin? if user.admin?
can :manage, :all can :manage, :all
# Protection # Protection
cannot :approve, RegisterRequest, :approved => true cannot :approve, RegisterRequest, approved: true
cannot :reject, RegisterRequest, :rejected => true cannot :reject, RegisterRequest, rejected: true
cannot [:destroy, :create], Subscribe cannot [:destroy, :create], Subscribe
# Act admin as simple user # Act admin as simple user
cannot :read, Product, :platform => {:platform_type => 'personal'} cannot :read, Product, platform: {platform_type: 'personal'}
cannot [:owned, :related], [BuildList, Platform] cannot [:owned, :related], [BuildList, Platform]
cannot :membered, Project # list products which user members cannot :membered, Project # list products which user members
end end
if user.user? if user.user?
can :edit, User, :id => user.id can :edit, User, id: user.id
can [:read, :create], Group can [:read, :create], Group
can [:update, :manage_members, :members, :add_member, :remove_member, :update_member], Group do |group| can [:update, :manage_members, :members, :add_member, :remove_member, :update_member], Group do |group|
group.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin') # or group.owner_id = user.id group.actors.exists?(actor_type: 'User', actor_id: user.id, role: 'admin') # or group.owner_id = user.id
end end
can :write, Group do |group| can :write, Group do |group|
group.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => ['writer', 'admin']) group.actors.exists?(actor_type: 'User', actor_id: user.id, role: ['writer', 'admin'])
end end
can :destroy, Group, :owner_id => user.id can :destroy, Group, owner_id: user.id
can :remove_user, Group can :remove_user, Group
can :create, Project can :create, Project
can([:mass_import, :run_mass_import], Project) if user.platforms.main.find{ |p| local_admin?(p) }.present? can([:mass_import, :run_mass_import], Project) if user.platforms.main.find{ |p| local_admin?(p) }.present?
can :read, Project, :visibility => 'open' can :read, Project, visibility: 'open'
can [:read, :archive, :membered, :get_id], Project, :owner_type => 'User', :owner_id => user.id can [:read, :archive, :membered, :get_id], Project, owner_type: 'User', owner_id: user.id
can [:read, :archive, :membered, :get_id], Project, :owner_type => 'Group', :owner_id => user_group_ids can [:read, :archive, :membered, :get_id], Project, owner_type: 'Group', owner_id: user_group_ids
can([:read, :archive, :membered, :get_id], Project, read_relations_for('projects')) {|project| local_reader? project} can([:read, :archive, :membered, :get_id], Project, read_relations_for('projects')) {|project| local_reader? project}
can(:write, Project) {|project| local_writer? project} # for grack can(:write, Project) {|project| local_writer? project} # for grack
can [:update, :sections, :manage_collaborators, :autocomplete_maintainers, :add_member, :remove_member, :update_member, :members], Project do |project| can [:update, :sections, :manage_collaborators, :autocomplete_maintainers, :add_member, :remove_member, :update_member, :members], Project do |project|
@ -72,15 +72,15 @@ class Ability
can(:fork, Project) {|project| can? :read, project} can(:fork, Project) {|project| can? :read, project}
can(:fork, Project) {|project| project.owner_type == 'Group' and can? :update, project.owner} can(:fork, Project) {|project| project.owner_type == 'Group' and can? :update, project.owner}
can(:destroy, Project) {|project| owner? project} can(:destroy, Project) {|project| owner? project}
can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.actors.exists?(:actor_type => 'User', :actor_id => user.id, :role => 'admin')} can(:destroy, Project) {|project| project.owner_type == 'Group' and project.owner.actors.exists?(actor_type: 'User', actor_id: user.id, role: 'admin')}
can :remove_user, Project can :remove_user, Project
can :preview, Project can :preview, Project
can([:read, :create, :edit, :destroy, :update], Hook) {|hook| can?(:edit, hook.project)} can([:read, :create, :edit, :destroy, :update], Hook) {|hook| can?(:edit, hook.project)}
can [:read, :log, :owned, :everything], BuildList, :user_id => user.id can [:read, :log, :owned, :everything], BuildList, user_id: user.id
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'User', :owner_id => user.id} can [:read, :log, :related, :everything], BuildList, project: {owner_type: 'User', owner_id: user.id}
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user_group_ids} can [:read, :log, :related, :everything], BuildList, project: {owner_type: 'Group', owner_id: user_group_ids}
can([:read, :log, :everything, :list], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project} can([:read, :log, :everything, :list], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
can(:publish_into_testing, BuildList) { |build_list| can?(:create, build_list) && build_list.save_to_platform.main? } can(:publish_into_testing, BuildList) { |build_list| can?(:create, build_list) && build_list.save_to_platform.main? }
@ -92,7 +92,7 @@ class Ability
can(:publish, BuildList) do |build_list| can(:publish, BuildList) do |build_list|
if build_list.build_published? if build_list.build_published?
local_admin?(build_list.save_to_platform) || build_list.save_to_repository.members.exists?(:id => user.id) local_admin?(build_list.save_to_platform) || build_list.save_to_repository.members.exists?(id: user.id)
else else
build_list.save_to_repository.publish_without_qa ? build_list.save_to_repository.publish_without_qa ?
can?(:write, build_list.project) : local_admin?(build_list.save_to_platform) can?(:write, build_list.project) : local_admin?(build_list.save_to_platform)
@ -107,23 +107,23 @@ class Ability
end end
can([:cancel, :create_container], BuildList) {|build_list| can?(:write, build_list.project)} can([:cancel, :create_container], BuildList) {|build_list| can?(:write, build_list.project)}
can [:read, :owned, :related, :members], Platform, :owner_type => 'User', :owner_id => user.id can [:read, :owned, :related, :members], Platform, owner_type: 'User', owner_id: user.id
can [:read, :related, :members], Platform, :owner_type => 'Group', :owner_id => user_group_ids can [:read, :related, :members], Platform, owner_type: 'Group', owner_id: user_group_ids
can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform} can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform}
can [:read, :related], Platform, :id => user.repositories.pluck(:platform_id) can [:read, :related], Platform, id: user.repositories.pluck(:platform_id)
can([:update, :destroy, :change_visibility], Platform) {|platform| owner?(platform) } can([:update, :destroy, :change_visibility], Platform) {|platform| owner?(platform) }
can([:local_admin_manage, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) } can([:local_admin_manage, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) }
can([:create, :publish], MassBuild) {|mass_build| owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)} can([:create, :publish], MassBuild) {|mass_build| owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)}
can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)) && !mass_build.stop_build} can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.save_to_platform) || local_admin?(mass_build.save_to_platform)) && !mass_build.stop_build}
can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :projects_list, :projects], Repository, platform: {owner_type: 'User', owner_id: user.id}
can [:read, :projects_list, :projects], Repository, :platform => {:owner_type => 'Group', :owner_id => user_group_ids} can [:read, :projects_list, :projects], Repository, platform: {owner_type: 'Group', owner_id: user_group_ids}
can([:read, :projects_list, :projects], Repository, read_relations_for('repositories')) {|repository| can? :show, repository.platform} can([:read, :projects_list, :projects], Repository, read_relations_for('repositories')) {|repository| can? :show, repository.platform}
can([:read, :projects_list, :projects], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform} can([:read, :projects_list, :projects], Repository, read_relations_for('repositories', 'platforms')) {|repository| local_reader? repository.platform}
can([:create, :edit, :update, :destroy, :projects_list, :projects, :add_project, :remove_project, :regenerate_metadata, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository) {|repository| local_admin? repository.platform} can([:create, :edit, :update, :destroy, :projects_list, :projects, :add_project, :remove_project, :regenerate_metadata, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository) {|repository| local_admin? repository.platform}
can([:remove_members, :remove_member, :add_member, :signatures, :packages], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)} can([:remove_members, :remove_member, :add_member, :signatures, :packages], Repository) {|repository| owner?(repository.platform) || local_admin?(repository.platform)}
can([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(:id => user.id)} can([:add_project, :remove_project], Repository) {|repository| repository.members.exists?(id: user.id)}
can(:clear, Platform) {|platform| owner?(platform) && platform.personal?} can(:clear, Platform) {|platform| owner?(platform) && platform.personal?}
can(:regenerate_metadata, Platform) {|platform| owner?(platform) || local_admin?(platform)} can(:regenerate_metadata, Platform) {|platform| owner?(platform) || local_admin?(platform)}
can([:settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform} can([:settings, :destroy, :edit, :update], Repository) {|repository| owner? repository.platform}
@ -132,26 +132,26 @@ class Ability
can([:read, :create, :withdraw], Token) {|token| local_admin?(token.subject)} can([:read, :create, :withdraw], Token) {|token| local_admin?(token.subject)}
can :read, Product, :platform => {:owner_type => 'User', :owner_id => user.id, :platform_type => 'main'} can :read, Product, platform: {owner_type: 'User', owner_id: user.id, platform_type: 'main'}
can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user_group_ids, :platform_type => 'main'} can :read, Product, platform: {owner_type: 'Group', owner_id: user_group_ids, platform_type: 'main'}
can(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.main?} can(:read, Product, read_relations_for('products', 'platforms')) {|product| product.platform.main?}
can([:create, :update, :destroy, :clone], Product) {|product| local_admin? product.platform and product.platform.main?} can([:create, :update, :destroy, :clone], Product) {|product| local_admin? product.platform and product.platform.main?}
can([:create, :cancel, :update], ProductBuildList) {|pbl| can?(:update, pbl.product)} can([:create, :cancel, :update], ProductBuildList) {|pbl| can?(:update, pbl.product)}
can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)} can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)}
can [:read, :create], PrivateUser, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :create], PrivateUser, platform: {owner_type: 'User', owner_id: user.id}
can [:read, :create], PrivateUser, :platform => {:owner_type => 'Group', :owner_id => user_group_ids} can [:read, :create], PrivateUser, platform: {owner_type: 'Group', owner_id: user_group_ids}
can :read, Issue, :project => {:owner_type => 'User', :owner_id => user.id} can :read, Issue, project: {owner_type: 'User', owner_id: user.id}
can :read, Issue, :project => {:owner_type => 'Group', :owner_id => user_group_ids} can :read, Issue, project: {owner_type: 'Group', owner_id: user_group_ids}
can(:read, Issue, read_relations_for('issues', 'projects')) {|issue| can? :read, issue.project rescue nil} can(:read, Issue, read_relations_for('issues', 'projects')) {|issue| can? :read, issue.project rescue nil}
can(:create, Issue) {|issue| can? :read, issue.project} can(:create, Issue) {|issue| can? :read, issue.project}
can(:update, Issue) {|issue| issue.user_id == user.id or local_admin?(issue.project)} can(:update, Issue) {|issue| issue.user_id == user.id or local_admin?(issue.project)}
cannot :manage, Issue, :project => {:has_issues => false} # switch off issues cannot :manage, Issue, project: {has_issues: false} # switch off issues
can [:read, :commits, :files], PullRequest, :to_project => {:owner_type => 'User', :owner_id => user.id} can [:read, :commits, :files], PullRequest, to_project: {owner_type: 'User', owner_id: user.id}
can [:read, :commits, :files], PullRequest, :to_project => {:owner_type => 'Group', :owner_id => user_group_ids} can [:read, :commits, :files], PullRequest, to_project: {owner_type: 'Group', owner_id: user_group_ids}
can([:read, :commits, :files], PullRequest, read_relations_for('pull_requests', 'to_projects')) {|pull| can? :read, pull.to_project} can([:read, :commits, :files], PullRequest, read_relations_for('pull_requests', 'to_projects')) {|pull| can? :read, pull.to_project}
can :create, PullRequest can :create, PullRequest
can(:update, PullRequest) {|pull| pull.user_id == user.id or local_admin?(pull.to_project)} can(:update, PullRequest) {|pull| pull.user_id == user.id or local_admin?(pull.to_project)}
@ -165,24 +165,24 @@ class Ability
end end
# Shared cannot rights for all users (registered, admin) # Shared cannot rights for all users (registered, admin)
cannot [:regenerate_metadata, :destroy], Platform, :platform_type => 'personal' cannot [:regenerate_metadata, :destroy], Platform, platform_type: 'personal'
cannot [:create, :destroy], Repository, :platform => {:platform_type => 'personal'}, :name => 'main' cannot [:create, :destroy], Repository, platform: {platform_type: 'personal'}, name: 'main'
cannot [:packages], Repository, :platform => {:platform_type => 'personal'} cannot [:packages], Repository, platform: {platform_type: 'personal'}
cannot [:remove_members, :remove_member, :add_member, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository, :platform => {:platform_type => 'personal'} cannot [:remove_members, :remove_member, :add_member, :sync_lock_file, :add_repo_lock_file, :remove_repo_lock_file], Repository, platform: {platform_type: 'personal'}
cannot :clear, Platform, :platform_type => 'main' cannot :clear, Platform, platform_type: 'main'
cannot :destroy, Issue cannot :destroy, Issue
cannot [:members, :add_member, :remove_member, :remove_members], Platform, :platform_type => 'personal' cannot [:members, :add_member, :remove_member, :remove_members], Platform, platform_type: 'personal'
cannot [:create, :update, :destroy, :clone], Product, :platform => {:platform_type => 'personal'} cannot [:create, :update, :destroy, :clone], Product, platform: {platform_type: 'personal'}
cannot [:clone], Platform, :platform_type => 'personal' cannot [:clone], Platform, platform_type: 'personal'
cannot [:publish, :publish_into_testing], BuildList, :new_core => false cannot [:publish, :publish_into_testing], BuildList, new_core: false
cannot :create_container, BuildList, :new_core => false cannot :create_container, BuildList, new_core: false
cannot(:publish, BuildList) {|build_list| !build_list.can_publish? } cannot(:publish, BuildList) {|build_list| !build_list.can_publish? }
cannot(:publish_into_testing, BuildList) {|build_list| !build_list.can_publish_into_testing? } cannot(:publish_into_testing, BuildList) {|build_list| !build_list.can_publish_into_testing? }
cannot :publish_into_testing, BuildList, :save_to_platform => {:platform_type => 'personal'} cannot :publish_into_testing, BuildList, save_to_platform: {platform_type: 'personal'}
cannot(:cancel, MassBuild) {|mass_build| mass_build.stop_build} cannot(:cancel, MassBuild) {|mass_build| mass_build.stop_build}
@ -193,10 +193,10 @@ class Ability
end end
can :create, Subscribe do |subscribe| can :create, Subscribe do |subscribe|
!subscribe.subscribeable.subscribes.exists?(:user_id => user.id) !subscribe.subscribeable.subscribes.exists?(user_id: user.id)
end end
can :destroy, Subscribe do |subscribe| can :destroy, Subscribe do |subscribe|
subscribe.subscribeable.subscribes.exists?(:user_id => user.id) && user.id == subscribe.user_id subscribe.subscribeable.subscribes.exists?(user_id: user.id) && user.id == subscribe.user_id
end end
end end
end end
@ -205,29 +205,6 @@ class Ability
key = parent ? "#{parent.singularize}_id" : 'id' key = parent ? "#{parent.singularize}_id" : 'id'
parent ||= table parent ||= table
# Removes duplicates from subquery
#
# ["#{table}.#{key} IN
# (
# SELECT target_id FROM relations
# INNER JOIN #{parent} ON relations.target_type = :target_type AND relations.target_id = #{parent}.id
# WHERE relations.target_type = :target_type AND
# (
# #{parent}.owner_type = 'User' AND #{parent}.owner_id != :user OR
# #{parent}.owner_type = 'Group' AND #{parent}.owner_id NOT IN (:groups)
# ) AND (
# relations.actor_type = 'User' AND relations.actor_id = :user OR
# relations.actor_type = 'Group' AND relations.actor_id IN (:groups)
# )
# )",
# {
# :target_type => parent.classify,
# :user => @user.id,
# :groups => @user.group_ids
# }
# ]
["#{table}.#{key} IN ( ["#{table}.#{key} IN (
SELECT target_id FROM relations WHERE relations.target_type = ? AND SELECT target_id FROM relations WHERE relations.target_type = ? AND
(relations.actor_type = 'User' AND relations.actor_id = ? OR (relations.actor_type = 'User' AND relations.actor_id = ? OR
@ -257,5 +234,4 @@ class Ability
def user_group_ids def user_group_ids
@user_group_ids ||= @user.group_ids @user_group_ids ||= @user.group_ids
end end
end end

View File

@ -3,18 +3,18 @@ class Advisory < ActiveRecord::Base
has_and_belongs_to_many :projects has_and_belongs_to_many :projects
has_many :build_lists has_many :build_lists
validates :description, :update_type, :presence => true validates :description, :update_type, presence: true
validates :update_type, :inclusion => BuildList::RELEASE_UPDATE_TYPES validates :update_type, inclusion: BuildList::RELEASE_UPDATE_TYPES
after_create :generate_advisory_id after_create :generate_advisory_id
before_save :normalize_references, :if => :references_changed? before_save :normalize_references, if: :references_changed?
ID_TEMPLATE = 'ROSA-%<type>s-%<year>d:%<id>04d' ID_TEMPLATE = 'ROSA-%<type>s-%<year>d:%<id>04d'
ID_STRING_TEMPLATE = 'ROSA-%<type>s-%<year>04s:%<id>04s' ID_STRING_TEMPLATE = 'ROSA-%<type>s-%<year>04s:%<id>04s'
TYPES = {'security' => 'SA', 'bugfix' => 'A'} TYPES = {'security' => 'SA', 'bugfix' => 'A'}
scope :search_by_id, lambda { |aid| where("#{table_name}.advisory_id ILIKE ?", "%#{aid.to_s.strip}%") } scope :search_by_id, lambda { |aid| where("#{table_name}.advisory_id ILIKE ?", "%#{aid.to_s.strip}%") }
scope :by_update_type, lambda { |ut| where(:update_type => ut) } scope :by_update_type, lambda { |ut| where(update_type: ut) }
default_scope order("#{table_name}.created_at DESC") default_scope order("#{table_name}.created_at DESC")
def to_param def to_param
@ -32,15 +32,15 @@ class Advisory < ActiveRecord::Base
# this method fetches and structurize packages attached to current advisory. # this method fetches and structurize packages attached to current advisory.
def fetch_packages_info def fetch_packages_info
packages_info = Hash.new { |h, k| h[k] = {} } # maaagic, it's maaagic ;) packages_info = Hash.new { |h, k| h[k] = {} } # maaagic, it's maaagic ;)
build_lists.find_in_batches(:include => [:save_to_platform, :packages, :project]) do |batch| build_lists.find_in_batches(include: [:save_to_platform, :packages, :project]) do |batch|
batch.each do |build_list| batch.each do |build_list|
tmp = build_list.packages.inject({:srpm => nil, :rpm => []}) do |h, p| tmp = build_list.packages.inject({srpm: nil, rpm: []}) do |h, p|
p.package_type == 'binary' ? h[:rpm] << p.fullname : h[:srpm] = p.fullname p.package_type == 'binary' ? h[:rpm] << p.fullname : h[:srpm] = p.fullname
h h
end end
h = { build_list.project => tmp } h = { build_list.project => tmp }
packages_info[build_list.save_to_platform].merge!(h) do |pr, old, new| packages_info[build_list.save_to_platform].merge!(h) do |pr, old, new|
{:srpm => new[:srpm], :rpm => old[:rpm].concat(new[:rpm]).uniq} {srpm: new[:srpm], rpm: old[:rpm].concat(new[:rpm]).uniq}
end end
end end
end end
@ -50,7 +50,7 @@ class Advisory < ActiveRecord::Base
protected protected
def generate_advisory_id def generate_advisory_id
self.advisory_id = sprintf(ID_TEMPLATE, :type => TYPES[self.update_type], :year => Time.now.utc.year, :id => self.id) self.advisory_id = sprintf(ID_TEMPLATE, type: TYPES[self.update_type], year: Time.now.utc.year, id: self.id)
self.save self.save
end end

View File

@ -1,9 +1,9 @@
class Arch < ActiveRecord::Base class Arch < ActiveRecord::Base
DEFAULT = %w[i586 x86_64] DEFAULT = %w[i586 x86_64]
has_many :build_lists, :dependent => :destroy has_many :build_lists, dependent: :destroy
validates :name, :presence => true, :uniqueness => true validates :name, presence: true, uniqueness: true
scope :recent, order("#{table_name}.name ASC") scope :recent, order("#{table_name}.name ASC")
end end

View File

@ -1,6 +1,6 @@
class Authentication < ActiveRecord::Base class Authentication < ActiveRecord::Base
belongs_to :user belongs_to :user
validates :provider, :uid, :user_id, :presence => true validates :provider, :uid, :user_id, presence: true
validates :uid, :uniqueness => {:scope => :provider, :case_sensitive => false} validates :uid, uniqueness: {scope: :provider, case_sensitive: false}
end end

View File

@ -2,15 +2,15 @@ class Avatar < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
MAX_AVATAR_SIZE = 5.megabyte MAX_AVATAR_SIZE = 5.megabyte
AVATAR_SIZES = {:micro => 16, :small => 30, :medium => 40, :big => 81} AVATAR_SIZES = {micro: 16, small: 30, medium: 40, big: 81}
AVATAR_SIZES_HASH = {}.tap do |styles| AVATAR_SIZES_HASH = {}.tap do |styles|
AVATAR_SIZES.each do |name, size| AVATAR_SIZES.each do |name, size|
styles[name] = { :geometry => "#{size}x#{size}#", :format => :jpg, :convert_options => '-strip -background white -flatten -quality 70'} styles[name] = { geometry: "#{size}x#{size}#", format: :jpg, convert_options: '-strip -background white -flatten -quality 70'}
end end
end end
has_attached_file :avatar, :styles => AVATAR_SIZES_HASH has_attached_file :avatar, styles: AVATAR_SIZES_HASH
validates_inclusion_of :avatar_file_size, :in => (0..MAX_AVATAR_SIZE), :allow_nil => true validates_inclusion_of :avatar_file_size, in: (0..MAX_AVATAR_SIZE), allow_nil: true
attr_accessible :avatar attr_accessible :avatar

View File

@ -6,17 +6,17 @@ class BuildList < ActiveRecord::Base
belongs_to :project belongs_to :project
belongs_to :arch belongs_to :arch
belongs_to :save_to_platform, :class_name => 'Platform' belongs_to :save_to_platform, class_name: 'Platform'
belongs_to :save_to_repository, :class_name => 'Repository' belongs_to :save_to_repository, class_name: 'Repository'
belongs_to :build_for_platform, :class_name => 'Platform' belongs_to :build_for_platform, class_name: 'Platform'
belongs_to :user belongs_to :user
belongs_to :builder, :class_name => 'User' belongs_to :builder, class_name: 'User'
belongs_to :publisher, :class_name => 'User' belongs_to :publisher, class_name: 'User'
belongs_to :advisory belongs_to :advisory
belongs_to :mass_build, :counter_cache => true belongs_to :mass_build, counter_cache: true
has_many :items, :class_name => '::BuildList::Item', :dependent => :destroy has_many :items, class_name: '::BuildList::Item', dependent: :destroy
has_many :packages, :class_name => '::BuildList::Package', :dependent => :destroy has_many :packages, class_name: '::BuildList::Package', dependent: :destroy
has_many :source_packages, :class_name => '::BuildList::Package', :conditions => {:package_type => 'source'} has_many :source_packages, class_name: '::BuildList::Package', conditions: {package_type: 'source'}
UPDATE_TYPES = %w[bugfix security enhancement recommended newpackage] UPDATE_TYPES = %w[bugfix security enhancement recommended newpackage]
RELEASE_UPDATE_TYPES = %w[bugfix security] RELEASE_UPDATE_TYPES = %w[bugfix security]
@ -24,13 +24,13 @@ class BuildList < ActiveRecord::Base
EXTERNAL_NODES = %w[owned everything] EXTERNAL_NODES = %w[owned everything]
validates :project_id, :project_version, :arch, :include_repos, validates :project_id, :project_version, :arch, :include_repos,
:build_for_platform_id, :save_to_platform_id, :save_to_repository_id, :presence => true :build_for_platform_id, :save_to_platform_id, :save_to_repository_id, presence: true
validates_numericality_of :priority, :greater_than_or_equal_to => 0 validates_numericality_of :priority, greater_than_or_equal_to: 0
validates :external_nodes, :inclusion => {:in => EXTERNAL_NODES}, :allow_blank => true validates :external_nodes, inclusion: {in: EXTERNAL_NODES}, allow_blank: true
validates :update_type, :inclusion => UPDATE_TYPES, validates :update_type, inclusion: UPDATE_TYPES,
:unless => Proc.new { |b| b.advisory.present? } unless: Proc.new { |b| b.advisory.present? }
validates :update_type, :inclusion => {:in => RELEASE_UPDATE_TYPES, :message => I18n.t('flash.build_list.frozen_platform')}, validates :update_type, inclusion: {in: RELEASE_UPDATE_TYPES, message: I18n.t('flash.build_list.frozen_platform')},
:if => Proc.new { |b| b.advisory.present? } if: Proc.new { |b| b.advisory.present? }
validate lambda { validate lambda {
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.main? && save_to_platform_id != build_for_platform_id errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_platform')) if save_to_platform.main? && save_to_platform_id != build_for_platform_id
} }
@ -41,17 +41,17 @@ class BuildList < ActiveRecord::Base
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_repository')) if save_to_repository.platform_id != save_to_platform.id errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_repository')) if save_to_repository.platform_id != save_to_platform.id
} }
validate lambda { validate lambda {
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_include_repos')) if build_for_platform.repositories.where(:id => include_repos).count != include_repos.size errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_include_repos')) if build_for_platform.repositories.where(id: include_repos).count != include_repos.size
} }
validate lambda { validate lambda {
errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_project')) unless save_to_repository.projects.exists?(project_id) errors.add(:save_to_repository, I18n.t('flash.build_list.wrong_project')) unless save_to_repository.projects.exists?(project_id)
} }
before_validation lambda { self.include_repos = include_repos.uniq if include_repos.present? }, :on => :create before_validation lambda { self.include_repos = include_repos.uniq if include_repos.present? }, on: :create
before_validation :prepare_extra_repositories, :on => :create before_validation :prepare_extra_repositories, on: :create
before_validation :prepare_extra_build_lists, :on => :create before_validation :prepare_extra_build_lists, on: :create
before_validation :prepare_extra_params, :on => :create before_validation :prepare_extra_params, on: :create
before_validation lambda { self.auto_publish = false if external_nodes.present?; true }, :on => :create before_validation lambda { self.auto_publish = false if external_nodes.present?; true }, on: :create
before_validation lambda { self.auto_create_container = false if auto_publish?; true }, :on => :create before_validation lambda { self.auto_create_container = false if auto_publish?; true }, on: :create
attr_accessible :include_repos, :auto_publish, :build_for_platform_id, :commit_hash, attr_accessible :include_repos, :auto_publish, :build_for_platform_id, :commit_hash,
:arch_id, :project_id, :save_to_repository_id, :update_type, :arch_id, :project_id, :save_to_repository_id, :update_type,
@ -93,21 +93,21 @@ class BuildList < ActiveRecord::Base
scope :recent, order("#{table_name}.updated_at DESC") scope :recent, order("#{table_name}.updated_at DESC")
scope :for_extra_build_lists, lambda {|ids, current_ability, save_to_platform| scope :for_extra_build_lists, lambda {|ids, current_ability, save_to_platform|
s = scoped s = scoped
s = s.where(:id => ids).published_container.accessible_by(current_ability, :read) s = s.where(id: ids).published_container.accessible_by(current_ability, :read)
s = s.where(:save_to_platform_id => save_to_platform.id) if save_to_platform && save_to_platform.main? s = s.where(save_to_platform_id: save_to_platform.id) if save_to_platform && save_to_platform.main?
s s
} }
scope :for_status, lambda {|status| where(:status => status) if status.present? } scope :for_status, lambda {|status| where(status: status) if status.present? }
scope :for_user, lambda { |user| where(:user_id => user.id) } scope :for_user, lambda { |user| where(user_id: user.id) }
scope :not_owned_external_nodes, where("#{table_name}.external_nodes is null OR #{table_name}.external_nodes != ?", :owned) scope :not_owned_external_nodes, where("#{table_name}.external_nodes is null OR #{table_name}.external_nodes != ?", :owned)
scope :external_nodes, lambda { |type| where("#{table_name}.external_nodes = ?", type) } scope :external_nodes, lambda { |type| where("#{table_name}.external_nodes = ?", type) }
scope :oldest, lambda { where("#{table_name}.updated_at < ?", Time.zone.now - 15.seconds) } scope :oldest, lambda { where("#{table_name}.updated_at < ?", Time.zone.now - 15.seconds) }
scope :for_platform, lambda { |platform| where(:build_for_platform_id => platform) } scope :for_platform, lambda { |platform| where(build_for_platform_id: platform) }
scope :by_mass_build, lambda { |mass_build| where(:mass_build_id => mass_build) } scope :by_mass_build, lambda { |mass_build| where(mass_build_id: mass_build) }
scope :scoped_to_arch, lambda {|arch| where(:arch_id => arch) if arch.present? } scope :scoped_to_arch, lambda {|arch| where(arch_id: arch) if arch.present? }
scope :scoped_to_save_platform, lambda {|pl_id| where(:save_to_platform_id => pl_id) if pl_id.present? } scope :scoped_to_save_platform, lambda {|pl_id| where(save_to_platform_id: pl_id) if pl_id.present? }
scope :scoped_to_project_version, lambda {|project_version| where(:project_version => project_version) if project_version.present? } scope :scoped_to_project_version, lambda {|project_version| where(project_version: project_version) if project_version.present? }
scope :scoped_to_is_circle, lambda {|is_circle| where(:is_circle => is_circle) } scope :scoped_to_is_circle, lambda {|is_circle| where(is_circle: is_circle) }
scope :for_creation_date_period, lambda{|start_date, end_date| scope :for_creation_date_period, lambda{|start_date, end_date|
s = scoped s = scoped
s = s.where(["#{table_name}.created_at >= ?", start_date]) if start_date s = s.where(["#{table_name}.created_at >= ?", start_date]) if start_date
@ -121,9 +121,9 @@ class BuildList < ActiveRecord::Base
s s
} }
scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%") if project_name.present? } scope :scoped_to_project_name, lambda {|project_name| joins(:project).where('projects.name LIKE ?', "%#{project_name}%") if project_name.present? }
scope :scoped_to_new_core, lambda {|new_core| where(:new_core => new_core)} scope :scoped_to_new_core, lambda {|new_core| where(new_core: new_core)}
scope :outdated, where("#{table_name}.created_at < ? AND #{table_name}.status NOT IN (?) OR #{table_name}.created_at < ?", Time.now - LIVE_TIME, [BUILD_PUBLISHED,BUILD_PUBLISHED_INTO_TESTING], Time.now - MAX_LIVE_TIME) scope :outdated, where("#{table_name}.created_at < ? AND #{table_name}.status NOT IN (?) OR #{table_name}.created_at < ?", Time.now - LIVE_TIME, [BUILD_PUBLISHED,BUILD_PUBLISHED_INTO_TESTING], Time.now - MAX_LIVE_TIME)
scope :published_container, where(:container_status => BUILD_PUBLISHED) scope :published_container, where(container_status: BUILD_PUBLISHED)
serialize :additional_repos serialize :additional_repos
serialize :include_repos serialize :include_repos
@ -132,10 +132,10 @@ class BuildList < ActiveRecord::Base
serialize :extra_build_lists, Array serialize :extra_build_lists, Array
serialize :extra_params, Hash serialize :extra_params, Hash
after_commit :place_build, :on => :create after_commit :place_build, on: :create
after_destroy :remove_container after_destroy :remove_container
state_machine :status, :initial => :waiting_for_response do state_machine :status, initial: :waiting_for_response do
# WTF? around_transition -> infinite loop # WTF? around_transition -> infinite loop
before_transition do |build_list, transition| before_transition do |build_list, transition|
@ -152,36 +152,36 @@ class BuildList < ActiveRecord::Base
end end
end end
after_transition :on => :place_build, :do => :add_job_to_abf_worker_queue, after_transition on: :place_build, do: :add_job_to_abf_worker_queue,
:if => lambda { |build_list| build_list.external_nodes.blank? } :if => lambda { |build_list| build_list.external_nodes.blank? }
after_transition :on => :published, after_transition on: :published,
:do => [:set_version_and_tag, :actualize_packages] do: [:set_version_and_tag, :actualize_packages]
after_transition :on => :publish, :do => :set_publisher after_transition on: :publish, do: :set_publisher
after_transition(:on => :publish) do |build_list, transition| after_transition(on: :publish) do |build_list, transition|
if transition.from == BUILD_PUBLISHED_INTO_TESTING if transition.from == BUILD_PUBLISHED_INTO_TESTING
build_list.cleanup_packages_from_testing build_list.cleanup_packages_from_testing
end end
end end
after_transition :on => :cancel, :do => :cancel_job after_transition on: :cancel, do: :cancel_job
after_transition :on => [:published, :fail_publish, :build_error, :tests_failed], :do => :notify_users after_transition on: [:published, :fail_publish, :build_error, :tests_failed], do: :notify_users
after_transition :on => :build_success, :do => :notify_users, after_transition on: :build_success, do: :notify_users,
:unless => lambda { |build_list| build_list.auto_publish? } unless: lambda { |build_list| build_list.auto_publish? }
event :place_build do event :place_build do
transition :waiting_for_response => :build_pending transition waiting_for_response: :build_pending
end end
event :start_build do event :start_build do
transition :build_pending => :build_started transition build_pending: :build_started
end end
event :cancel do event :cancel do
transition [:build_pending, :build_started] => :build_canceling transition [:build_pending, :build_started] => :build_canceling
end end
# :build_canceling => :build_canceled - canceling from UI # build_canceling: :build_canceled - canceling from UI
# :build_started => :build_canceled - canceling from worker by time-out (time_living has been expired) # build_started: :build_canceled - canceling from worker by time-out (time_living has been expired)
event :build_canceled do event :build_canceled do
transition [:build_canceling, :build_started] => :build_canceled transition [:build_canceling, :build_started] => :build_canceled
end end
@ -250,11 +250,11 @@ class BuildList < ActiveRecord::Base
end end
HUMAN_STATUSES.each do |code,name| HUMAN_STATUSES.each do |code,name|
state name, :value => code state name, value: code
end end
end end
later :publish, :queue => :clone_build later :publish, queue: :clone_build
HUMAN_CONTAINER_STATUSES = { WAITING_FOR_RESPONSE => :waiting_for_publish, HUMAN_CONTAINER_STATUSES = { WAITING_FOR_RESPONSE => :waiting_for_publish,
@ -263,23 +263,23 @@ class BuildList < ActiveRecord::Base
FAILED_PUBLISH => :container_failed_publish FAILED_PUBLISH => :container_failed_publish
}.freeze }.freeze
state_machine :container_status, :initial => :waiting_for_publish do state_machine :container_status, initial: :waiting_for_publish do
after_transition :on => :publish_container, :do => :create_container after_transition on: :publish_container, do: :create_container
after_transition :on => [:fail_publish_container, :destroy_container], after_transition on: [:fail_publish_container, :destroy_container],
:do => :remove_container do: :remove_container
event :publish_container do event :publish_container do
transition [:waiting_for_publish, :container_failed_publish] => :container_publish, transition [:waiting_for_publish, :container_failed_publish] => :container_publish,
:if => :can_create_container? if: :can_create_container?
end end
event :published_container do event :published_container do
transition :container_publish => :container_published transition container_publish: :container_published
end end
event :fail_publish_container do event :fail_publish_container do
transition :container_publish => :container_failed_publish transition container_publish: :container_failed_publish
end end
event :destroy_container do event :destroy_container do
@ -287,12 +287,12 @@ class BuildList < ActiveRecord::Base
end end
HUMAN_CONTAINER_STATUSES.each do |code,name| HUMAN_CONTAINER_STATUSES.each do |code,name|
state name, :value => code state name, value: code
end end
end end
def set_version_and_tag def set_version_and_tag
pkg = self.packages.where(:package_type => 'source', :project_id => self.project_id).first pkg = self.packages.where(package_type: 'source', project_id: self.project_id).first
# TODO: remove 'return' after deployment ABF kernel 2.0 # TODO: remove 'return' after deployment ABF kernel 2.0
return if pkg.nil? # For old client that does not sends data about packages return if pkg.nil? # For old client that does not sends data about packages
self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}" self.package_version = "#{pkg.platform.name}-#{pkg.version}-#{pkg.release}"
@ -303,8 +303,8 @@ class BuildList < ActiveRecord::Base
def actualize_packages def actualize_packages
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
# packages from previous build_list # packages from previous build_list
self.last_published.limit(2).last.packages.update_all :actual => false self.last_published.limit(2).last.packages.update_all actual: false
self.packages.update_all :actual => true self.packages.update_all actual: true
end end
end end
@ -316,11 +316,11 @@ class BuildList < ActiveRecord::Base
return true if !save_to_repository.synchronizing_publications? || save_to_platform.personal? || project.architecture_dependent? return true if !save_to_repository.synchronizing_publications? || save_to_platform.personal? || project.architecture_dependent?
arch_ids = save_to_platform.platform_arch_settings.by_default.pluck(:arch_id) arch_ids = save_to_platform.platform_arch_settings.by_default.pluck(:arch_id)
BuildList.where( BuildList.where(
:project_id => project_id, project_id: project_id,
:save_to_repository_id => save_to_repository_id, save_to_repository_id: save_to_repository_id,
:arch_id => arch_ids, arch_id: arch_ids,
:commit_hash => commit_hash, commit_hash: commit_hash,
:status => [ status: [
SUCCESS, SUCCESS,
BUILD_PUBLISHED, BUILD_PUBLISHED,
BUILD_PUBLISH, BUILD_PUBLISH,
@ -345,7 +345,7 @@ class BuildList < ActiveRecord::Base
# - true if version of packages is equal to version of pubished packages (only if platform is not released). # - true if version of packages is equal to version of pubished packages (only if platform is not released).
# - true if version of packages is greater than version of pubished packages. # - true if version of packages is greater than version of pubished packages.
def has_new_packages? def has_new_packages?
if last_bl = last_published.joins(:source_packages).where(:build_list_packages => {:actual => true}).last if last_bl = last_published.joins(:source_packages).where(build_list_packages: {actual: true}).last
source_packages.each do |nsp| source_packages.each do |nsp|
sp = last_bl.source_packages.find{ |sp| nsp.name == sp.name } sp = last_bl.source_packages.find{ |sp| nsp.name == sp.name }
return true unless sp return true unless sp
@ -363,17 +363,17 @@ class BuildList < ActiveRecord::Base
end end
def can_publish? def can_publish?
[SUCCESS, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED, BUILD_PUBLISHED_INTO_TESTING, FAILED_PUBLISH_INTO_TESTING].include?(status) && extra_build_lists_published? && save_to_repository.projects.exists?(:id => project_id) [SUCCESS, FAILED_PUBLISH, BUILD_PUBLISHED, TESTS_FAILED, BUILD_PUBLISHED_INTO_TESTING, FAILED_PUBLISH_INTO_TESTING].include?(status) && extra_build_lists_published? && save_to_repository.projects.exists?(id: project_id)
end end
def extra_build_lists_published? def extra_build_lists_published?
# All extra build lists should be published before publishing this build list for main platforms! # All extra build lists should be published before publishing this build list for main platforms!
return true unless save_to_platform.main? return true unless save_to_platform.main?
BuildList.where(:id => extra_build_lists).where('status != ?', BUILD_PUBLISHED).count == 0 BuildList.where(id: extra_build_lists).where('status != ?', BUILD_PUBLISHED).count == 0
end end
def human_average_build_time def human_average_build_time
I18n.t('layout.project_statistics.human_average_build_time', {:hours => (average_build_time/3600).to_i, :minutes => (average_build_time%3600/60).to_i}) I18n.t('layout.project_statistics.human_average_build_time', {hours: (average_build_time/3600).to_i, minutes: (average_build_time%3600/60).to_i})
end end
def formatted_average_build_time def formatted_average_build_time
@ -403,13 +403,13 @@ class BuildList < ActiveRecord::Base
items_hash.each do |level, items| items_hash.each do |level, items|
items.each do |item| items.each do |item|
self.items << self.items.build(:name => item['name'], :version => item['version'], :level => level.to_i) self.items << self.items.build(name: item['name'], version: item['version'], level: level.to_i)
end end
end end
end end
def set_packages(pkg_hash, project_name) def set_packages(pkg_hash, project_name)
prj = Project.joins(:repositories => :platform).where('platforms.id = ?', save_to_platform.id).find_by_name!(project_name) prj = Project.joins(repositories: :platform).where('platforms.id = ?', save_to_platform.id).find_by_name!(project_name)
build_package(pkg_hash['srpm'], 'source', prj) {|p| p.save!} build_package(pkg_hash['srpm'], 'source', prj) {|p| p.save!}
pkg_hash['rpm'].each do |rpm_hash| pkg_hash['rpm'].each do |rpm_hash|
build_package(rpm_hash, 'binary', prj) {|p| p.save!} build_package(rpm_hash, 'binary', prj) {|p| p.save!}
@ -417,7 +417,7 @@ class BuildList < ActiveRecord::Base
end end
def event_log_message def event_log_message
{:project => project.name, :version => project_version, :arch => arch.name}.inspect {project: project.name, version: project_version, arch: arch.name}.inspect
end end
def current_duration def current_duration
@ -425,11 +425,11 @@ class BuildList < ActiveRecord::Base
end end
def human_current_duration def human_current_duration
I18n.t("layout.build_lists.human_current_duration", {:hours => (current_duration/3600).to_i, :minutes => (current_duration%3600/60).to_i}) I18n.t("layout.build_lists.human_current_duration", {hours: (current_duration/3600).to_i, minutes: (current_duration%3600/60).to_i})
end end
def human_duration def human_duration
I18n.t("layout.build_lists.human_duration", {:hours => (duration.to_i/3600).to_i, :minutes => (duration.to_i%3600/60).to_i}) I18n.t("layout.build_lists.human_duration", {hours: (duration.to_i/3600).to_i, minutes: (duration.to_i%3600/60).to_i})
end end
def in_work? def in_work?
@ -454,8 +454,8 @@ class BuildList < ActiveRecord::Base
end end
def last_published(testing = false) def last_published(testing = false)
BuildList.where(:project_id => self.project_id, BuildList.where(project_id: self.project_id,
:save_to_repository_id => self.save_to_repository_id) save_to_repository_id: self.save_to_repository_id)
.for_platform(self.build_for_platform_id) .for_platform(self.build_for_platform_id)
.scoped_to_arch(self.arch_id) .scoped_to_arch(self.arch_id)
.for_status(testing ? BUILD_PUBLISHED_INTO_TESTING : BUILD_PUBLISHED) .for_status(testing ? BUILD_PUBLISHED_INTO_TESTING : BUILD_PUBLISHED)
@ -469,7 +469,7 @@ class BuildList < ActiveRecord::Base
def abf_worker_args def abf_worker_args
repos = include_repos repos = include_repos
include_repos_hash = {}.tap do |h| include_repos_hash = {}.tap do |h|
Repository.where(:id => (repos | (extra_repositories || [])) ).each do |repo| Repository.where(id: (repos | (extra_repositories || [])) ).each do |repo|
path, prefix = repo.platform.public_downloads_url( path, prefix = repo.platform.public_downloads_url(
repo.platform.main? ? nil : build_for_platform.name, repo.platform.main? ? nil : build_for_platform.name,
arch.name, arch.name,
@ -481,7 +481,7 @@ class BuildList < ActiveRecord::Base
end end
end end
host = EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host] host = EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host]
BuildList.where(:id => extra_build_lists).each do |bl| BuildList.where(id: extra_build_lists).each do |bl|
path = "#{APP_CONFIG['downloads_url']}/#{bl.save_to_platform.name}/container/" path = "#{APP_CONFIG['downloads_url']}/#{bl.save_to_platform.name}/container/"
path << "#{bl.id}/#{bl.arch.name}/#{bl.save_to_repository.name}/release" path << "#{bl.id}/#{bl.arch.name}/#{bl.save_to_repository.name}/release"
include_repos_hash["container_#{bl.id}"] = insert_token_to_path(path, bl.save_to_platform) include_repos_hash["container_#{bl.id}"] = insert_token_to_path(path, bl.save_to_platform)
@ -500,17 +500,17 @@ class BuildList < ActiveRecord::Base
}.map{ |k, v| "#{k}='#{v}'" }.join(' ') }.map{ |k, v| "#{k}='#{v}'" }.join(' ')
{ {
:id => id, id: id,
:time_living => (build_for_platform.platform_arch_settings.by_arch(arch).first.try(:time_living) || PlatformArchSetting::DEFAULT_TIME_LIVING), time_living: (build_for_platform.platform_arch_settings.by_arch(arch).first.try(:time_living) || PlatformArchSetting::DEFAULT_TIME_LIVING),
:distrib_type => build_for_platform.distrib_type, distrib_type: build_for_platform.distrib_type,
:cmd_params => cmd_params, cmd_params: cmd_params,
:include_repos => include_repos_hash, include_repos: include_repos_hash,
:platform => { platform: {
:type => build_for_platform.distrib_type, type: build_for_platform.distrib_type,
:name => build_for_platform.name, name: build_for_platform.name,
:arch => arch.name arch: arch.name
}, },
:user => {:uname => user.uname, :email => user.email} user: {uname: user.uname, email: user.email}
} }
end end
@ -583,7 +583,7 @@ class BuildList < ActiveRecord::Base
self.extra_repositories = nil self.extra_repositories = nil
else else
self.extra_repositories = Repository.joins(:platform). self.extra_repositories = Repository.joins(:platform).
where(:id => extra_repositories, :platforms => {:platform_type => 'personal'}). where(id: extra_repositories, platforms: {platform_type: 'personal'}).
accessible_by(current_ability, :read).pluck('repositories.id') accessible_by(current_ability, :read).pluck('repositories.id')
end end
end end
@ -597,7 +597,7 @@ class BuildList < ActiveRecord::Base
(projects.publish_i686_into_x86_64 is true) (projects.publish_i686_into_x86_64 is true)
', arch_id).joins(:project) ', arch_id).joins(:project)
else else
bls = bls.where(:arch_id => arch_id) bls = bls.where(arch_id: arch_id)
end end
end end
self.extra_build_lists = bls.pluck('build_lists.id') self.extra_build_lists = bls.pluck('build_lists.id')
@ -612,5 +612,4 @@ class BuildList < ActiveRecord::Base
self.extra_params = params.select{ |k,v| v.present? } self.extra_params = params.select{ |k,v| v.present? }
end end
end end
end
end

View File

@ -12,7 +12,7 @@ class BuildList::Filter
build_lists = @project ? @project.build_lists : BuildList.scoped build_lists = @project ? @project.build_lists : BuildList.scoped
if @options[:id] if @options[:id]
build_lists = build_lists.where(:id => @options[:id]) build_lists = build_lists.where(id: @options[:id])
else else
build_lists = build_lists.scoped_to_new_core(@options[:new_core] == '0' ? nil : true) if @options[:new_core].present? build_lists = build_lists.scoped_to_new_core(@options[:new_core] == '0' ? nil : true) if @options[:new_core].present?
build_lists = build_lists.by_mass_build(@options[:mass_build_id]) if @options[:mass_build_id] build_lists = build_lists.by_mass_build(@options[:mass_build_id]) if @options[:mass_build_id]
@ -42,18 +42,18 @@ class BuildList::Filter
def set_options(options) def set_options(options)
@options = HashWithIndifferentAccess.new(options.reverse_merge({ @options = HashWithIndifferentAccess.new(options.reverse_merge({
:ownership => nil, ownership: nil,
:status => nil, status: nil,
:updated_at_start => nil, updated_at_start: nil,
:updated_at_end => nil, updated_at_end: nil,
:arch_id => nil, arch_id: nil,
:platform_id => nil, platform_id: nil,
:is_circle => nil, is_circle: nil,
:project_version => nil, project_version: nil,
:id => nil, id: nil,
:project_name => nil, project_name: nil,
:mass_build_id => nil, mass_build_id: nil,
:new_core => nil new_core: nil
})) }))
@options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'everything' : 'owned') @options[:ownership] = @options[:ownership].presence || (@project || !@user ? 'everything' : 'owned')

View File

@ -1,20 +1,20 @@
class BuildList::Item < ActiveRecord::Base class BuildList::Item < ActiveRecord::Base
belongs_to :build_list, :touch => true belongs_to :build_list, touch: true
attr_protected :build_list_id attr_protected :build_list_id
GIT_ERROR = 5 GIT_ERROR = 5
STATUSES = [BuildList::SUCCESS, BuildList::BUILD_ERROR, BuildList::BUILD_STARTED, GIT_ERROR, BuildList::BUILD_CANCELED] # BuildList::DEPENDENCIES_ERROR STATUSES = [BuildList::SUCCESS, BuildList::BUILD_ERROR, BuildList::BUILD_STARTED, GIT_ERROR, BuildList::BUILD_CANCELED] # BuildList::DEPENDENCIES_ERROR
HUMAN_STATUSES = { HUMAN_STATUSES = {
nil => :unknown, nil => :unknown,
GIT_ERROR => :git_error, GIT_ERROR => :git_error,
# BuildList::DEPENDENCIES_ERROR => :dependencies_error, # BuildList:DEPENDENCIES_ERROR: :dependencies_error,
BuildList::SUCCESS => :success, BuildList:SUCCESS: :success,
BuildList::BUILD_STARTED => :build_started, BuildList:BUILD_STARTED: :build_started,
BuildList::BUILD_ERROR => :build_error, BuildList:BUILD_ERROR: :build_error,
BuildList::BUILD_CANCELED => :build_canceled BuildList:BUILD_CANCELED: :build_canceled
} }
scope :recent, order("#{table_name}.level ASC, #{table_name}.name ASC") scope :recent, order("#{table_name}.level ASC, #{table_name}.name ASC")
@ -40,5 +40,5 @@ class BuildList::Item < ActiveRecord::Base
def human_status def human_status
self.class.human_status(status) self.class.human_status(status)
end end
end end

View File

@ -9,17 +9,17 @@ class BuildList::Package < ActiveRecord::Base
validates :build_list_id, :project_id, :platform_id, :fullname, validates :build_list_id, :project_id, :platform_id, :fullname,
:package_type, :name, :release, :version, :package_type, :name, :release, :version,
:presence => true presence: true
validates :package_type, :inclusion => PACKAGE_TYPES validates :package_type, inclusion: PACKAGE_TYPES
validates :sha1, :presence => true, :if => Proc.new { |p| p.build_list.new_core? } validates :sha1, presence: true, if: Proc.new { |p| p.build_list.new_core? }
default_scope order("lower(#{table_name}.name) ASC, length(#{table_name}.name) ASC") default_scope order("lower(#{table_name}.name) ASC, length(#{table_name}.name) ASC")
# Fetches only actual (last publised) packages. # Fetches only actual (last publised) packages.
scope :actual, where(:actual => true) scope :actual, where(actual: true)
scope :by_platform, lambda {|platform| where(:platform_id => platform) } scope :by_platform, lambda {|platform| where(platform_id: platform) }
scope :by_name, lambda {|name| where(:name => name) } scope :by_name, lambda {|name| where(name: name) }
scope :by_package_type, lambda {|type| where(:package_type => type) } scope :by_package_type, lambda {|type| where(package_type: type) }
scope :like_name, lambda {|name| where("#{table_name}.name ILIKE ?", "%#{name}%") if name.present?} scope :like_name, lambda {|name| where("#{table_name}.name ILIKE ?", "%#{name}%") if name.present?}
before_create :set_epoch before_create :set_epoch

View File

@ -21,7 +21,7 @@ class BuildListObserver < ActiveRecord::Observer
end end
build_count = statistic.build_count build_count = statistic.build_count
new_av_time = ( statistic.average_build_time * build_count + record.duration ) / ( build_count + 1 ) new_av_time = ( statistic.average_build_time * build_count + record.duration ) / ( build_count + 1 )
statistic.update_attributes(:average_build_time => new_av_time, :build_count => build_count + 1) statistic.update_attributes(average_build_time: new_av_time, build_count: build_count + 1)
end end
end end
end end

View File

@ -10,7 +10,7 @@ class Collaborator
attr_accessible :role attr_accessible :role
delegate :new_record?, :to => :relation delegate :new_record?, to: :relation
class << self class << self
def find_by_project(project) def find_by_project(project)
@ -128,7 +128,7 @@ class Collaborator
def from_relation(relation) def from_relation(relation)
return nil unless relation.present? return nil unless relation.present?
return self.new(:relation => relation) return self.new(relation: relation)
end end
end end
@ -139,7 +139,7 @@ class Collaborator
if @actor.present? and @project.present? if @actor.present? and @project.present?
@relation = Relation.by_actor(@actor).by_target(@project).limit(1).first @relation = Relation.by_actor(@actor).by_target(@project).limit(1).first
@relation ||= Relation.new(:actor_id => @actor.id, :actor_type => @actor.class.to_s, @relation ||= Relation.new(:actor_id => @actor.id, :actor_type => @actor.class.to_s,
:target_id => @project.id, :target_type => 'Project') target_id: @project.id, target_type: 'Project')
else else
@relation = Relation.new @relation = Relation.new
@relation.actor = @actor @relation.actor = @actor

View File

@ -7,17 +7,17 @@ class Comment < ActiveRecord::Base
# #Num # #Num
ISSUES_REGEX = /(?:[a-zA-Z0-9\-_]*\/)?(?:[a-zA-Z0-9\-_]*)?#[0-9]+/ ISSUES_REGEX = /(?:[a-zA-Z0-9\-_]*\/)?(?:[a-zA-Z0-9\-_]*)?#[0-9]+/
belongs_to :commentable, :polymorphic => true, :touch => true belongs_to :commentable, polymorphic: true, touch: true
belongs_to :user belongs_to :user
belongs_to :project belongs_to :project
serialize :data serialize :data
validates :body, :user_id, :commentable_id, :commentable_type, :project_id, :presence => true validates :body, :user_id, :commentable_id, :commentable_type, :project_id, presence: true
scope :for_commit, lambda {|c| where(:commentable_id => c.id.hex, :commentable_type => c.class)} scope :for_commit, lambda {|c| where(commentable_id: c.id.hex, commentable_type: c.class)}
default_scope order("#{table_name}.created_at") default_scope order("#{table_name}.created_at")
after_create :subscribe_on_reply, :unless => lambda {|c| c.commit_comment?} after_create :subscribe_on_reply, unless: lambda {|c| c.commit_comment?}
after_create :subscribe_users after_create :subscribe_users
attr_accessible :body, :data attr_accessible :body, :data
@ -91,11 +91,11 @@ class Comment < ActiveRecord::Base
def set_additional_data params def set_additional_data params
return true if params[:path].blank? && params[:line].blank? # not inline comment return true if params[:path].blank? && params[:line].blank? # not inline comment
if params[:in_reply].present? && reply = Comment.where(:id => params[:in_reply]).first if params[:in_reply].present? && reply = Comment.where(id: params[:in_reply]).first
self.data = reply.data self.data = reply.data
return true return true
end end
self.data = {:path => params[:path], :line => params[:line]} self.data = {path: params[:path], line: params[:line]}
return actual_inline_comment?(nil, true) if commentable.is_a?(Grit::Commit) return actual_inline_comment?(nil, true) if commentable.is_a?(Grit::Commit)
if commentable.is_a?(Issue) && pull = commentable.pull_request if commentable.is_a?(Issue) && pull = commentable.pull_request
diff_path = pull.diff.select {|d| d.a_path == params[:path]} diff_path = pull.diff.select {|d| d.a_path == params[:path]}
@ -140,13 +140,13 @@ class Comment < ActiveRecord::Base
opts = {} opts = {}
when item.is_a?(Issue) when item.is_a?(Issue)
elements = [[item, item.title], [item, item.body]] elements = [[item, item.title], [item, item.body]]
opts = {:created_from_issue_id => item.id} opts = {created_from_issue_id: item.id}
when item.commentable_type == 'Issue' when item.commentable_type == 'Issue'
elements = [[item, item.body]] elements = [[item, item.body]]
opts = {:created_from_issue_id => item.commentable_id} opts = {created_from_issue_id: item.commentable_id}
when item.commentable_type == 'Grit::Commit' when item.commentable_type == 'Grit::Commit'
elements = [[item, item.body]] elements = [[item, item.body]]
opts = {:created_from_commit_hash => item.commentable_id} opts = {created_from_commit_hash: item.commentable_id}
else else
raise "Unsupported item type #{item.class.name}!" raise "Unsupported item type #{item.class.name}!"
end end
@ -157,18 +157,18 @@ class Comment < ActiveRecord::Base
next unless issue next unless issue
# dont create link to the same issue # dont create link to the same issue
next if opts[:created_from_issue_id] == issue.id next if opts[:created_from_issue_id] == issue.id
opts = {:created_from_commit_hash => element[0].hex} if item.is_a?(GitHook) opts = {created_from_commit_hash: element[0].hex} if item.is_a?(GitHook)
# dont create duplicate link to issue # dont create duplicate link to issue
next if Comment.find_existing_automatic_comment issue, opts next if Comment.find_existing_automatic_comment issue, opts
# dont create link to outdated commit # dont create link to outdated commit
next if item.is_a?(GitHook) && !item.project.repo.commit(element[0]) next if item.is_a?(GitHook) && !item.project.repo.commit(element[0])
comment = linker.comments.new :body => 'automatic comment' comment = linker.comments.new body: 'automatic comment'
comment.commentable, comment.project, comment.automatic = issue, issue.project, true comment.commentable, comment.project, comment.automatic = issue, issue.project, true
comment.data = {:from_project_id => item.project.id} comment.data = {from_project_id: item.project.id}
if opts[:created_from_commit_hash] if opts[:created_from_commit_hash]
comment.created_from_commit_hash = opts[:created_from_commit_hash] comment.created_from_commit_hash = opts[:created_from_commit_hash]
elsif opts[:created_from_issue_id] elsif opts[:created_from_issue_id]
comment.data.merge!(:comment_id => item.id) if item.is_a? Comment comment.data.merge!(comment_id: item.id) if item.is_a? Comment
comment.created_from_issue_id = opts[:created_from_issue_id] comment.created_from_issue_id = opts[:created_from_issue_id]
else else
raise 'Unsupported opts for automatic comment!' raise 'Unsupported opts for automatic comment!'
@ -187,25 +187,25 @@ class Comment < ActiveRecord::Base
protected protected
def subscribe_on_reply def subscribe_on_reply
commentable.subscribes.create(:user_id => user_id) if !commentable.subscribes.exists?(:user_id => user_id) commentable.subscribes.create(user_id: user_id) if !commentable.subscribes.exists?(user_id: user_id)
end end
def subscribe_users def subscribe_users
if issue_comment? if issue_comment?
commentable.subscribes.create(:user => user) if !commentable.subscribes.exists?(:user_id => user.id) commentable.subscribes.create(user: user) if !commentable.subscribes.exists?(user_id: user.id)
elsif commit_comment? elsif commit_comment?
recipients = project.admins recipients = project.admins
recipients << user << User.where(:email => commentable.try(:committer).try(:email)).first # commentor and committer recipients << user << User.where(email: commentable.try(:committer).try(:email)).first # commentor and committer
recipients.compact.uniq.each do |user| recipients.compact.uniq.each do |user|
options = {:project_id => project.id, :subscribeable_id => commentable_id, :subscribeable_type => commentable.class.name, :user_id => user.id} options = {project_id: project.id, subscribeable_id: commentable_id, subscribeable_type: commentable.class.name, user_id: user.id}
Subscribe.subscribe_to_commit(options) if Subscribe.subscribed_to_commit?(project, user, commentable) Subscribe.subscribe_to_commit(options) if Subscribe.subscribed_to_commit?(project, user, commentable)
end end
end end
end end
def self.find_existing_automatic_comment issue, opts def self.find_existing_automatic_comment issue, opts
find_dup = opts.merge(:automatic => true, :commentable_type => issue.class.name, find_dup = opts.merge(automatic: true, commentable_type: issue.class.name,
:commentable_id => issue.id) commentable_id: issue.id)
Comment.exists? find_dup Comment.exists? find_dup
end end
end end

View File

@ -1,6 +1,6 @@
class EventLog < ActiveRecord::Base class EventLog < ActiveRecord::Base
belongs_to :user belongs_to :user
belongs_to :eventable, :polymorphic => true belongs_to :eventable, polymorphic: true
# self.per_page = 1 # self.per_page = 1

View File

@ -2,24 +2,24 @@ class EventLogObserver < ActiveRecord::Observer
observe :user, :private_user, :platform, :repository, :project, :product, :build_list, :product_build_list observe :user, :private_user, :platform, :repository, :project, :product, :build_list, :product_build_list
def after_create(record) def after_create(record)
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record) ActiveSupport::Notifications.instrument("event_log.observer", eventable: record)
end end
def before_update(record) def before_update(record)
case record.class.to_s case record.class.to_s
when 'BuildList' when 'BuildList'
if record.status_changed? and [BuildList::BUILD_CANCELED, BuildList::BUILD_PUBLISHED].include?(record.status) if record.status_changed? and [BuildList::BUILD_CANCELED, BuildList::BUILD_PUBLISHED].include?(record.status)
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record) ActiveSupport::Notifications.instrument("event_log.observer", eventable: record)
end end
when 'Platform' when 'Platform'
if record.visibility_changed? if record.visibility_changed?
ActiveSupport::Notifications.instrument "event_log.observer", :eventable => record, ActiveSupport::Notifications.instrument "event_log.observer", eventable: record,
:message => I18n.t("activerecord.attributes.platform.visibility_types.#{record.visibility}") message: I18n.t("activerecord.attributes.platform.visibility_types.#{record.visibility}")
end end
end end
end end
def after_destroy(record) def after_destroy(record)
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record) ActiveSupport::Notifications.instrument("event_log.observer", eventable: record)
end end
end end

View File

@ -12,10 +12,10 @@ class Feedback
attr_accessible :name, :email, :subject, :message attr_accessible :name, :email, :subject, :message
validates :name, :subject, :message, :presence => true validates :name, :subject, :message, presence: true
validates :email, :presence => true, validates :email, presence: true,
:format => { :with => /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/, format: { with: /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/,
:allow_blank => false } allow_blank: false }
def initialize(args = {}, options = {}) def initialize(args = {}, options = {})
return args.dup if args.is_a? Feedback return args.dup if args.is_a? Feedback

View File

@ -5,10 +5,10 @@ class FlashNotify < ActiveRecord::Base
STATUSES = %w[error success info] STATUSES = %w[error success info]
validates :status, :inclusion => {:in => STATUSES} validates :status, inclusion: {in: STATUSES}
validates :body_ru, :body_en, :status, :presence => true validates :body_ru, :body_en, :status, presence: true
scope :published, where(:published => true) scope :published, where(published: true)
def hash_id def hash_id
@digest ||= Digest::MD5.hexdigest("#{self.id}-#{self.updated_at}") @digest ||= Digest::MD5.hexdigest("#{self.id}-#{self.updated_at}")

View File

@ -13,8 +13,8 @@ class GitHook
def initialize(owner_uname, repo, newrev, oldrev, ref, newrev_type, user = nil, message = nil) def initialize(owner_uname, repo, newrev, oldrev, ref, newrev_type, user = nil, message = nil)
@repo, @newrev, @oldrev, @refname, @newrev_type, @user, @message = repo, newrev, oldrev, ref, newrev_type, user, message @repo, @newrev, @oldrev, @refname, @newrev_type, @user, @message = repo, newrev, oldrev, ref, newrev_type, user, message
if @owner = User.where(:uname => owner_uname).first || Group.where(:uname => owner_uname).first! if @owner = User.where(uname: owner_uname).first || Group.where(uname: owner_uname).first!
@project = @owner.own_projects.where(:name => repo).first! @project = @owner.own_projects.where(name: repo).first!
end end
@change_type, @user = git_change_type, find_user(user) @change_type, @user = git_change_type, find_user(user)
git_revision_types git_revision_types

View File

@ -1,29 +1,29 @@
class Group < Avatar class Group < Avatar
belongs_to :owner, :class_name => 'User' belongs_to :owner, class_name: 'User'
has_many :relations, :as => :actor, :dependent => :destroy, :dependent => :destroy has_many :relations, as: :actor, dependent: :destroy, dependent: :destroy
has_many :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy has_many :actors, as: :target, class_name: 'Relation', dependent: :destroy
has_many :targets, :as => :actor, :class_name => 'Relation', :dependent => :destroy has_many :targets, as: :actor, class_name: 'Relation', dependent: :destroy
has_many :members, :through => :actors, :source => :actor, :source_type => 'User', :autosave => true has_many :members, through: :actors, source: :actor, source_type: 'User', autosave: true
has_many :projects, :through => :targets, :source => :target, :source_type => 'Project', :autosave => true has_many :projects, through: :targets, source: :target, source_type: 'Project', autosave: true
has_many :own_projects, :as => :owner, :class_name => 'Project', :dependent => :destroy has_many :own_projects, as: :owner, class_name: 'Project', dependent: :destroy
has_many :own_platforms, :as => :owner, :class_name => 'Platform', :dependent => :destroy has_many :own_platforms, as: :owner, class_name: 'Platform', dependent: :destroy
validates :owner, :presence => true validates :owner, presence: true
validates :uname, :presence => true, :uniqueness => {:case_sensitive => false}, :format => {:with => /\A[a-z0-9_]+\z/}, :reserved_name => true validates :uname, presence: true, uniqueness: {case_sensitive: false}, format: {with: /\A[a-z0-9_]+\z/}, reserved_name: true
validate { errors.add(:uname, :taken) if User.by_uname(uname).present? } validate { errors.add(:uname, :taken) if User.by_uname(uname).present? }
scope :opened, where('1=1') scope :opened, where('1=1')
scope :by_owner, lambda {|owner| where(:owner_id => owner.id)} scope :by_owner, lambda {|owner| where(owner_id: owner.id)}
scope :by_admin, lambda {|admin| joins(:actors).where(:'relations.role' => 'admin', :'relations.actor_id' => admin.id, :'relations.actor_type' => 'User')} scope :by_admin, lambda {|admin| joins(:actors).where(:'relations.role' => 'admin', :'relations.actor_id' => admin.id, :'relations.actor_type' => 'User')}
scope :by_admin_and_writer, lambda {|actor| joins(:actors).where(:'relations.role' => ['admin', 'writer'], :'relations.actor_id' => actor.id, :'relations.actor_type' => 'User')} scope :by_admin_and_writer, lambda {|actor| joins(:actors).where(:'relations.role' => ['admin', 'writer'], :'relations.actor_id' => actor.id, :'relations.actor_type' => 'User')}
attr_accessible :uname, :description attr_accessible :uname, :description
attr_readonly :uname attr_readonly :uname
delegate :email, :to => :owner delegate :email, to: :owner
after_create :add_owner_to_members after_create :add_owner_to_members
@ -58,6 +58,6 @@ class Group < Avatar
protected protected
def add_owner_to_members def add_owner_to_members
Relation.create_with_role(self.owner, self, 'admin') # members << self.owner if !members.exists?(:id => self.owner.id) Relation.create_with_role(self.owner, self, 'admin') # members << self.owner if !members.exists?(id: self.owner.id)
end end
end end

View File

@ -5,14 +5,14 @@ class Hook < ActiveRecord::Base
belongs_to :project belongs_to :project
before_validation :cleanup_data before_validation :cleanup_data
validates :project_id, :data, :presence => true validates :project_id, :data, presence: true
validates :name, :presence => true, :inclusion => {:in => NAMES} validates :name, presence: true, inclusion: {in: NAMES}
attr_accessible :data, :name attr_accessible :data, :name
serialize :data, Hash serialize :data, Hash
scope :for_name, lambda {|name| where(:name => name) if name.present? } scope :for_name, lambda {|name| where(name: name) if name.present? }
def receive_issues(issue, action) def receive_issues(issue, action)
pull = issue.pull_request pull = issue.pull_request
@ -21,38 +21,38 @@ class Hook < ActiveRecord::Base
payload = meta(issue.project, issue.user) payload = meta(issue.project, issue.user)
base_params = { base_params = {
:number => issue.serial_id, number: issue.serial_id,
:state => issue.status, state: issue.status,
:title => issue.title, title: issue.title,
:body => issue.body, body: issue.body,
:user => {:login => issue.user.uname}, user: {login: issue.user.uname},
} }
if pull if pull
total_commits = pull.repo.commits_between(pull.to_commit, pull.from_commit).count total_commits = pull.repo.commits_between(pull.to_commit, pull.from_commit).count
repo_owner = pull.to_project.owner.uname repo_owner = pull.to_project.owner.uname
post 'pull_request', { post 'pull_request', {
:payload => payload.merge( payload: payload.merge(
:action => (pull.ready? ? 'opened' : pull.status), action: (pull.ready? ? 'opened' : pull.status),
:pull_request => base_params.merge( pull_request: base_params.merge(
:commits => total_commits, commits: total_commits,
:head => {:label => "#{pull.from_project.owner.uname}:#{pull.from_ref}"}, head: {label: "#{pull.from_project.owner.uname}:#{pull.from_ref}"},
:base => {:label => "#{repo_owner}:#{pull.to_ref}"}, base: {label: "#{repo_owner}:#{pull.to_ref}"},
:html_url => project_pull_request_url(pull.to_project, pull) html_url: project_pull_request_url(pull.to_project, pull)
) )
).to_json ).to_json
} }
else else
post 'issues', { post 'issues', {
:payload => payload.merge( payload: payload.merge(
:action => (issue.closed? ? 'closed' : 'opened'), action: (issue.closed? ? 'closed' : 'opened'),
:issue => base_params.merge( issue: base_params.merge(
:html_url => project_issue_url(issue.project, issue) html_url: project_issue_url(issue.project, issue)
) )
).to_json ).to_json
} }
end end
end end
later :receive_issues, :queue => :notification later :receive_issues, queue: :notification
def receive_push(git_hook) def receive_push(git_hook)
default_url_options default_url_options
@ -60,9 +60,9 @@ class Hook < ActiveRecord::Base
user = User.find(git_hook['user']['user']['id']) user = User.find(git_hook['user']['user']['id'])
payload = meta(project, user) payload = meta(project, user)
oldrev, newrev, change_type = git_hook.values_at *%w(oldrev newrev change_type) oldrev, newrev, change_type = git_hook.values_at *%w(oldrev newrev change_type)
commits = [] commits = []
payload.merge!(:before => oldrev, :after => newrev) payload.merge!(before: oldrev, after: newrev)
if %w(delete create).exclude? change_type if %w(delete create).exclude? change_type
payload.merge!( payload.merge!(
:compare => diff_url(project, "#{oldrev[0..6]}...#{newrev[0..6]}") :compare => diff_url(project, "#{oldrev[0..6]}...#{newrev[0..6]}")
@ -76,45 +76,45 @@ class Hook < ActiveRecord::Base
end end
post 'push', { post 'push', {
:payload => payload.merge( payload: payload.merge(
:ref => git_hook['refname'], ref: git_hook['refname'],
:commits => commits.map{ |commit| commits: commits.map{ |commit|
files = changed_files commit files = changed_files commit
{ {
:id => commit.id, id: commit.id,
:message => commit.message, message: commit.message,
:distinct => true, distinct: true,
:url => commit_url(project, commit), url: commit_url(project, commit),
:removed => files[:removed], removed: files[:removed],
:added => files[:added], added: files[:added],
:modified => files[:modified], modified: files[:modified],
:timestamp => commit.committed_date, timestamp: commit.committed_date,
:author => {:name => commit.committer.name, :email => commit.committer.email} author: {name: commit.committer.name, email: commit.committer.email}
} }
} }
).to_json ).to_json
} }
end end
later :receive_push, :queue => :notification later :receive_push, queue: :notification
protected protected
def post(action, params) def post(action, params)
github_services = APP_CONFIG['github_services'] github_services = APP_CONFIG['github_services']
uri = URI "http://#{github_services['ip']}:#{github_services['port']}/#{name}/#{action}" uri = URI "http://#{github_services['ip']}:#{github_services['port']}/#{name}/#{action}"
Net::HTTP.post_form uri, params.merge(:data => data.to_json) Net::HTTP.post_form uri, params.merge(data: data.to_json)
rescue # Dont care about it rescue # Dont care about it
end end
def meta(project, user) def meta(project, user)
{ {
:repository => { repository: {
:name => project.name, name: project.name,
:url => project_url(project), url: project_url(project),
:owner => { :login => project.owner.uname } owner: { login: project.owner.uname }
}, },
:sender => {:login => user.uname}, sender: {login: user.uname},
:pusher => {:name => user.uname} pusher: {name: user.uname}
} }
end end
@ -140,7 +140,7 @@ class Hook < ActiveRecord::Base
modified << diff.a_path modified << diff.a_path
end end
end end
{:removed => removed, :added => added, :modified => modified} {removed: removed, added: added, modified: modified}
end end
end end

View File

@ -4,30 +4,30 @@ class Issue < ActiveRecord::Base
belongs_to :project belongs_to :project
belongs_to :user belongs_to :user
belongs_to :assignee, :class_name => 'User', :foreign_key => 'assignee_id' belongs_to :assignee, class_name: 'User', foreign_key: 'assignee_id'
belongs_to :closer, :class_name => 'User', :foreign_key => 'closed_by' belongs_to :closer, class_name: 'User', foreign_key: 'closed_by'
has_many :comments, :as => :commentable, :dependent => :destroy has_many :comments, as: :commentable, dependent: :destroy
has_many :subscribes, :as => :subscribeable, :dependent => :destroy has_many :subscribes, as: :subscribeable, dependent: :destroy
has_many :labelings, :dependent => :destroy has_many :labelings, dependent: :destroy
has_many :labels, :through => :labelings, :uniq => true has_many :labels, through: :labelings, uniq: true
has_one :pull_request, :dependent => :destroy has_one :pull_request, dependent: :destroy
validates :title, :body, :project_id, :presence => true validates :title, :body, :project_id, presence: true
after_create :set_serial_id after_create :set_serial_id
after_create :subscribe_users after_create :subscribe_users
after_update :subscribe_issue_assigned_user after_update :subscribe_issue_assigned_user
attr_accessible :labelings_attributes, :title, :body, :assignee_id attr_accessible :labelings_attributes, :title, :body, :assignee_id
accepts_nested_attributes_for :labelings, :allow_destroy => true accepts_nested_attributes_for :labelings, allow_destroy: true
scope :opened, where(:status => 'open') scope :opened, where(status: 'open')
scope :closed, where(:status => 'closed') scope :closed, where(status: 'closed')
scope :needed_checking, where(:issues => {:status => ['open', 'blocked', 'ready', 'already']}) scope :needed_checking, where(issues: {status: ['open', 'blocked', 'ready', 'already']})
scope :not_closed_or_merged, needed_checking scope :not_closed_or_merged, needed_checking
scope :closed_or_merged, where(:issues => {:status => ['closed', 'merged']}) scope :closed_or_merged, where(issues: {status: ['closed', 'merged']})
# Using mb_chars for correct transform to lowercase ('Русский Текст'.downcase => "Русский Текст") # Using mb_chars for correct transform to lowercase ('Русский Текст'.downcase => "Русский Текст")
scope :search, lambda {|q| where("#{table_name}.title ILIKE ?", "%#{q.mb_chars.downcase}%") if q.present?} scope :search, lambda {|q| where("#{table_name}.title ILIKE ?", "%#{q.mb_chars.downcase}%") if q.present?}
scope :without_pull_requests, where('NOT EXISTS (select null from pull_requests as pr where pr.issue_id = issues.id)') scope :without_pull_requests, where('NOT EXISTS (select null from pull_requests as pr where pr.issue_id = issues.id)')
@ -41,8 +41,8 @@ class Issue < ActiveRecord::Base
end end
def subscribe_creator(creator_id) def subscribe_creator(creator_id)
if !self.subscribes.exists?(:user_id => creator_id) if !self.subscribes.exists?(user_id: creator_id)
self.subscribes.create(:user_id => creator_id) self.subscribes.create(user_id: creator_id)
end end
end end
@ -75,7 +75,7 @@ class Issue < ActiveRecord::Base
project = Project.find_by_owner_and_name(owner_uname.chomp('/'), project_name) project = Project.find_by_owner_and_name(owner_uname.chomp('/'), project_name)
return nil unless project return nil unless project
return nil unless current_ability.can? :show, project return nil unless current_ability.can? :show, project
project.issues.where(:serial_id => serial_id).first project.issues.where(serial_id: serial_id).first
end end
protected protected
@ -87,17 +87,17 @@ class Issue < ActiveRecord::Base
def subscribe_users def subscribe_users
collect_recipients.each do |recipient| collect_recipients.each do |recipient|
if recipient.notifier.new_comment && !self.subscribes.exists?(:user_id => recipient.id) if recipient.notifier.new_comment && !self.subscribes.exists?(user_id: recipient.id)
ss = self.subscribes.create(:user_id => recipient.id) ss = self.subscribes.create(user_id: recipient.id)
end end
end end
end end
def subscribe_issue_assigned_user def subscribe_issue_assigned_user
if self.assignee_id && self.assignee_id_changed? if self.assignee_id && self.assignee_id_changed?
self.subscribes.where(:user_id => self.assignee_id_was).first.destroy unless self.assignee_id_was.blank? self.subscribes.where(user_id: self.assignee_id_was).first.destroy unless self.assignee_id_was.blank?
if self.assignee.notifier.issue_assign && !self.subscribes.exists?(:user_id => self.assignee_id) if self.assignee.notifier.issue_assign && !self.subscribes.exists?(user_id: self.assignee_id)
self.subscribes.create(:user_id => self.assignee_id) self.subscribes.create(user_id: self.assignee_id)
end end
end end
end end

View File

@ -4,12 +4,12 @@ class KeyPair < ActiveRecord::Base
attr_accessor :fingerprint attr_accessor :fingerprint
attr_accessible :public, :secret, :repository_id attr_accessible :public, :secret, :repository_id
attr_encrypted :secret, :key => APP_CONFIG['keys']['key_pair_secret_key'] attr_encrypted :secret, key: APP_CONFIG['keys']['key_pair_secret_key']
validates :repository_id, :user_id, :presence => true validates :repository_id, :user_id, presence: true
validates :secret, :public, :presence => true, :length => { :maximum => 10000 }, :on => :create validates :secret, :public, presence: true, length: { maximum: 10000 }, on: :create
validates :repository_id, :uniqueness => {:message => I18n.t("activerecord.errors.key_pair.repo_key_exists")} validates :repository_id, uniqueness: {message: I18n.t("activerecord.errors.key_pair.repo_key_exists")}
validate :check_keys validate :check_keys
before_create { |record| record.key_id = @fingerprint } before_create { |record| record.key_id = @fingerprint }

View File

@ -1,10 +1,10 @@
class Label < ActiveRecord::Base class Label < ActiveRecord::Base
has_many :labelings, :dependent => :destroy has_many :labelings, dependent: :destroy
has_many :issues, :through => :labelings has_many :issues, through: :labelings
belongs_to :project belongs_to :project
validates :name, :uniqueness => {:scope => :project_id} validates :name, uniqueness: {scope: :project_id}
validates :name, :color, :presence => true validates :name, :color, presence: true
validates :color, :format => { :with => /\A([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, :message => I18n.t('layout.issues.invalid_labels')} validates :color, format: { with: /\A([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/, message: I18n.t('layout.issues.invalid_labels')}
end end

View File

@ -1,26 +1,26 @@
class MassBuild < ActiveRecord::Base class MassBuild < ActiveRecord::Base
belongs_to :build_for_platform, :class_name => 'Platform', :conditions => {:platform_type => 'main'} belongs_to :build_for_platform, class_name: 'Platform', conditions: {platform_type: 'main'}
belongs_to :save_to_platform, :class_name => 'Platform' belongs_to :save_to_platform, class_name: 'Platform'
belongs_to :user belongs_to :user
has_many :build_lists, :dependent => :destroy has_many :build_lists, dependent: :destroy
serialize :extra_repositories, Array serialize :extra_repositories, Array
serialize :extra_build_lists, Array serialize :extra_build_lists, Array
scope :recent, order("#{table_name}.created_at DESC") scope :recent, order("#{table_name}.created_at DESC")
scope :by_platform, lambda { |platform| where(:save_to_platform_id => platform.id) } scope :by_platform, lambda { |platform| where(save_to_platform_id: platform.id) }
scope :outdated, where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) scope :outdated, where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME)
attr_accessor :arches attr_accessor :arches
attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id, attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id,
:extra_repositories, :extra_build_lists, :increase_release_tag :extra_repositories, :extra_build_lists, :increase_release_tag
validates :save_to_platform_id, :build_for_platform_id, :arch_names, :name, :user_id, :presence => true validates :save_to_platform_id, :build_for_platform_id, :arch_names, :name, :user_id, presence: true
validates :projects_list, :length => {:maximum => 500_000}, :presence => true validates :projects_list, length: {maximum: 500_000}, presence: true
validates_inclusion_of :auto_publish, :increase_release_tag, :in => [true, false] validates_inclusion_of :auto_publish, :increase_release_tag, in: [true, false]
after_commit :build_all, :on => :create after_commit :build_all, on: :create
before_validation :set_data, :on => :create before_validation :set_data, on: :create
COUNT_STATUSES = [ COUNT_STATUSES = [
:build_lists, :build_lists,
@ -35,7 +35,7 @@ class MassBuild < ActiveRecord::Base
def build_all def build_all
# later with resque # later with resque
arches_list = arch_names ? Arch.where(:name => arch_names.split(', ')) : Arch.all arches_list = arch_names ? Arch.where(name: arch_names.split(', ')) : Arch.all
projects_list.lines.each do |name| projects_list.lines.each do |name|
next if name.blank? next if name.blank?
@ -59,15 +59,15 @@ class MassBuild < ActiveRecord::Base
end end
end end
end end
later :build_all, :queue => :clone_build later :build_all, queue: :clone_build
def generate_failed_builds_list def generate_failed_builds_list
report = "" report = ""
BuildList.select('build_lists.id, projects.name as project_name, arches.name as arch_name'). BuildList.select('build_lists.id, projects.name as project_name, arches.name as arch_name').
where( where(
:status => BuildList::BUILD_ERROR, status: BuildList::BUILD_ERROR,
:mass_build_id => self.id mass_build_id: self.id
).joins(:project, :arch).find_in_batches(:batch_size => 100) do |build_lists| ).joins(:project, :arch).find_in_batches(batch_size: 100) do |build_lists|
build_lists.each do |build_list| build_lists.each do |build_list|
report << "ID: #{build_list.id}; " report << "ID: #{build_list.id}; "
report << "PROJECT_NAME: #{build_list.project_name}; " report << "PROJECT_NAME: #{build_list.project_name}; "
@ -79,28 +79,28 @@ class MassBuild < ActiveRecord::Base
def cancel_all def cancel_all
update_column(:stop_build, true) update_column(:stop_build, true)
build_lists.find_each(:batch_size => 100) do |bl| build_lists.find_each(batch_size: 100) do |bl|
bl.cancel bl.cancel
end end
end end
later :cancel_all, :queue => :clone_build later :cancel_all, queue: :clone_build
def publish_success_builds(user) def publish_success_builds(user)
publish user, BuildList::SUCCESS, BuildList::FAILED_PUBLISH publish user, BuildList::SUCCESS, BuildList::FAILED_PUBLISH
end end
later :publish_success_builds, :queue => :clone_build later :publish_success_builds, queue: :clone_build
def publish_test_failed_builds(user) def publish_test_failed_builds(user)
publish user, BuildList::TESTS_FAILED publish user, BuildList::TESTS_FAILED
end end
later :publish_test_failed_builds, :queue => :clone_build later :publish_test_failed_builds, queue: :clone_build
private private
def publish(user, *statuses) def publish(user, *statuses)
builds = build_lists.where(:status => statuses) builds = build_lists.where(status: statuses)
builds.update_all(:publisher_id => user.id) builds.update_all(publisher_id: user.id)
builds.order(:id).find_in_batches(:batch_size => 50) do |bls| builds.order(:id).find_in_batches(batch_size: 50) do |bls|
bls.each{ |bl| bl.can_publish? && bl.has_new_packages? && bl.now_publish } bls.each{ |bl| bl.can_publish? && bl.has_new_packages? && bl.now_publish }
end end
end end
@ -110,7 +110,7 @@ class MassBuild < ActiveRecord::Base
self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{save_to_platform.name}" self.name = "#{Time.now.utc.to_date.strftime("%d.%b")}-#{save_to_platform.name}"
self.build_for_platform = save_to_platform if save_to_platform.main? self.build_for_platform = save_to_platform if save_to_platform.main?
end end
self.arch_names = Arch.where(:id => arches).map(&:name).join(", ") self.arch_names = Arch.where(id: arches).map(&:name).join(", ")
self.projects_list = projects_list.lines.map do |name| self.projects_list = projects_list.lines.map do |name|
name.chomp.strip if name.present? name.chomp.strip if name.present?

View File

@ -9,29 +9,29 @@ class Platform < ActiveRecord::Base
NAME_PATTERN = /[\w\-\.]+/ NAME_PATTERN = /[\w\-\.]+/
HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze HUMAN_STATUSES = HUMAN_STATUSES.clone.freeze
belongs_to :parent, :class_name => 'Platform', :foreign_key => 'parent_platform_id' belongs_to :parent, class_name: 'Platform', foreign_key: 'parent_platform_id'
belongs_to :owner, :polymorphic => true belongs_to :owner, polymorphic: true
has_many :repositories, :dependent => :destroy has_many :repositories, dependent: :destroy
has_many :products, :dependent => :destroy has_many :products, dependent: :destroy
has_many :tokens, :as => :subject, :dependent => :destroy has_many :tokens, as: :subject, dependent: :destroy
has_many :platform_arch_settings, :dependent => :destroy has_many :platform_arch_settings, dependent: :destroy
has_many :repository_statuses has_many :repository_statuses
has_many :relations, :as => :target, :dependent => :destroy has_many :relations, as: :target, dependent: :destroy
has_many :actors, :as => :target, :class_name => 'Relation', :dependent => :destroy has_many :actors, as: :target, class_name: 'Relation', dependent: :destroy
has_many :members, :through => :actors, :source => :actor, :source_type => 'User' has_many :members, through: :actors, source: :actor, source_type: 'User'
has_and_belongs_to_many :advisories has_and_belongs_to_many :advisories
has_many :packages, :class_name => "BuildList::Package", :dependent => :destroy has_many :packages, class_name: "BuildList::Package", dependent: :destroy
has_many :mass_builds, :foreign_key => :save_to_platform_id has_many :mass_builds, foreign_key: :save_to_platform_id
validates :description, :presence => true validates :description, presence: true
validates :visibility, :presence => true, :inclusion => {:in => VISIBILITIES} validates :visibility, presence: true, inclusion: {in: VISIBILITIES}
validates :name, :uniqueness => {:case_sensitive => false}, :presence => true, :format => { :with => /\A#{NAME_PATTERN}\z/ } validates :name, uniqueness: {case_sensitive: false}, presence: true, format: { with: /\A#{NAME_PATTERN}\z/ }
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']} validates :distrib_type, presence: true, inclusion: {in: APP_CONFIG['distr_types']}
validate lambda { validate lambda {
if released_was && !released if released_was && !released
errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed')) errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed'))
@ -41,7 +41,7 @@ class Platform < ActiveRecord::Base
if personal? && (owner_id_changed? || owner_type_changed?) if personal? && (owner_id_changed? || owner_type_changed?)
errors.add :owner, I18n.t('flash.platform.owner_can_not_be_changed') errors.add :owner, I18n.t('flash.platform.owner_can_not_be_changed')
end end
}, :on => :update }, on: :update
before_create :create_directory before_create :create_directory
before_destroy :detele_directory before_destroy :detele_directory
@ -54,35 +54,35 @@ class Platform < ActiveRecord::Base
scope :search_order, order("CHAR_LENGTH(#{table_name}.name) ASC") scope :search_order, order("CHAR_LENGTH(#{table_name}.name) ASC")
scope :search, lambda {|q| where("#{table_name}.name ILIKE ?", "%#{q.to_s.strip}%")} scope :search, lambda {|q| where("#{table_name}.name ILIKE ?", "%#{q.to_s.strip}%")}
scope :by_visibilities, lambda {|v| where(:visibility => v)} scope :by_visibilities, lambda {|v| where(visibility: v)}
scope :opened, where(:visibility => 'open') scope :opened, where(visibility: 'open')
scope :hidden, where(:visibility => 'hidden') scope :hidden, where(visibility: 'hidden')
scope :by_type, lambda {|type| where(:platform_type => type) if type.present?} scope :by_type, lambda {|type| where(platform_type: type) if type.present?}
scope :main, by_type('main') scope :main, by_type('main')
scope :personal, by_type('personal') scope :personal, by_type('personal')
scope :waiting_for_regeneration, where(:status => WAITING_FOR_REGENERATION) scope :waiting_for_regeneration, where(status: WAITING_FOR_REGENERATION)
accepts_nested_attributes_for :platform_arch_settings, :allow_destroy => true accepts_nested_attributes_for :platform_arch_settings, allow_destroy: true
attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released, :platform_arch_settings_attributes attr_accessible :name, :distrib_type, :parent_platform_id, :platform_type, :owner, :visibility, :description, :released, :platform_arch_settings_attributes
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
include Modules::Models::Owner include Modules::Models::Owner
state_machine :status, :initial => :ready do state_machine :status, initial: :ready do
event :ready do event :ready do
transition :regenerating => :ready transition regenerating: :ready
end end
event :regenerate do event :regenerate do
transition :ready => :waiting_for_regeneration, :if => lambda{ |p| p.main? } transition ready: :waiting_for_regeneration, if: lambda{ |p| p.main? }
end end
event :start_regeneration do event :start_regeneration do
transition :waiting_for_regeneration => :regenerating transition waiting_for_regeneration: :regenerating
end end
HUMAN_STATUSES.each do |code,name| HUMAN_STATUSES.each do |code,name|
state name, :value => code state name, value: code
end end
end end
@ -95,7 +95,7 @@ class Platform < ActiveRecord::Base
urpmi_commands = ActiveSupport::OrderedHash.new urpmi_commands = ActiveSupport::OrderedHash.new
# TODO: rename method or create separate methods for mdv and rhel # TODO: rename method or create separate methods for mdv and rhel
# Platform.main.opened.where(:distrib_type => APP_CONFIG['distr_types'].first).each do |pl| # Platform.main.opened.where(distrib_type: APP_CONFIG['distr_types'].first).each do |pl|
Platform.main.opened.each do |pl| Platform.main.opened.each do |pl|
urpmi_commands[pl.name] = {} urpmi_commands[pl.name] = {}
# FIXME should support restricting access to the hidden platform # FIXME should support restricting access to the hidden platform
@ -158,7 +158,7 @@ class Platform < ActiveRecord::Base
end end
def clone_relations(from = parent) def clone_relations(from = parent)
self.repositories = from.repositories.map{|r| r.full_clone(:platform_id => id)} self.repositories = from.repositories.map{|r| r.full_clone(platform_id: id)}
self.products = from.products.map(&:full_clone) self.products = from.products.map(&:full_clone)
end end
@ -170,9 +170,9 @@ class Platform < ActiveRecord::Base
def change_visibility def change_visibility
if !hidden? if !hidden?
update_attributes(:visibility => 'hidden') update_attributes(visibility: 'hidden')
else else
update_attributes(:visibility => 'open') update_attributes(visibility: 'open')
end end
end end
@ -191,15 +191,15 @@ class Platform < ActiveRecord::Base
def update_owner_relation def update_owner_relation
if owner_id_was != owner_id if owner_id_was != owner_id
r = relations.where(:actor_id => owner_id_was, :actor_type => owner_type_was).first r = relations.where(actor_id: owner_id_was, actor_type: owner_type_was).first
r.update_attributes(:actor_id => owner_id, :actor_type => owner_type) r.update_attributes(actor_id: owner_id, actor_type: owner_type)
end end
end end
def destroy def destroy
with_skip {super} # avoid cascade XML RPC requests with_skip {super} # avoid cascade XML RPC requests
end end
later :destroy, :queue => :clone_build later :destroy, queue: :clone_build
def default_host def default_host
EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host] EventLog.current_controller.request.host_with_port rescue ::Rosa::Application.config.action_mailer.default_url_options[:host]
@ -217,12 +217,12 @@ class Platform < ActiveRecord::Base
token, pass = *ActionController::HttpAuthentication::Basic::user_name_and_password(request) token, pass = *ActionController::HttpAuthentication::Basic::user_name_and_password(request)
end end
Rails.cache.fetch([platform_name, token, :platform_allowed], :expires_in => 2.minutes) do Rails.cache.fetch([platform_name, token, :platform_allowed], expires_in: 2.minutes) do
platform = Platform.find_by_name platform_name platform = Platform.find_by_name platform_name
next false unless platform next false unless platform
next true unless platform.hidden? next true unless platform.hidden?
next false unless token next false unless token
next true if platform.tokens.by_active.where(:authentication_token => token).exists? next true if platform.tokens.by_active.where(authentication_token: token).exists?
user = User.find_by_authentication_token token user = User.find_by_authentication_token token
current_ability = Ability.new(user) current_ability = Ability.new(user)
@ -252,11 +252,11 @@ class Platform < ActiveRecord::Base
def fs_clone(old_name = parent.name, new_name = name) def fs_clone(old_name = parent.name, new_name = name)
FileUtils.cp_r "#{parent.path}/repository", path FileUtils.cp_r "#{parent.path}/repository", path
end end
later :fs_clone, :queue => :clone_build later :fs_clone, queue: :clone_build
def freeze_platform_and_update_repos def freeze_platform_and_update_repos
if released_changed? && released == true if released_changed? && released == true
repositories.update_all(:publish_without_qa => false) repositories.update_all(publish_without_qa: false)
end end
end end
end end

View File

@ -7,11 +7,11 @@ class PlatformArchSetting < ActiveRecord::Base
belongs_to :arch belongs_to :arch
belongs_to :platform belongs_to :platform
validates :arch_id, :platform_id, :presence => true validates :arch_id, :platform_id, presence: true
validates :platform_id, :uniqueness => {:scope => :arch_id} validates :platform_id, :uniqueness => {scope: :arch_id}
scope :by_arch, lambda {|arch| where(:arch_id => arch) if arch.present?} scope :by_arch, lambda {|arch| where(arch_id: arch) if arch.present?}
scope :by_default, where(:default => true) scope :by_default, where(default: true)
attr_accessible :arch_id, :platform_id, :default attr_accessible :arch_id, :platform_id, :default

View File

@ -20,9 +20,9 @@ class PlatformContent
return nil unless repository_name = @path.match(/\/[\w]+\/(release|updates)\//) return nil unless repository_name = @path.match(/\/[\w]+\/(release|updates)\//)
repository_name = repository_name[0].gsub(/\/(release|updates)\/$/, '').gsub('/', '') repository_name = repository_name[0].gsub(/\/(release|updates)\/$/, '').gsub('/', '')
repository = @platform.repositories.where(:name => repository_name).first repository = @platform.repositories.where(name: repository_name).first
return nil unless repository return nil unless repository
if @platform.main? if @platform.main?
build_for_platform = @platform build_for_platform = @platform
else else
@ -36,8 +36,8 @@ class PlatformContent
@build_list = BuildList.for_status(BuildList::BUILD_PUBLISHED) @build_list = BuildList.for_status(BuildList::BUILD_PUBLISHED)
.for_platform(build_for_platform) .for_platform(build_for_platform)
.scoped_to_save_platform(@platform) .scoped_to_save_platform(@platform)
.where(:save_to_repository_id => repository) .where(save_to_repository_id: repository)
.where(:build_list_packages => {:fullname => name, :actual => true}) .where(build_list_packages: {fullname: name, actual: true})
.joins(:packages) .joins(:packages)
.last .last

View File

@ -1,32 +1,32 @@
class PrivateUser < ActiveRecord::Base class PrivateUser < ActiveRecord::Base
require 'digest/sha2' require 'digest/sha2'
belongs_to :platform belongs_to :platform
belongs_to :user belongs_to :user
validate :login, :uniqueness => true validate :login, uniqueness: true
def event_log_message def event_log_message
{:platform => platform.name, :user => user.uname}.inspect {platform: platform.name, user: user.uname}.inspect
end end
class << self class << self
def can_generate_more?(user_id, platform_id) def can_generate_more?(user_id, platform_id)
!PrivateUser.exists?(:user_id => user_id, :platform_id => platform_id) !PrivateUser.exists?(user_id: user_id, platform_id: platform_id)
end end
def generate_pair(platform_id, user_id) def generate_pair(platform_id, user_id)
login = "login_#{ActiveSupport::SecureRandom.hex(16)}" login = "login_#{ActiveSupport::SecureRandom.hex(16)}"
pass = "pass_#{ActiveSupport::SecureRandom.hex(16)}" pass = "pass_#{ActiveSupport::SecureRandom.hex(16)}"
PrivateUser.create( PrivateUser.create(
:login => login, login: login,
:password => Digest::SHA2.new.hexdigest(pass), password: Digest::SHA2.new.hexdigest(pass),
:platform_id => platform_id, platform_id: platform_id,
:user_id => user_id user_id: user_id
) )
{:login => login, :pass => pass} {login: login, pass: pass}
end end
end end
end end

View File

@ -3,7 +3,7 @@ class Product < ActiveRecord::Base
belongs_to :platform belongs_to :platform
belongs_to :project belongs_to :project
has_many :product_build_lists, :dependent => :destroy has_many :product_build_lists, dependent: :destroy
ONCE_A_12_HOURS = 0 ONCE_A_12_HOURS = 0
ONCE_A_DAY = 1 ONCE_A_DAY = 1
@ -16,11 +16,11 @@ class Product < ActiveRecord::Base
ONCE_A_WEEK => :once_a_week ONCE_A_WEEK => :once_a_week
} }
validates :name, :presence => true, :uniqueness => {:scope => :platform_id} validates :name, presence: true, uniqueness: {scope: :platform_id}
validates :project_id, :presence => true validates :project_id, presence: true
validates :main_script, :params, :length => { :maximum => 255 } validates :main_script, :params, length: { maximum: 255 }
validates :autostart_status, :numericality => true, validates :autostart_status, numericality: true,
:inclusion => {:in => AUTOSTART_STATUSES}, :allow_blank => true inclusion: {in: AUTOSTART_STATUSES}, allow_blank: true
scope :recent, order("#{table_name}.name ASC") scope :recent, order("#{table_name}.name ASC")
@ -61,7 +61,7 @@ class Product < ActiveRecord::Base
end end
def self.autostart_iso_builds(autostart_status) def self.autostart_iso_builds(autostart_status)
Product.where(:autostart_status => autostart_status).each do |product| Product.where(autostart_status: autostart_status).each do |product|
pbl = product.product_build_lists.new pbl = product.product_build_lists.new
[:params, :main_script, :project, :project_version].each do |k| [:params, :main_script, :project, :project_version].each do |k|
pbl.send "#{k}=", product.send(k) pbl.send "#{k}=", product.send(k)

View File

@ -38,16 +38,16 @@ class ProductBuildList < ActiveRecord::Base
belongs_to :user belongs_to :user
# see: Issue #6 # see: Issue #6
before_validation lambda { self.arch_id = Arch.find_by_name('x86_64').id }, :on => :create before_validation lambda { self.arch_id = Arch.find_by_name('x86_64').id }, on: :create
# field "not_delete" can be changed only if build has been completed # field "not_delete" can be changed only if build has been completed
before_validation lambda { self.not_delete = false unless build_completed?; true } before_validation lambda { self.not_delete = false unless build_completed?; true }
validates :product_id, validates :product_id,
:status, :status,
:project_id, :project_id,
:main_script, :main_script,
:arch_id, :presence => true :arch_id, presence: true
validates :status, :inclusion => { :in => STATUSES } validates :status, inclusion: { in: STATUSES }
validates :main_script, :params, :length => { :maximum => 255 } validates :main_script, :params, length: { maximum: 255 }
attr_accessor :base_url attr_accessor :base_url
attr_accessible :status, attr_accessible :status,
@ -65,45 +65,45 @@ class ProductBuildList < ActiveRecord::Base
scope :default_order, order("#{table_name}.updated_at DESC") scope :default_order, order("#{table_name}.updated_at DESC")
scope :for_status, lambda {|status| where(:status => status) } scope :for_status, lambda {|status| where(status: status) }
scope :for_user, lambda { |user| where(:user_id => user.id) } scope :for_user, lambda { |user| where(user_id: user.id) }
scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")} scope :scoped_to_product_name, lambda {|product_name| joins(:product).where('products.name LIKE ?', "%#{product_name}%")}
scope :recent, order("#{table_name}.updated_at DESC") scope :recent, order("#{table_name}.updated_at DESC")
scope :outdated, where(:not_delete => false). scope :outdated, where(not_delete: false).
where("(#{table_name}.created_at < ? AND #{table_name}.autostarted is TRUE) OR #{table_name}.created_at < ?", Time.now - LIVE_TIME, Time.now - MAX_LIVE_TIME) where("(#{table_name}.created_at < ? AND #{table_name}.autostarted is TRUE) OR #{table_name}.created_at < ?", Time.now - LIVE_TIME, Time.now - MAX_LIVE_TIME)
after_create :add_job_to_abf_worker_queue after_create :add_job_to_abf_worker_queue
before_destroy :can_destroy? before_destroy :can_destroy?
state_machine :status, :initial => :build_pending do state_machine :status, initial: :build_pending do
event :start_build do event :start_build do
transition :build_pending => :build_started transition build_pending: :build_started
end end
event :cancel do event :cancel do
transition [:build_pending, :build_started] => :build_canceling transition [:build_pending, :build_started] => :build_canceling
end end
after_transition :on => :cancel, :do => :cancel_job after_transition on: :cancel, do: :cancel_job
# :build_canceling => :build_canceled - canceling from UI # build_canceling: :build_canceled - canceling from UI
# :build_started => :build_canceled - canceling from worker by time-out (time_living has been expired) # build_started: :build_canceled - canceling from worker by time-out (time_living has been expired)
event :build_canceled do event :build_canceled do
transition [:build_canceling, :build_started] => :build_canceled transition [:build_canceling, :build_started] => :build_canceled
end end
# :build_canceling => :build_completed - Worker hasn't time to cancel building because build had been already completed # build_canceling: :build_completed - Worker hasn't time to cancel building because build had been already completed
event :build_success do event :build_success do
transition [:build_started, :build_canceling] => :build_completed transition [:build_started, :build_canceling] => :build_completed
end end
# :build_canceling => :build_failed - Worker hasn't time to cancel building because build had been already failed # build_canceling: :build_failed - Worker hasn't time to cancel building because build had been already failed
event :build_error do event :build_error do
transition [:build_started, :build_canceling] => :build_failed transition [:build_started, :build_canceling] => :build_failed
end end
HUMAN_STATUSES.each do |code,name| HUMAN_STATUSES.each do |code,name|
state name, :value => code state name, value: code
end end
end end
@ -120,7 +120,7 @@ class ProductBuildList < ActiveRecord::Base
end end
def event_log_message def event_log_message
{:product => product.name}.inspect {product: product.name}.inspect
end end
def self.human_status(status) def self.human_status(status)
@ -152,7 +152,7 @@ class ProductBuildList < ActiveRecord::Base
def abf_worker_args def abf_worker_args
file_name = "#{project.name}-#{commit_hash}" file_name = "#{project.name}-#{commit_hash}"
opts = default_url_options opts = default_url_options
opts.merge!({:user => user.authentication_token, :password => ''}) if user.present? opts.merge!({user: user.authentication_token, password: ''}) if user.present?
srcpath = url_helpers.archive_url( srcpath = url_helpers.archive_url(
project.owner, project.owner,
project.name, project.name,
@ -161,19 +161,19 @@ class ProductBuildList < ActiveRecord::Base
opts opts
) )
{ {
:id => id, id: id,
# TODO: remove comment # TODO: remove comment
# :srcpath => 'http://dl.dropbox.com/u/945501/avokhmin-test-iso-script-5d9b463d4e9c06ea8e7c89e1b7ff5cb37e99e27f.tar.gz', # srcpath: 'http://dl.dropbox.com/u/945501/avokhmin-test-iso-script-5d9b463d4e9c06ea8e7c89e1b7ff5cb37e99e27f.tar.gz',
:srcpath => srcpath, srcpath: srcpath,
:params => params, params: params,
:time_living => time_living, time_living: time_living,
:main_script => main_script, main_script: main_script,
:platform => { platform: {
:type => product.platform.distrib_type, type: product.platform.distrib_type,
:name => product.platform.name, name: product.platform.name,
:arch => arch.name arch: arch.name
}, },
:user => {:uname => user.try(:uname), :email => user.try(:email)} user: {uname: user.try(:uname), email: user.try(:email)}
} }
end end
end end

Some files were not shown because too many files have changed in this diff Show More