[#345] remove observers; use new labmda syntax

This commit is contained in:
Alexander Machehin 2014-03-11 13:39:25 +06:00
parent a81b5fc69e
commit a5f56bb835
56 changed files with 344 additions and 309 deletions

View File

@ -7,12 +7,12 @@ class ApplicationController < ActionController::Base
layout :layout_by_resource
# Hack to prevent token auth on all pages except atom feed:
prepend_before_filter lambda { redirect_to(new_user_session_path) if params[:token] && params[:token].is_a?(String) && params[:format] != 'atom'}
prepend_before_filter -> { redirect_to(new_user_session_path) if params[:token] && params[:token].is_a?(String) && params[:format] != 'atom'}
before_filter :set_locale
before_filter lambda { EventLog.current_controller = self },
before_filter -> { EventLog.current_controller = self },
only: [:create, :destroy, :open_id, :cancel, :publish, :change_visibility] # :update
after_filter lambda { EventLog.current_controller = nil }
after_filter -> { EventLog.current_controller = nil }
helper_method :get_owner

View File

@ -1,5 +1,5 @@
class Groups::MembersController < Groups::BaseController
before_filter lambda { authorize! :manage_members, @group }
before_filter -> { authorize! :manage_members, @group }
def index
end

View File

@ -1,6 +1,6 @@
class Projects::Git::BlobsController < Projects::Git::BaseController
before_filter :set_blob
before_filter lambda {authorize! :write, @project}, only: [:edit, :update]
before_filter -> {authorize! :write, @project}, only: [:edit, :update]
def show
end

View File

@ -1,10 +1,10 @@
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 -> {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
before_filter lambda { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, only: [:branch, :destroy]
before_filter -> { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, only: [:branch, :destroy]
skip_authorize_resource :project, only: [:destroy, :restore_branch, :create]
before_filter lambda { authorize!(:write, @project) }, only: [:destroy, :restore_branch, :create]
before_filter -> { authorize!(:write, @project) }, only: [:destroy, :restore_branch, :create]
def show
unless request.xhr?

View File

@ -8,13 +8,12 @@ class ActivityFeed < ActiveRecord::Base
belongs_to :user
serialize :data
default_scope order("#{table_name}.created_at DESC")
scope :outdated, offset(100)
default_scope { order created_at: :desc }
scope :outdated, -> { offset(100) }
self.per_page = 10
def partial
'home/partials/' + self.kind
end
end

View File

@ -1,4 +1,6 @@
class Advisory < ActiveRecord::Base
self.include_root_in_json = false
has_and_belongs_to_many :platforms
has_and_belongs_to_many :projects
has_many :build_lists
@ -13,14 +15,14 @@ class Advisory < ActiveRecord::Base
ID_STRING_TEMPLATE = 'ROSA-%<type>s-%<year>04s:%<id>04s'
TYPES = {'security' => 'SA', 'bugfix' => 'A'}
scope :search, lambda { |q|
scope :search, ->(q) {
q = q.to_s.strip
where("#{table_name}.advisory_id ILIKE :q OR #{table_name}.description ILIKE :q OR build_list_packages.fullname ILIKE :q", q: "%#{q}%").
joins(build_lists: :packages) if q.present?
}
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) }
default_scope order("#{table_name}.created_at DESC")
scope :search_by_id, ->(aid) { where("#{table_name}.advisory_id ILIKE ?", "%#{aid.to_s.strip}%") }
scope :by_update_type, ->(ut) { where(update_type: ut) }
default_scope { order(created_at: :desc) }
def to_param
advisory_id
@ -69,4 +71,3 @@ class Advisory < ActiveRecord::Base
end
end
Advisory.include_root_in_json = false

View File

@ -5,5 +5,5 @@ class Arch < ActiveRecord::Base
validates :name, presence: true, uniqueness: true
scope :recent, order("#{table_name}.name ASC")
scope :recent, -> { order(:name) }
end

View File

@ -6,14 +6,15 @@ class Avatar < ActiveRecord::Base
AVATAR_SIZES_HASH = {}.tap do |styles|
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
has_attached_file :avatar, styles: AVATAR_SIZES_HASH
validates_attachment_size :avatar, less_than_or_equal_to: MAX_AVATAR_SIZE
validates_attachment_content_type :avatar, content_type: /\Aimage/
validates_attachment_file_name :avatar, matches: [ /(png|jpe?g|gif|bmp|tif?f)\z/i ]
attr_accessible :avatar
end

View File

@ -2,7 +2,9 @@ class BuildList < ActiveRecord::Base
include Modules::Models::CommitAndVersion
include Modules::Models::FileStoreClean
include AbfWorker::ModelHelper
include Modules::Observers::ActivityFeed::BuildList
include Feed::BuildList
include BuildListObserver
include EventLoggable
belongs_to :project
belongs_to :arch
@ -37,22 +39,22 @@ class BuildList < ActiveRecord::Base
unless: Proc.new { |b| b.advisory.present? }
validates :update_type, inclusion: { in: RELEASE_UPDATE_TYPES, message: I18n.t('flash.build_list.frozen_platform') },
if: Proc.new { |b| b.advisory.present? }
validate lambda {
validate -> {
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
}
validate lambda {
validate -> {
errors.add(:build_for_platform, I18n.t('flash.build_list.wrong_build_for_platform')) unless build_for_platform.main?
}
validate lambda {
validate -> {
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 -> {
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 -> {
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 -> { self.include_repos = include_repos.uniq if include_repos.present? }, on: :create
before_validation :prepare_extra_repositories, on: :create
before_validation :prepare_extra_build_lists, on: :create
before_validation :prepare_extra_params, on: :create
@ -95,40 +97,45 @@ class BuildList < ActiveRecord::Base
STATUSES.freeze
HUMAN_STATUSES.freeze
scope :recent, order("#{table_name}.updated_at DESC")
scope :for_extra_build_lists, lambda {|ids, current_ability, save_to_platform|
scope :recent, -> { order(updated_at: :desc) }
scope :for_extra_build_lists, ->(ids, current_ability, save_to_platform) {
s = scoped
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
}
scope :for_status, lambda {|status| where(status: status) if status.present? }
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 :external_nodes, lambda { |type| where("#{table_name}.external_nodes = ?", type) }
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 :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_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_is_circle, lambda {|is_circle| where(is_circle: is_circle) }
scope :for_creation_date_period, lambda{|start_date, end_date|
scope :for_status, ->(status) { where(status: status) if status.present? }
scope :for_user, ->(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 :external_nodes, ->(type) { where("#{table_name}.external_nodes = ?", type) }
scope :oldest, -> { where("#{table_name}.updated_at < ?", Time.zone.now - 15.seconds) }
scope :for_platform, ->(platform) { where(build_for_platform_id: platform) }
scope :by_mass_build, ->(mass_build) { where(mass_build_id: mass_build) }
scope :scoped_to_arch, ->(arch) { where(arch_id: arch) if arch.present? }
scope :scoped_to_save_platform, ->(pl_id) { where(save_to_platform_id: pl_id) if pl_id.present? }
scope :scoped_to_project_version, ->(pr_version) { where(project_version: pr_version) if pr_version.present? }
scope :scoped_to_is_circle, ->(is_circle) { { where(is_circle: is_circle) }
scope :for_creation_date_period, ->(start_date, end_date) {
s = scoped
s = s.where(["#{table_name}.created_at >= ?", start_date]) if start_date
s = s.where(["#{table_name}.created_at <= ?", end_date]) if end_date
s
}
scope :for_notified_date_period, lambda{|start_date, end_date|
scope :for_notified_date_period, ->(start_date, end_date) {
s = scoped
s = s.where("#{table_name}.updated_at >= ?", start_date) if start_date.present?
s = s.where("#{table_name}.updated_at <= ?", end_date) if end_date.present?
s
}
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 :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 :scoped_to_project_name, ->(project_name) {
joins(:project).where('projects.name LIKE ?', "%#{project_name}%") if project_name.present?
}
scope :scoped_to_new_core, ->(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 :published_container, -> { where(container_status: BUILD_PUBLISHED) }
serialize :additional_repos
serialize :include_repos
@ -157,7 +164,7 @@ class BuildList < ActiveRecord::Base
after_transition on: [:published, :fail_publish, :build_error, :tests_failed], do: :notify_users
after_transition on: :build_success, do: :notify_users,
unless: lambda { |build_list| build_list.auto_publish? || build_list.auto_publish_into_testing? }
unless: -> { |build_list| build_list.auto_publish? || build_list.auto_publish_into_testing? }
event :place_build do
transition waiting_for_response: :build_pending

View File

@ -16,11 +16,11 @@ class BuildList::Package < ActiveRecord::Base
default_scope order("lower(#{table_name}.name) ASC, length(#{table_name}.name) ASC")
# Fetches only actual (last publised) packages.
scope :actual, where(actual: true)
scope :by_platform, lambda {|platform| where(platform_id: platform) }
scope :by_name, lambda {|name| where(name: name) }
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 :actual, -> { where(actual: true) }
scope :by_platform, ->(platform) { where(platform_id: platform) }
scope :by_name, ->(name) { where(name: name) }
scope :by_package_type, ->(type) { where(package_type: type) }
scope :like_name, ->(name) { where("#{table_name}.name ILIKE ?", "%#{name}%") if name.present? }
before_create :set_epoch

View File

@ -1,30 +0,0 @@
class BuildListObserver < ActiveRecord::Observer
observe :build_list
def before_update(record)
if record.status_changed?
record.started_at = Time.now if record.status == BuildList::BUILD_STARTED
if [BuildList::BUILD_ERROR,
BuildList::SUCCESS,
BuildList::BUILD_CANCELING,
BuildList::TESTS_FAILED,
BuildList::BUILD_CANCELED].include? record.status
# stores time interval beetwin build start and finish in seconds
record.duration = record.current_duration if record.started_at
if record.status == BuildList::SUCCESS
# Update project average build time
begin
statistic = record.project.project_statistics.find_or_create_by_arch_id(record.arch_id)
rescue ActiveRecord::RecordNotUnique
retry
end
build_count = statistic.build_count.to_i
new_av_time = ( statistic.average_build_time * build_count + record.duration.to_i ) / ( build_count + 1 )
statistic.update_attributes(average_build_time: new_av_time, build_count: build_count + 1)
end
end
end
end # before_update
end

View File

@ -1,5 +1,5 @@
class Comment < ActiveRecord::Base
include Modules::Observers::ActivityFeed::Comment
include ActivityFeed::Comment
# regexp take from http://code.google.com/p/concerto-platform/source/browse/v3/cms/lib/CodeMirror/mode/gfm/gfm.js?spec=svn861&r=861#71
# User/Project#Num
@ -14,10 +14,10 @@ class Comment < ActiveRecord::Base
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)}
default_scope order("#{table_name}.created_at")
scope :for_commit, ->(c) { where(commentable_id: c.id.hex, commentable_type: c.class) }
default_scope { order(:created_at) }
after_create :subscribe_on_reply, unless: lambda {|c| c.commit_comment?}
after_create :subscribe_on_reply, unless: -> {|c| c.commit_comment?}
after_create :subscribe_users
attr_accessible :body, :data

View File

@ -0,0 +1,36 @@
module BuildListObserver
extend ActiveSupport::Concern
included do
before_update :update_average_build_time
end
private
def update_average_build_time
if status_changed?
started_at = Time.now if status == BUILD_STARTED
if [BUILD_ERROR,
SUCCESS,
BUILD_CANCELING,
TESTS_FAILED,
BUILD_CANCELED].include? status
# stores time interval beetwin build start and finish in seconds
duration = current_duration if started_at
if status == SUCCESS
# Update project average build time
begin
statistic = project.project_statistics.find_or_create_by_arch_id(arch_id)
rescue ActiveRecord::RecordNotUnique
retry
end
build_count = statistic.build_count.to_i
new_av_time = ( statistic.average_build_time * build_count + record.duration.to_i ) / ( build_count + 1 )
statistic.update_attributes(average_build_time: new_av_time, build_count: build_count + 1)
end
end
end
end
end

View File

@ -0,0 +1,32 @@
module EventLoggable
extend ActiveSupport::Concern
included do
after_create :log_creation_event
after_destroy :log_destroying_event
end
private
def log_creation_event
ActiveSupport::Notifications.instrument(self.class.name, eventable: self)
end
def log_before_update
case self.class.to_s
when 'BuildList'
if status_changed? and [BuildList::BUILD_CANCELED, BuildList::BUILD_PUBLISHED].include?(status)
ActiveSupport::Notifications.instrument("event_log.observer", eventable: self)
end
when 'Platform'
if self.visibility_changed?
ActiveSupport::Notifications.instrument "event_log.observer", eventable: self,
message: I18n.t("activeself.attributes.platform.visibility_types.#{visibility}")
end
end
end
def destroying_event
ActiveSupport::Notifications.instrument(self.class.name, eventable: self)
end
end

View File

@ -1,4 +1,4 @@
module Modules::Observers::ActivityFeed::BuildList
module Feed::BuildList
extend ActiveSupport::Concern
included do

View File

@ -1,4 +1,4 @@
module Modules::Observers::ActivityFeed::Comment
module Feed::Comment
extend ActiveSupport::Concern
included do

View File

@ -1,4 +1,4 @@
module Modules::Observers::ActivityFeed::Git
module Feed::Git
def self.create_notifications(record)

View File

@ -1,4 +1,4 @@
module Modules::Observers::ActivityFeed::Issue
module Feed::Issue
extend ActiveSupport::Concern
included do

View File

@ -1,4 +1,4 @@
module Modules::Observers::ActivityFeed::User
module Feed::User
extend ActiveSupport::Concern
included do

View File

@ -4,8 +4,8 @@ class EventLog < ActiveRecord::Base
# self.per_page = 1
scope :eager_loading, preload(:user)
scope :default_order, order("#{table_name}.id DESC") # order('created_at DESC')
scope :eager_loading, -> { preload(:user) }
scope :default_order -> { order(id: :desc) }
before_create do
self.user_name = user.try(:uname) || 'guest'

View File

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

View File

@ -8,6 +8,8 @@ class Feedback
include ActiveModel::MassAssignmentSecurity
extend ActiveModel::Naming
self.include_root_in_json = false
attr_accessor :name, :email, :subject, :message
attr_accessible :name, :email, :subject, :message
@ -99,6 +101,4 @@ class Feedback
perform_validation = options[:validate] != false
perform_validation ? valid?(options[:context]) : true
end
end
Feedback.include_root_in_json = false

View File

@ -8,7 +8,7 @@ class FlashNotify < ActiveRecord::Base
validates :status, inclusion: {in: STATUSES}
validates :body_ru, :body_en, :status, presence: true
scope :published, where(published: true)
scope :published, -> { where(published: true) }
def hash_id
@digest ||= Digest::MD5.hexdigest("#{self.id}-#{self.updated_at}")

View File

@ -1,12 +1,13 @@
class GitHook
include Feed::Git
include Resque::Plugins::Status
ZERO = '0000000000000000000000000000000000000000'
@queue = :hook
attr_reader :repo, :newrev, :oldrev, :newrev_type, :oldrev_type, :refname,
:change_type, :rev, :rev_type, :refname_type, :owner, :project, :user, :message
include Resque::Plugins::Status
def self.perform(*options)
self.process(*options)
end
@ -64,7 +65,7 @@ class GitHook
end
def self.process(*args)
Modules::Observers::ActivityFeed::Git.create_notifications(args.size > 1 ? GitHook.new(*args) : args.first)
create_notifications(args.size > 1 ? GitHook.new(*args) : args.first)
end
def find_user(user)

View File

@ -1,4 +1,7 @@
class Group < Avatar
include Modules::Models::ActsLikeMember
include Modules::Models::PersonalRepository
belongs_to :owner, class_name: 'User'
has_many :relations, as: :actor, dependent: :destroy, dependent: :destroy
@ -15,10 +18,14 @@ class Group < Avatar
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? }
scope :opened, where('1=1')
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_and_writer, lambda {|actor| joins(:actors).where(:'relations.role' => ['admin', 'writer'], :'relations.actor_id' => actor.id, :'relations.actor_type' => 'User')}
scope :opened, -> { scoped }
scope :by_owner, ->(owner) { where(owner_id: owner.id) }
scope :by_admin, ->(admin) {
joins(:actors).where('relations.role' => 'admin', 'relations.actor_id' => admin.id, 'relations.actor_type' => 'User')
}
scope :by_admin_and_writer, ->(actor) {
joins(:actors).where('relations.role' => ['admin', 'writer'], 'relations.actor_id' => actor.id, 'relations.actor_type' => 'User')
}
attr_accessible :uname, :description
attr_readonly :uname
@ -27,10 +34,6 @@ class Group < Avatar
after_create :add_owner_to_members
include Modules::Models::ActsLikeMember
include Modules::Models::PersonalRepository
# include Modules::Models::Owner
def self.can_own_project(user)
(by_owner(user) | by_admin_and_writer(user))
end

View File

@ -12,7 +12,7 @@ class Hook < ActiveRecord::Base
serialize :data, Hash
scope :for_name, lambda {|name| where(name: name) if name.present? }
scope :for_name, ->(name) { where(name: name) if name.present? }
def receive_issues(issue, action)
pull = issue.pull_request

View File

@ -1,5 +1,5 @@
class Issue < ActiveRecord::Base
include Modules::Observers::ActivityFeed::Issue
include Feed::Issue
STATUSES = ['open', 'closed']
belongs_to :project
@ -22,15 +22,17 @@ class Issue < ActiveRecord::Base
attr_accessible :labelings_attributes, :title, :body, :assignee_id
accepts_nested_attributes_for :labelings, allow_destroy: true
scope :opened, where(status: 'open')
scope :closed, where(status: 'closed')
scope :opened, -> { where(status: 'open') }
scope :closed, -> { where(status: 'closed') }
scope :needed_checking, where(issues: {status: ['open', 'blocked', 'ready', 'already']})
scope :not_closed_or_merged, needed_checking
scope :closed_or_merged, where(issues: {status: ['closed', 'merged']})
scope :needed_checking, -> { where(issues: {status: ['open', 'blocked', 'ready', 'already']}) }
scope :not_closed_or_merged, -> { needed_checking }
scope :closed_or_merged, -> { where(issues: {status: ['closed', 'merged']}) }
# 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 :without_pull_requests, where('NOT EXISTS (select null from pull_requests as pr where pr.issue_id = issues.id)')
scope :search, ->(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)')
}
def assign_uname
assignee.uname if assignee

View File

@ -1,5 +1,4 @@
class Labeling < ActiveRecord::Base
belongs_to :issue
belongs_to :label
end

View File

@ -7,9 +7,9 @@ class MassBuild < ActiveRecord::Base
serialize :extra_repositories, Array
serialize :extra_build_lists, Array
scope :recent, order("#{table_name}.created_at DESC")
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 :recent, -> { order(created_at: :desc) }
scope :by_platform, ->(platform) { where(save_to_platform_id: platform.id) }
scope :outdated, -> { where("#{table_name}.created_at < ?", Time.now + 1.day - BuildList::MAX_LIVE_TIME) }
attr_accessor :arches
attr_accessible :arches, :auto_publish, :projects_list, :build_for_platform_id,

View File

@ -4,6 +4,8 @@ class Platform < ActiveRecord::Base
include Modules::Models::FileStoreClean
include Modules::Models::RegenerationStatus
include Modules::Models::Owner
include EventLoggable
AUTOMATIC_METADATA_REGENERATIONS = %w(day week)
VISIBILITIES = %w(open hidden)
@ -34,12 +36,12 @@ class Platform < ActiveRecord::Base
validates :automatic_metadata_regeneration, inclusion: {in: AUTOMATIC_METADATA_REGENERATIONS}, allow_blank: true
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']}
validate lambda {
validate -> {
if released_was && !released
errors.add(:released, I18n.t('flash.platform.released_status_can_not_be_changed'))
end
}
validate lambda {
validate -> {
if personal? && (owner_id_changed? || owner_type_changed?)
errors.add :owner, I18n.t('flash.platform.owner_can_not_be_changed')
end
@ -51,25 +53,23 @@ class Platform < ActiveRecord::Base
after_update :freeze_platform_and_update_repos
after_update :update_owner_relation
after_create lambda { symlink_directory unless hidden? }
after_destroy lambda { remove_symlink_directory unless hidden? }
after_create -> { symlink_directory unless hidden? }
after_destroy -> { remove_symlink_directory unless hidden? }
scope :search_order, order("CHAR_LENGTH(#{table_name}.name) ASC")
scope :search, lambda {|q| where("#{table_name}.name ILIKE ?", "%#{q.to_s.strip}%")}
scope :by_visibilities, lambda {|v| where(visibility: v)}
scope :opened, where(visibility: 'open')
scope :hidden, where(visibility: 'hidden')
scope :by_type, lambda {|type| where(platform_type: type) if type.present?}
scope :main, by_type('main')
scope :personal, by_type('personal')
scope :waiting_for_regeneration, where(status: WAITING_FOR_REGENERATION)
scope :search_order, -> { order(:name) }
scope :search, ->(q) { where("#{table_name}.name ILIKE ?", "%#{q.to_s.strip}%") }
scope :by_visibilities, ->(v) { where(visibility: v) }
scope :opened, -> { where(visibility: 'open') }
scope :hidden, -> { where(visibility: 'hidden') }
scope :by_type, ->(type) { where(platform_type: type) if type.present? }
scope :main, -> { by_type('main') }
scope :personal, -> { by_type('personal') }
scope :waiting_for_regeneration, -> { where(status: WAITING_FOR_REGENERATION) }
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, :automatic_metadata_regeneration
attr_readonly :name, :distrib_type, :parent_platform_id, :platform_type
include Modules::Models::Owner
state_machine :status, initial: :ready do
after_transition on: :ready, do: :notify_users
@ -79,7 +79,7 @@ class Platform < ActiveRecord::Base
end
event :regenerate do
transition ready: :waiting_for_regeneration, if: lambda{ |p| p.main? }
transition ready: :waiting_for_regeneration, if: -> { |p| p.main? }
end
event :start_regeneration do

View File

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

View File

@ -1,15 +1,7 @@
class PlatformContent
# ------------------
# *** ATTRIBUTES ***
# ------------------
attr_reader :path
# ---------------
# *** METHODS ***
# ---------------
def initialize(platform, path)
@platform, @path = platform, path
end
@ -61,10 +53,6 @@ class PlatformContent
"#{APP_CONFIG['downloads_url']}/#{@platform.name}#{suffix}"
end
# ---------------------
# *** CLASS METHODS ***
# ---------------------
def self.find_by_platform(platform, path, term)
# Strip out the non-ascii character
term = (term || '').strip.gsub(/[\\\/]+/, '')

View File

@ -1,6 +1,7 @@
class Product < ActiveRecord::Base
include Modules::Models::TimeLiving
include Modules::Models::Autostart
include EventLoggable
belongs_to :platform
belongs_to :project
@ -10,7 +11,7 @@ class Product < ActiveRecord::Base
validates :project_id, presence: true
validates :main_script, :params, length: { maximum: 255 }
scope :recent, order("#{table_name}.name ASC")
scope :recent, -> { order(:name) }
attr_accessible :name,
:description,

View File

@ -4,6 +4,8 @@ class ProductBuildList < ActiveRecord::Base
include Modules::Models::FileStoreClean
include Modules::Models::UrlHelper
include AbfWorker::ModelHelper
include EventLoggable
delegate :url_helpers, to: 'Rails.application.routes'
LIVE_TIME = 2.week # for autostart
@ -38,9 +40,9 @@ class ProductBuildList < ActiveRecord::Base
belongs_to :user
# see: Issue #6
before_validation lambda { self.arch_id = Arch.find_by_name('x86_64').id }, on: :create
before_validation -> { self.arch_id = Arch.find_by_name('x86_64').id }, on: :create
# 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 -> { self.not_delete = false unless build_completed?; true }
validates :product_id,
:status,
:project_id,
@ -64,13 +66,16 @@ class ProductBuildList < ActiveRecord::Base
serialize :results, Array
scope :default_order, order("#{table_name}.updated_at DESC")
scope :for_status, lambda {|status| where(status: status) }
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 :recent, order("#{table_name}.updated_at DESC")
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)
scope :default_order, -> { order(updated_at: desc) }
scope :for_status, ->(status) { where(status: status) }
scope :for_user, ->(user) { where(user_id: user.id) }
scope :scoped_to_product_name, ->(product_name) { joins(:product).where('products.name LIKE ?', "%#{product_name}%") }
scope :recent, -> { order(updated_at: desc) }
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)
}
after_create :add_job_to_abf_worker_queue
before_destroy :can_destroy?

View File

@ -1,12 +1,17 @@
class Project < ActiveRecord::Base
include Modules::Models::Autostart
include Modules::Models::Owner
include Modules::Models::Git
include Modules::Models::Wiki
include Modules::Models::UrlHelper
include EventLoggable
VISIBILITIES = ['open', 'hidden']
MAX_OWN_PROJECTS = 32000
NAME_REGEXP = /[\w\-\+\.]+/
belongs_to :owner, polymorphic: true, counter_cache: :own_projects_count
belongs_to :maintainer, class_name: "User"
belongs_to :maintainer, class_name: 'User'
has_many :issues, dependent: :destroy
has_many :pull_requests, dependent: :destroy, foreign_key: 'to_project_id'
@ -25,7 +30,7 @@ class Project < ActiveRecord::Base
has_many :collaborators, through: :relations, source: :actor, source_type: 'User'
has_many :groups, through: :relations, source: :actor, source_type: 'Group'
has_many :packages, class_name: "BuildList::Package", dependent: :destroy
has_many :packages, class_name: 'BuildList::Package', dependent: :destroy
has_and_belongs_to_many :advisories # should be without dependent: :destroy
validates :name, uniqueness: {scope: [:owner_id, :owner_type], case_sensitive: false},
@ -53,49 +58,43 @@ class Project < ActiveRecord::Base
:autostart_status
attr_readonly :owner_id, :owner_type
scope :recent, order("lower(#{table_name}.name) ASC")
scope :search_order, order("CHAR_LENGTH(#{table_name}.name) ASC")
scope :search, lambda {|q|
scope :recent, -> { order(:name) }
scope :search_order, -> { order('CHAR_LENGTH(projects.name) ASC') }
scope :search, ->(q) {
q = q.to_s.strip
by_name("%#{q}%").search_order if q.present?
}
scope :by_name, lambda {|name| where("#{table_name}.name ILIKE ?", name) if name.present?}
scope :by_owner_and_name, lambda { |*params|
scope :by_name, ->(name) { where('projects.name ILIKE ?', name) if name.present? }
scope :by_owner_and_name, ->(*params) {
term = params.map(&:strip).join('/').downcase
where("lower(concat(owner_uname, '/', name)) ILIKE ?", "%#{term}%") if term.present?
where('lower(concat(owner_uname, '/', name)) ILIKE ?', "%#{term}%") if term.present?
}
scope :by_visibilities, lambda {|v| where(visibility: v)}
scope :opened, where(visibility: 'open')
scope :package, where(is_package: true)
scope :addable_to_repository, lambda { |repository_id| where %Q(
projects.id NOT IN (
SELECT
ptr.project_id
FROM
project_to_repositories AS ptr
WHERE (ptr.repository_id = #{ repository_id })
)
) }
scope :by_owners, lambda { |group_owner_ids, user_owner_ids|
where("(#{table_name}.owner_id in (?) AND #{table_name}.owner_type = 'Group') OR (#{table_name}.owner_id in (?) AND #{table_name}.owner_type = 'User')", group_owner_ids, user_owner_ids)
scope :by_visibilities, ->(v) { where(visibility: v) }
scope :opened, -> { where(visibility: 'open') }
scope :package, -> { where(is_package: true) }
scope :addable_to_repository, ->(repository_id) {
where('projects.id NOT IN (
SELECT ptr.project_id
FROM project_to_repositories AS ptr
WHERE ptr.repository_id = ?)', repository_id)
}
scope :by_owners, ->(group_owner_ids, user_owner_ids) {
where("projects.owner_id in (?) AND projects.owner_type = 'Group') OR
(projects.owner_id in (?) AND projects.owner_type = 'User')", group_owner_ids, user_owner_ids)
}
before_validation :truncate_name, on: :create
before_save lambda { self.owner_uname = owner.uname if owner_uname.blank? || owner_id_changed? || owner_type_changed? }
before_save -> { self.owner_uname = owner.uname if owner_uname.blank? || owner_id_changed? || owner_type_changed? }
before_create :set_maintainer
after_save :attach_to_personal_repository
after_update :set_new_git_head
after_update lambda { update_path_to_project(name_was) }, if: :name_changed?
after_update -> { update_path_to_project(name_was) }, if: :name_changed?
before_save :ensure_authentication_token
has_ancestry orphan_strategy: :rootify #:adopt not available yet
attr_accessor :url, :srpms_list, :mass_import, :add_to_repository_id
include Modules::Models::Owner
include Modules::Models::Git
include Modules::Models::Wiki
include Modules::Models::UrlHelper
class << self
def find_by_owner_and_name(owner_name, project_name)
where(owner_uname: owner_name, name: project_name).first ||

View File

@ -5,7 +5,7 @@ class ProjectImport < ActiveRecord::Base
validates :name, uniqueness: {scope: :platform_id, case_sensitive: false}
validates :name, :platform_id, :version, presence: true
scope :by_name, lambda {|name| where("#{table_name}.name ILIKE ?", name)}
scope :by_name, ->(name) { where("#{table_name}.name ILIKE ?", name) }
after_initialize lambda {|r| r.file_mtime ||= Time.current - 10.years } # default
after_initialize -> {|r| r.file_mtime ||= Time.current - 10.years } # default
end

View File

@ -11,14 +11,9 @@ class ProjectTag < ActiveRecord::Base
validates :project_id, :commit_id, :sha1, :tag_name, :format_id, presence: true
validates :project_id, uniqueness: {scope: [:tag_name, :format_id]}
attr_accessible :project_id,
:commit_id,
:sha1,
:tag_name,
:format_id
attr_accessible :project_id, :commit_id, :sha1, :tag_name, :format_id
def sha1_of_file_store_files
[sha1]
end
end

View File

@ -6,13 +6,14 @@ class ProjectToRepository < ActiveRecord::Base
delegate :path, to: :project
scope :autostart_enabled, lambda { where("autostart_options -> 'enabled' = 'true'") }
scope :autostart_enabled, -> { where("autostart_options -> 'enabled' = 'true'") }
after_destroy lambda { project.destroy_project_from_repository(repository) }, unless: lambda {Thread.current[:skip]}
after_destroy -> { project.destroy_project_from_repository(repository) }, unless: -> { Thread.current[:skip] }
validate :one_project_in_platform_repositories, on: :create
serialize :autostart_options, ActiveRecord::Coders::Hstore
AUTOSTART_OPTIONS.each do |field|
store_accessor :autostart_options, field
end
@ -28,7 +29,8 @@ class ProjectToRepository < ActiveRecord::Base
protected
def one_project_in_platform_repositories
errors.add(:base, I18n.t('activerecord.errors.project_to_repository.project')) if Project.joins(repositories: :platform).
where('platforms.id = ?', repository.platform_id).by_name(project.name).exists?
if Project.joins(repositories: :platform).where('platforms.id = ?', repository.platform_id).by_name(project.name).exists?
errors.add(:base, I18n.t('activerecord.errors.project_to_repository.project'))
end
end
end

View File

@ -7,7 +7,7 @@ class PullRequest < ActiveRecord::Base
:created_at, :updated_at, :comments, :status=, to: :issue, allow_nil: true
validates :from_project, :to_project, presence: true
validate :uniq_merge, if: Proc.new { |pull| pull.to_project.present? }
validate :uniq_merge, if: -> { |pull| pull.to_project.present? }
validates_each :from_ref, :to_ref do |record, attr, value|
check_ref record, attr, value
end
@ -19,9 +19,9 @@ class PullRequest < ActiveRecord::Base
accepts_nested_attributes_for :issue
attr_accessible :issue_attributes, :to_ref, :from_ref
scope :needed_checking, includes(:issue).where(issues: {status: ['open', 'blocked', 'ready']})
scope :not_closed_or_merged, needed_checking
scope :closed_or_merged, where(issues: {status: ['closed', 'merged']})
scope :needed_checking, -> { includes(:issue).where(issues: {status: ['open', 'blocked', 'ready']}) }
scope :not_closed_or_merged, -> { needed_checking }
scope :closed_or_merged, -> { where(issues: {status: ['closed', 'merged']}) }
state_machine :status, initial: :open do
event :ready do

View File

@ -1,12 +1,13 @@
class RegisterRequest < ActiveRecord::Base
default_scope order('created_at ASC')
default_scope { order(:created_at) }
scope :rejected, where(rejected: true)
scope :approved, where(approved: true)
scope :unprocessed, where(approved: false, rejected: false)
scope :rejected, -> { where(rejected: true) }
scope :approved, -> { where(approved: true) }
scope :unprocessed, -> { where(approved: false, rejected: false) }
validates :email, presence: true, uniqueness: {case_sensitive: false}, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }
validates :email, presence: true, uniqueness: {case_sensitive: false},
format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }
# before_create :generate_token
before_update :invite_approve_notification

View File

@ -1,17 +1,20 @@
class Relation < ActiveRecord::Base
ROLES = %w[reader writer admin]
belongs_to :target, polymorphic: true
belongs_to :actor, polymorphic: true, touch: true
ROLES = %w[reader writer admin]
validates :role, inclusion: {in: ROLES}
# validate { errors.add(:actor, :taken) if Relation.where(actor_type: self.actor_type, actor_id: self.actor_id).present? }
before_validation :add_default_role
scope :by_user_through_groups, lambda {|u| where("actor_type = 'User' AND actor_id = ? OR actor_type = 'Group' AND actor_id IN (?)", u.id, u.group_ids)}
scope :by_actor, lambda {|obj| where(actor_id: obj.id, actor_type: obj.class.to_s)}
scope :by_target, lambda {|tar| where(target_id: tar.id, target_type: tar.class.to_s)}
scope :by_role, lambda {|role| where(role: role)}
scope :by_user_through_groups, ->(u) {
where("actor_type = 'User' AND actor_id = ? OR actor_type = 'Group' AND actor_id IN (?)", u.id, u.group_ids)
}
scope :by_actor, ->(obj) { where(actor_id: obj.id, actor_type: obj.class.to_s) }
scope :by_target, ->(tar) { where(target_id: tar.id, target_type: tar.class.to_s) }
scope :by_role, ->(role) { where(role: role) }
def self.create_with_role(actor, target, role)
r = self.new

View File

@ -2,6 +2,8 @@ class Repository < ActiveRecord::Base
extend FriendlyId
friendly_id :name
include EventLoggable
LOCK_FILE_NAMES = {sync: '.sync.lock', repo: '.repo.lock'}
SORT = {'base' => 1, 'main' => 2, 'contrib' => 3, 'non-free' => 4, 'restricted' => 5}
@ -19,10 +21,11 @@ class Repository < ActiveRecord::Base
has_many :build_lists, foreign_key: :save_to_repository_id, dependent: :destroy
validates :description, presence: true
validates :name, uniqueness: {scope: :platform_id, case_sensitive: false}, presence: true, format: {with: /\A[a-z0-9_\-]+\z/}
validates :name, uniqueness: {scope: :platform_id, case_sensitive: false}, presence: true,
format: {with: /\A[a-z0-9_\-]+\z/}
scope :recent, order("#{table_name}.name ASC")
scope :main, lambda { where(name: %w(main base)) }
scope :recent, -> { order(:name) }
scope :main, -> { where(name: %w(main base)) }
before_destroy :detele_directory

View File

@ -33,10 +33,10 @@ class RepositoryStatus < ActiveRecord::Base
attr_accessible :platform_id, :repository_id
scope :platform_ready, where(platforms: {status: READY}).joins(:platform)
scope :for_regeneration, where(status: WAITING_FOR_REGENERATION)
scope :for_resign, where(status: [WAITING_FOR_RESIGN, WAITING_FOR_RESIGN_AND_REGENERATION])
scope :not_ready, where('repository_statuses.status != ?', READY)
scope :platform_ready, -> { where(platforms: {status: READY}).joins(:platform) }
scope :for_regeneration, -> { where(status: WAITING_FOR_REGENERATION) }
scope :for_resign, -> { where(status: [WAITING_FOR_RESIGN, WAITING_FOR_RESIGN_AND_REGENERATION]) }
scope :not_ready, -> { where('repository_statuses.status != ?', READY) }
state_machine :status, initial: :ready do
event :ready do
@ -80,5 +80,4 @@ class RepositoryStatus < ActiveRecord::Base
state name, value: code
end
end
end

View File

@ -29,5 +29,4 @@ class RpmBuildNode < Ohm::Model
end
{ systems: systems, others: others, busy: busy }
end
end

View File

@ -7,7 +7,7 @@ class SshKey < ActiveRecord::Base
belongs_to :user
attr_accessible :key, :name
before_validation lambda { self.key = key.strip if key.present? }
before_validation -> { self.key = key.strip if key.present? }
before_validation :set_fingerprint
validates :name, length: {maximum: 255}

View File

@ -6,8 +6,8 @@ class Token < ActiveRecord::Base
validates :creator_id, :subject_id, :subject_type, presence: true
validates :authentication_token, presence: true, uniqueness: { case_sensitive: true }
default_scope order("#{table_name}.created_at desc")
scope :by_active, where(status: 'active')
default_scope { order(created_at: :desc) }
scope :by_active, -> { where(status: 'active') }
before_validation :generate_token, on: :create

View File

@ -1,11 +1,16 @@
class User < Avatar
include Modules::Models::PersonalRepository
include Modules::Models::ActsLikeMember
include Feed::User
include EventLoggable
ROLES = ['', 'admin', 'banned', 'tester']
EXTENDED_ROLES = ROLES | ['system']
LANGUAGES_FOR_SELECT = [['Russian', 'ru'], ['English', 'en']]
LANGUAGES = LANGUAGES_FOR_SELECT.map(&:last)
devise :database_authenticatable, :registerable, :omniauthable, :token_authenticatable,# :encryptable, :timeoutable
:recoverable, :rememberable, :validatable, :lockable, :confirmable#, :reconfirmable, :trackable
devise :database_authenticatable, :registerable, :omniauthable,
:recoverable, :rememberable, :validatable, :lockable, :confirmable
devise :omniauthable, omniauth_providers: [:facebook, :google_oauth2, :github]
has_one :notifier, class_name: 'SettingsNotifier', dependent: :destroy #:notifier
@ -44,23 +49,19 @@ class User < Avatar
attr_readonly :uname
attr_accessor :login
scope :opened, where('users.role != \'system\' OR users.role IS NULL')
scope :real, where(role: ['', nil])
scope :opened, -> { where('users.role != \'system\' OR users.role IS NULL') }
scope :real, -> { where(role: ['', nil]) }
EXTENDED_ROLES.select {|type| type.present?}.each do |type|
scope type.to_sym, where(role: type)
scope type.to_sym, -> { where(role: type) }
end
scope :member_of_project, lambda {|item|
where "#{table_name}.id IN (?)", item.members.map(&:id).uniq
scope :member_of_project, ->(item) {
where 'users.id IN (?)', item.members.map(&:id).uniq
}
after_create lambda { self.create_notifier unless self.system? }
after_create -> { self.create_notifier unless self.system? }
before_create :ensure_authentication_token
include Modules::Models::PersonalRepository
include Modules::Models::ActsLikeMember
include Modules::Observers::ActivityFeed::User
def admin?
role == 'admin'
end
@ -157,6 +158,12 @@ class User < Avatar
end
end
def ensure_authentication_token
if authentication_token.blank?
self.authentication_token = generate_authentication_token
end
end
protected
def target_roles target
@ -173,4 +180,11 @@ class User < Avatar
roles.map(&:role).uniq
end
def generate_authentication_token
loop do
token = Devise.friendly_token
break token unless User.where(authentication_token: token).first
end
end
end

View File

@ -3,12 +3,17 @@ require File.expand_path('../boot', __FILE__)
require 'rails/all'
require './lib/api_defender'
# Prevent deprecation warning
I18n.config.enforce_available_locales = true
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module Rosa
class Application < Rails::Application
config.i18n.enforce_available_locales = true
# Rate limit
config.middleware.insert_after Rack::Lock, ApiDefender
@ -27,9 +32,6 @@ module Rosa
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
config.active_record.observers = :event_log_observer, :build_list_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
@ -50,7 +52,5 @@ module Rosa
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
I18n.enforce_available_locales = false
end
end

View File

@ -204,4 +204,6 @@ Devise.setup do |config|
# manager.intercept_401 = false
# manager.default_strategies(:scope => :user).unshift :some_external_strategy
# end
config.secret_key = '4a8a8e28e63a3d1f4ec3be11df2f6d40e7baa99bbd6da601622150c99cb9d77f98c1baed3e5871c646b12738d07e6e76d5bb537ef407a02e4ca6de579c0e8a57'
end

View File

@ -132,7 +132,9 @@ Rosa::Application.routes.draw do
authenticated do
root to: 'home#activity'
end
root to: 'home#root'
unauthenticated do
root to: 'home#root', as: :authenticated_root
end
else
root to: 'home#activity'
end
@ -179,7 +181,7 @@ Rosa::Application.routes.draw do
end
resources :contents, only: [:index]
match '/contents/*path' => 'contents#index', format: false
get '/contents/*path' => 'contents#index', format: false
resources :mass_builds, only: [:create, :new, :index] do
member do
@ -363,10 +365,10 @@ Rosa::Application.routes.draw do
get '/tags' => "git/trees#tags", as: :tags
# Branches
get '/branches' => "git/trees#branches", as: :branches
get '/branches/:treeish' => "git/trees#branches", as: :branch
delete '/branches/:treeish' => "git/trees#destroy", as: :branch
put '/branches/:treeish' => "git/trees#restore_branch", as: :branch
post '/branches' => "git/trees#create", as: :branches
get '/branches/:treeish' => "git/trees#branches", as: :treeish_branch
delete '/branches/:treeish' => "git/trees#destroy", as: :destroy_branch
put '/branches/:treeish' => "git/trees#restore_branch", as: :restore_branch
post '/branches' => "git/trees#create", as: :create_branch
# Commits
get '/commits/:treeish(/*path)' => "git/commits#index", as: :commits, format: false
get '/commit/:id(.:format)' => "git/commits#show", as: :commit
@ -402,12 +404,12 @@ Rosa::Application.routes.draw do
get '/' => 'users/profile#show', as: :user
end
constraints Rosa::Constraints::Owner.new(Group, true) do
get '/' => 'groups/profile#show', as: :group
#get '/' => 'groups/profile#show', as: :group
end
end
# As of Rails 3.0.1, using rescue_from in your ApplicationController to
# recover from a routing error is broken!
# see: https://rails.lighthouseapp.com/projects/8994/tickets/4444-can-no-longer-rescue_from-actioncontrollerroutingerror
match '*a', to: 'application#render_404'
get '*a', to: 'application#render_404'
end

View File

@ -4,7 +4,7 @@ module Modules
extend ActiveSupport::Concern
included do
scope :not_member_of, lambda {|item|
scope :not_member_of, -> {|item|
where("
#{table_name}.id NOT IN (
SELECT relations.actor_id
@ -17,10 +17,10 @@ module Modules
)
")
}
scope :search_order, order("CHAR_LENGTH(uname) ASC")
scope :without, lambda {|a| where("#{table_name}.id NOT IN (?)", a)}
scope :by_uname, lambda {|n| where("#{table_name}.uname ILIKE ?", n)}
scope :search, lambda {|q| by_uname("%#{q.to_s.strip}%")}
scope :search_order, { order('CHAR_LENGTH(#{table_name}.uname) ASC') }
scope :without, ->(a) { where("#{table_name}.id NOT IN (?)", a) }
scope :by_uname, ->(n) { where("#{table_name}.uname ILIKE ?", n) }
scope :search, ->(q) { by_uname("%#{q.to_s.strip}%") }
end
def to_param

View File

@ -5,7 +5,7 @@ module Modules
included do
validate lambda {
validate -> {
if project && (commit_hash.blank? || project.repo.commit(commit_hash).blank?)
errors.add :commit_hash, I18n.t('flash.build_list.wrong_commit_hash', commit_hash: commit_hash)
end

View File

@ -16,7 +16,7 @@ module Modules
after_commit(on: :create) {|p| p.fork_git_repo unless p.is_root?} # later with resque
after_commit(on: :create) {|p| p.import_attached_srpm if p.srpm?} # later with resque # should be after create_git_repo
after_destroy :destroy_git_repo
# after_rollback lambda { destroy_git_repo rescue true if new_record? }
# after_rollback -> { destroy_git_repo rescue true if new_record? }
later :import_attached_srpm, queue: :fork_import
later :fork_git_repo, queue: :fork_import

View File

@ -5,7 +5,7 @@ module Modules
included do
validates :owner, presence: true
after_create lambda { relations.create actor_id: owner.id, actor_type: owner.class.to_s, role: 'admin' }
after_create -> { relations.create actor_id: owner.id, actor_type: owner.class.to_s, role: 'admin' }
end
end

View File

@ -9,22 +9,19 @@ module Modules
only_integer: true
}, presence: true
validate lambda {
validate -> {
# MIN_TIME_LIVING <= time_living <= MAX_TIME_LIVING or
# 2 min <= time_living <= 12 hours
# time_living in seconds
min = self.class.const_defined?(:MIN_TIME_LIVING) ? self.class::MIN_TIME_LIVING : 120
max = self.class.const_defined?(:MAX_TIME_LIVING) ? self.class::MAX_TIME_LIVING : 43200
if min > time_living.to_i || time_living.to_i > max
errors.add :time_living, I18n.t('flash.time_living.numericality_error',
min: (min / 60),
max: (max / 60)
)
errors.add :time_living,
I18n.t('flash.time_living.numericality_error', min: (min / 60), max: (max / 60))
end
}
before_validation :convert_time_living
attr_accessible :time_living
end