[Logilogi-svn] SF.net SVN: logilogi:[1615] trunk
Status: Beta
Brought to you by:
wybow
|
From: <wy...@us...> - 2009-10-19 20:02:44
|
Revision: 1615
http://logilogi.svn.sourceforge.net/logilogi/?rev=1615&view=rev
Author: wybow
Date: 2009-10-19 20:02:37 +0000 (Mon, 19 Oct 2009)
Log Message:
-----------
Added new files for alert-system
Added Paths:
-----------
trunk/config/initializers/active_record.rb
trunk/db/migrate/20091005232423_add_unix_names.rb
trunk/lib/modules/unix_name_module.rb
Added: trunk/config/initializers/active_record.rb
===================================================================
--- trunk/config/initializers/active_record.rb (rev 0)
+++ trunk/config/initializers/active_record.rb 2009-10-19 20:02:37 UTC (rev 1615)
@@ -0,0 +1,24 @@
+#--#
+# Copyright: (c) 2007 The LogiLogi Foundation <fou...@lo...>
+#
+# License:
+# This file is part of the OgOg program. OgOg is Free Software. You can run/
+# distribute/modify OgOg under the terms of the GNU Affero General Public
+# License version 3. The Affero GPL states that running a modified version
+# or a derivative work also requires you to make the sourcecode of that work
+# available to everyone that can interact with it. We chose the Affero GPL
+# to ensure that OgOg remains open and libre (doc/LICENSE contains the
+# full text of the legally binding license).
+#++#
+
+# To provide end_form_tag for the rubaidh formbuilder
+module ActiveRecord
+ class Base
+ class << self
+ def exists?(id_or_conditions = {})
+ find_initial(
+ :conditions => expand_id_conditions(id_or_conditions)) ? true : false
+ end
+ end
+ end
+end
Added: trunk/db/migrate/20091005232423_add_unix_names.rb
===================================================================
--- trunk/db/migrate/20091005232423_add_unix_names.rb (rev 0)
+++ trunk/db/migrate/20091005232423_add_unix_names.rb 2009-10-19 20:02:37 UTC (rev 1615)
@@ -0,0 +1,25 @@
+class AddUnixNames < ActiveRecord::Migration
+ def self.up
+ add_column :users, :unix_name, :string, :null => false
+ add_column :peer_groups, :unix_name, :string, :null => false
+
+ if GlobalConfig.available?
+ AddUnixNames.update
+ end
+ end
+
+ def self.down
+ raise 'No way back'
+ end
+
+ def self.update
+ User.find(:all).each do |user|
+ user.set_unix_name
+ user.save
+ end
+ PeerGroup.find(:all).each do |peer_group|
+ user.set_unix_name
+ peer_group.save
+ end
+ end
+end
Added: trunk/lib/modules/unix_name_module.rb
===================================================================
--- trunk/lib/modules/unix_name_module.rb (rev 0)
+++ trunk/lib/modules/unix_name_module.rb 2009-10-19 20:02:37 UTC (rev 1615)
@@ -0,0 +1,41 @@
+#--#
+# Copyright: (c) 2006-2009 The LogiLogi Foundation <fou...@lo...>
+#
+# License:
+# This file is part of the LogiLogi program. LogiLogi is Free Software.
+# You can run/distribute/modify LogiLogi under the terms of the GNU Affero
+# General Public License version 3. The Affero GPL states that running a
+# modified version or a derivative work also requires you to make the source
+# code of that work available to everyone that can interact with it. We
+# chose the Affero GPL to ensure that LogiLogi remains open and libre
+# (doc/LICENSE contains the full text of the legally binding license).
+#++#
+
+module UnixNameModule
+ ### Class methods
+
+ module ClassMethods
+ def initialize_module
+ ### Validations
+
+ validates_uniqueness_of :unix_name
+ end
+ end
+
+ def self.included(base)
+ base.extend(ClassMethods)
+ base.send(:initialize_module)
+ end
+
+ ### Filter-functions
+
+ # sets the unix-name of the object, based on it's name.
+ #
+ def set_unix_name
+ begin
+ self.unix_name = self.name.downcase.gsub(/[\ .-]/,'_').gsub(/[^a-z_]/,'')
+ rescue
+ self.errors.add(:name, "not unique in reduced format")
+ end
+ end
+end
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|