]> source.dussan.org Git - sonarqube.git/commitdiff
FIX filter creation and deletion
authorDavid Gageot <david@gageot.net>
Fri, 11 May 2012 15:06:58 +0000 (17:06 +0200)
committerDavid Gageot <david@gageot.net>
Fri, 11 May 2012 15:08:55 +0000 (17:08 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/filters_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/models/active_filter.rb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/models/filter.rb
sonar-server/src/main/webapp/WEB-INF/app/models/user.rb
sonar-server/src/main/webapp/WEB-INF/db/migrate/302_create_global_dashboards_for_filter.rb

index fbf5596aab29b78d1b86b67736da94e7a8916337..32f1b4a0ae22e14f4539bc10b9625f28f51f875c 100644 (file)
@@ -56,8 +56,6 @@ class FiltersController < ApplicationController
     if @filter.valid?
       @filter.save
 
-      # activate it by default
-      current_user.active_filters.create(:filter => @filter, :user_id => current_user.id, :order_index => (current_user.active_filters.size + 1))
       flash[:notice]='Filter saved'
 
       if params[:preview]=='true'
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/active_filter.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/active_filter.rb
deleted file mode 100644 (file)
index 0708f48..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# 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
index 41eee656b8e783fabfdd52ee046ade302c910918..659656446baf814fdb676a1740bbb62d11c7b276 100644 (file)
@@ -29,163 +29,162 @@ class Filter < ActiveRecord::Base
   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
index 9e379bd3f80b97ece9d0cf9e88b02f983cb7caac..2e25ac4dad735136ed115b93502c66b72d588a83 100644 (file)
@@ -24,16 +24,13 @@ class User < ActiveRecord::Base
   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
@@ -51,7 +48,7 @@ class User < ActiveRecord::Base
   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
@@ -84,7 +81,7 @@ class User < ActiveRecord::Base
     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
@@ -99,7 +96,7 @@ class User < ActiveRecord::Base
     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
@@ -108,7 +105,7 @@ class User < ActiveRecord::Base
     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
@@ -157,11 +154,11 @@ class User < ActiveRecord::Base
       []
     end
   end
-  
+
   #---------------------------------------------------------------------
   # FAVOURITES
   #---------------------------------------------------------------------
-  
+
   def favourite_ids
     @favourite_ids ||=
       begin
index 0c248dc7e95e5c54bbc368d7fa47df91e9fbc872..8ddccfa8e2afff1d017e8a85188f0c5befd63327 100644 (file)
@@ -22,6 +22,9 @@
 # Sonar 3.1
 #
 class CreateGlobalDashboardsForFilter < ActiveRecord::Migration
+  class ActiveFilter < ActiveRecord::Base
+  end
+
   class Dashboard < ActiveRecord::Base
   end