add User model features and uuid index
authorTom Clegg <tom@clinicalfuture.com>
Wed, 23 Jan 2013 17:44:44 +0000 (09:44 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Wed, 23 Jan 2013 17:49:05 +0000 (09:49 -0800)
add missing attribute Log#modified_at
remove duplicate code blocks

app/controllers/application_controller.rb
app/models/user.rb
db/migrate/20130122221616_add_modified_at_to_logs.rb [new file with mode: 0644]
db/migrate/20130123174514_add_uuid_index_to_users.rb [new file with mode: 0644]
db/schema.rb

index 36f4629823379feda41c61c5654a42230b8ff71d..7d1fd13c041279928aa2a609b467c3f4a8f3d7cf 100644 (file)
@@ -2,10 +2,10 @@ class ApplicationController < ActionController::Base
   protect_from_forgery
   before_filter :uncamelcase_params_hash_keys
   before_filter :find_object_by_uuid, :except => :index
-  before_filter :authenticate_api_token
+  before_filter :authenticate_api_token, :except => :render_not_found
 
   before_filter :set_remote_ip
-  before_filter :login_required
+  before_filter :login_required, :except => :render_not_found
 
   before_filter :catch_redirect_hint
 
@@ -37,52 +37,6 @@ class ApplicationController < ActionController::Base
   end
   # /Authentication
 
-  before_filter :set_remote_ip
-  before_filter :login_required
-
-  # Authentication
-  def login_required
-    if !current_user
-      respond_to do |format|
-        format.html  {
-          redirect_to '/auth/joshid'
-        }
-        format.json {
-          render :json => { 'error' => 'Not logged in' }.to_json
-        }
-      end
-    end
-  end
-
-  def current_user
-    return nil unless session[:user_id]
-    @current_user ||= User.find(session[:user_id]) rescue nil
-  end
-  # /Authentication
-
-  before_filter :set_remote_ip
-  before_filter :login_required
-
-  # Authentication
-  def login_required
-    if !current_user
-      respond_to do |format|
-        format.html  {
-          redirect_to '/auth/joshid'
-        }
-        format.json {
-          render :json => { 'error' => 'Not logged in' }.to_json
-        }
-      end
-    end
-  end
-
-  def current_user
-    return nil unless session[:user_id]
-    @current_user ||= User.find(session[:user_id]) rescue nil
-  end
-  # /Authentication
-
   unless Rails.application.config.consider_all_requests_local
     rescue_from Exception,
     :with => :render_error
index 6fc6814ffce250c7fc6dcdcf7b817ad55311625e..023b1795571fcd7b3dc3d798ffda237bf4268f9b 100644 (file)
@@ -1,4 +1,18 @@
 class User < ActiveRecord::Base
+  include AssignUuid
+  include KindAndEtag
+  include CommonApiTemplate
+  serialize :prefs, Hash
+
+  api_accessible :superuser, :extend => :common do |t|
+    t.add :email
+    t.add :full_name
+    t.add :first_name
+    t.add :last_name
+    t.add :identity_url
+    t.add :is_admin
+    t.add :prefs
+  end
 
   def full_name
     "#{first_name} #{last_name}"
diff --git a/db/migrate/20130122221616_add_modified_at_to_logs.rb b/db/migrate/20130122221616_add_modified_at_to_logs.rb
new file mode 100644 (file)
index 0000000..47828d0
--- /dev/null
@@ -0,0 +1,5 @@
+class AddModifiedAtToLogs < ActiveRecord::Migration
+  def change
+    add_column :logs, :modified_at, :datetime
+  end
+end
diff --git a/db/migrate/20130123174514_add_uuid_index_to_users.rb b/db/migrate/20130123174514_add_uuid_index_to_users.rb
new file mode 100644 (file)
index 0000000..f21d5e4
--- /dev/null
@@ -0,0 +1,5 @@
+class AddUuidIndexToUsers < ActiveRecord::Migration
+  def change
+    add_index :users, :uuid, :unique => true
+  end
+end
index 3a64857324b161c12057b0f0f3620b9c77df48df..3b9804271c3e81a450140c0ed5fce6ba06a05b51 100644 (file)
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended to check this file into your version control system.
 
-ActiveRecord::Schema.define(:version => 20130122221616) do
+ActiveRecord::Schema.define(:version => 20130123174514) do
 
   create_table "collections", :force => true do |t|
     t.string   "locator"
@@ -184,4 +184,6 @@ ActiveRecord::Schema.define(:version => 20130122221616) do
     t.datetime "updated_at"
   end
 
+  add_index "users", ["uuid"], :name => "index_users_on_uuid", :unique => true
+
 end