+++ /dev/null
-#
-# Sonar, entreprise quality control tool.
-# Copyright (C) 2008-2012 SonarSource
-# mailto:contact AT sonarsource DOT com
-#
-# Sonar is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later version.
-#
-# Sonar is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with Sonar; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
-#
-class ActiveFilter < ActiveRecord::Base
-
- belongs_to :user
- belongs_to :filter
-
- def name
- filter.name
- end
-
- def shared
- filter.shared
- end
-
- def author
- filter.user
- end
-
- def author_name
- author ? author.name : nil
- end
-
- def owner?
- filter.user && user && filter.user==user
- end
-
- def self.default_active_filters
- find(:all, :include => 'filter', :conditions => {:user_id => nil}, :order => 'order_index')
- end
-
- def self.for_anonymous
- find(:all, :include => 'filter', :conditions => ['active_filters.user_id is null AND (filters.favourites=? OR filters.favourites is null)', false], :order => 'order_index')
- end
-end
\ No newline at end of file
belongs_to :resource, :class_name => 'Project', :foreign_key => 'resource_id'
has_many :columns, :class_name => 'FilterColumn', :dependent => :destroy, :validate => true, :order => 'order_index'
has_many :criteria, :class_name => 'Criterion', :dependent => :destroy, :validate => true
- has_many :active_filters, :dependent => :destroy
validates_length_of :name, :within => 1..100
validates_uniqueness_of :name, :scope => :user_id, :if => Proc.new { |filter| filter.user_id }
validates_inclusion_of :default_view, :in => ['list', 'treemap'], :allow_nil => true
def criterion(family, key=nil)
- criteria.each do |criterion|
- if criterion.family==family && criterion.key==key
- return criterion if ((key.nil? && criterion.key.nil?) || (key && key==criterion.key))
- end
- end
- nil
+ criteria.each do |criterion|
+ if criterion.family==family && criterion.key==key
+ return criterion if ((key.nil? && criterion.key.nil?) || (key && key==criterion.key))
+ end
+ end
+ nil
end
def measure_criteria
- @measure_criteria ||=
- begin
- criteria.select { |c| c.on_metric? && c.metric }
- end
+ @measure_criteria ||=
+ begin
+ criteria.select { |c| c.on_metric? && c.metric }
+ end
end
def first_column
- columns.size>0 ? columns[0] : nil
+ columns.size>0 ? columns[0] : nil
end
def last_column
- columns.size>0 ? columns[-1] : nil
+ columns.size>0 ? columns[-1] : nil
end
def column(family, key=nil)
- columns.each do |col|
- if col.family==family
- return col if ((key.nil? && col.key.nil?) || (key && key==col.key))
- end
- end
- nil
+ columns.each do |col|
+ if col.family==family
+ return col if ((key.nil? && col.key.nil?) || (key && key==col.key))
+ end
+ end
+ nil
end
def measure_columns
- columns.select { |col| col.metric }
+ columns.select { |col| col.metric }
end
def sorted_column
- @sorted_column ||=
- begin
- columns.to_a.find { |c| c.sort_direction } || column('name')
- end
+ @sorted_column ||=
+ begin
+ columns.to_a.find { |c| c.sort_direction } || column('name')
+ end
end
def sorted_column=(col_or_id)
- if col_or_id.is_a?(Fixnum)
- @sorted_column=columns.to_a.find { |c| c.id==col_or_id }
- else
- @sorted_column=col_or_id
- end
+ if col_or_id.is_a?(Fixnum)
+ @sorted_column=columns.to_a.find { |c| c.id==col_or_id }
+ else
+ @sorted_column=col_or_id
+ end
end
def display_masterproject?
- name=='Projects'
+ name=='Projects'
end
def display_links?
- column('links')
+ column('links')
end
def default_view
- read_attribute(:default_view) || VIEW_LIST
+ read_attribute(:default_view) || VIEW_LIST
end
def page_size
- if default_view==VIEW_TREEMAP
- TREEMAP_PAGE_SIZE
- else
- read_attribute(:page_size) || DEFAULT_PAGE_SIZE
- end
+ if default_view==VIEW_TREEMAP
+ TREEMAP_PAGE_SIZE
+ else
+ read_attribute(:page_size) || DEFAULT_PAGE_SIZE
+ end
end
def ajax_loading?
- default_view==VIEW_TREEMAP
+ default_view==VIEW_TREEMAP
end
def projects_homepage?
- name=='Projects'
+ name=='Projects'
end
def advanced_search?
- @advanced_search ||=
- begin
- !(criterion('language').nil?) || favourites || !(criterion('name').nil?) || !(criterion('key').nil?) || !(criterion('date').nil?) || period?
- end
+ @advanced_search ||=
+ begin
+ !(criterion('language').nil?) || favourites || !(criterion('name').nil?) || !(criterion('key').nil?) || !(criterion('date').nil?) || period?
+ end
end
def period_index=(vi)
- if vi && vi>0
- write_attribute(:period_index, vi)
- else
- write_attribute(:period_index, nil)
- end
+ if vi && vi>0
+ write_attribute(:period_index, vi)
+ else
+ write_attribute(:period_index, nil)
+ end
end
def period?
- period_index && period_index>0
+ period_index && period_index>0
end
def column_by_id(col_id)
- columns.each do |col|
- return col if col.id==col_id
- end
- nil
+ columns.each do |col|
+ return col if col.id==col_id
+ end
+ nil
end
def clean_columns_order
- columns.each_with_index do |col, index|
- col.order_index=index+1
- col.save
- end
- reload
+ columns.each_with_index do |col, index|
+ col.order_index=index+1
+ col.save
+ end
+ reload
end
def authorized_to_execute?(authenticated_system)
- shared || (user==authenticated_system.current_user)
+ shared || (user==authenticated_system.current_user)
end
def authorized_to_edit?(authenticated_system)
- if authenticated_system.logged_in?
- (user && user==authenticated_system.current_user) || (!user && authenticated_system.is_admin?)
- else
- false
- end
+ if authenticated_system.logged_in?
+ (user && user==authenticated_system.current_user) || (!user && authenticated_system.is_admin?)
+ else
+ false
+ end
end
protected
def before_validation
- # the name column is mandatory
- if self.column('name').nil?
- self.columns.insert(0, FilterColumn.new(:family => 'name'))
- end
+ # the name column is mandatory
+ if self.column('name').nil?
+ self.columns.insert(0, FilterColumn.new(:family => 'name'))
+ end
- # one column must be sorted
- sorted_col=self.columns.to_a.find { |c| c.sort_direction }
- unless sorted_col
- column('name').sort_direction='ASC'
- end
+ # one column must be sorted
+ sorted_col=self.columns.to_a.find { |c| c.sort_direction }
+ unless sorted_col
+ column('name').sort_direction='ASC'
+ end
- # sanitize orders
- self.columns.each_with_index do |col, index|
- col.order_index=index+1
- end
- true
+ # sanitize orders
+ self.columns.each_with_index do |col, index|
+ col.order_index=index+1
+ end
+ true
end
def after_save
- self.columns.each do |col|
- col.save
- end
+ self.columns.each do |col|
+ col.save
+ end
end
-end
\ No newline at end of file
+end
FAVOURITE_PROPERTY_KEY='favourite'
has_and_belongs_to_many :groups
- has_many :user_roles, :dependent => :delete_all
+ has_many :user_roles, :dependent => :delete_all
has_many :properties, :foreign_key => 'user_id', :dependent => :delete_all
-
- has_many :active_filters, :include => 'filter', :order => 'order_index'
has_many :filters, :dependent => :destroy
-
has_many :active_dashboards, :dependent => :destroy, :order => 'order_index'
has_many :dashboards, :dependent => :destroy
-
+
include Authentication
include Authentication::ByPassword
include Authentication::ByCookieToken
validates_length_of :login, :within => 2..40
validates_uniqueness_of :login, :case_sensitive => true
validates_format_of :login, :with => Authentication.login_regex, :message => Authentication.bad_login_message
-
+
# HACK HACK HACK -- how to do attr_accessible from here?
# prevents a user from submitting a crafted form that bypasses activation
return 1 if other.name.nil?
name.downcase<=>other.name.downcase
end
-
+
# SONAR-3258 : we do not delete users anymore. Users are just deactivated.
# However, all related data is removed from the DB.
def deactivate
self.dashboards.each {|d| d.destroy}
self.active_dashboards.each {|ad| ad.destroy}
end
-
+
# SONAR-3258
def reactivate(default_group_name)
if default_group_name
end
self.active = true
end
-
+
def self.find_active_by_login(login)
User.find(:first, :conditions => ["login=:login AND active=:active", {:login => login, :active => true}])
end
[]
end
end
-
+
#---------------------------------------------------------------------
# FAVOURITES
#---------------------------------------------------------------------
-
+
def favourite_ids
@favourite_ids ||=
begin