create user_profile table

this moves the user bio to a new user_profile table.  We previously had
a UserProfile model that was a regular ruby class, but now it is using
ActiveRecord

Change-Id: I8848ef9b5f7e2a7bbb5c12df8044efe26388ae78
Reviewed-on: https://gerrit.instructure.com/12178
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jon Jensen <jon@instructure.com>
This commit is contained in:
Cameron Matheson 2012-07-11 17:20:39 -06:00
parent ea7df0a103
commit a8e556f768
8 changed files with 57 additions and 15 deletions

View File

@ -27,7 +27,7 @@ class EportfoliosController < ApplicationController
end
def user_index
@context = UserProfile.new(@current_user)
@context = @current_user.profile
return unless tab_enabled?(UserProfile::TAB_EPORTFOLIOS)
@active_tab = "eportfolios"
add_crumb(@current_user.short_name, user_profile_url(@current_user))

View File

@ -39,7 +39,7 @@ class ProfileController < ApplicationController
@user ||= @current_user
@active_tab = "profile"
@context = UserProfile.new(@current_user) if @user == @current_user
@context = @user.profile if @user == @current_user
js_env :USER_ID => @user.id
@ -111,7 +111,7 @@ class ProfileController < ApplicationController
@default_pseudonym = @user.primary_pseudonym
@pseudonyms = @user.pseudonyms.active
@password_pseudonyms = @pseudonyms.select{|p| !p.managed_password? }
@context = UserProfile.new(@user)
@context = @user.profile
@active_tab = "profile_settings"
respond_to do |format|
format.html do
@ -159,7 +159,7 @@ class ProfileController < ApplicationController
@current_user.used_feature(:cc_prefs)
@notification_categories = Notification.dashboard_categories(@user)
@policies = NotificationPolicy.for(@user).scoped(:include => [:communication_channel, :notification]).to_a
@context = UserProfile.new(@user)
@context = @user.profile
@active_tab = "communication-preferences"
# build placeholder notification policies for categories the user does not have policies for already

View File

@ -570,7 +570,7 @@ class UsersController < ApplicationController
@resource_title = @tool.label_for(:user_navigation)
@resource_url = @tool.settings[:user_navigation][:url]
@opaque_id = @current_user.opaque_identifier(:asset_string)
@context = UserProfile.new(@current_user)
@context = @current_user.profile
@resource_type = 'user_navigation'
@return_url = user_profile_url(@current_user, :include_host => true)
@launch = BasicLTI::ToolLaunch.new(:url => @resource_url, :tool => @tool, :user => @current_user, :context => @context, :link_code => @opaque_id, :return_url => @return_url, :resource_type => @resource_type)

View File

@ -158,6 +158,9 @@ class User < ActiveRecord::Base
has_many :collections, :as => :context
has_many :collection_items, :through => :collections
has_one :profile, :class_name => 'UserProfile'
alias :orig_profile :profile
include StickySisFields
are_sis_sticky :name, :sortable_name, :short_name
@ -2450,4 +2453,8 @@ class User < ActiveRecord::Base
def default_collection_name
t :default_collection_name, "%{user_name}'s Collection", :user_name => self.short_name
end
def profile(force_reload = false)
orig_profile(force_reload) || build_profile
end
end

View File

@ -1,5 +1,5 @@
#
# Copyright (C) 2011 Instructure, Inc.
# Copyright (C) 2011 - 2012 Instructure, Inc.
#
# This file is part of Canvas.
#
@ -16,13 +16,13 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
class UserProfile
attr_accessor :user
def initialize(user)
@user = user
end
class UserProfile < ActiveRecord::Base
delegate :id, :short_name, :name, :asset_string, :opaque_identifier, :to => :@user
belongs_to :user
delegate :short_name, :name, :asset_string, :opaque_identifier, :to => :user
attr_accessible :title, :bio
TAB_PROFILE, TAB_COMMUNICATION_PREFERENCES, TAB_FILES, TAB_EPORTFOLIOS,
TAB_HOME, TAB_PROFILE_SETTINGS = *0..10
@ -39,7 +39,7 @@ class UserProfile
@tabs.insert 1, {:id => TAB_PROFILE, :label => I18n.t('#user_profile.tabs.profile', "Profile"), :css_class => 'profile', :href => :user_profile_path, :args => [user]}
end
@tabs << { :id => TAB_EPORTFOLIOS, :label => I18n.t('#tabs.eportfolios', "ePortfolios"), :css_class => 'eportfolios', :href => :dashboard_eportfolios_path, :no_args => true } if @user.eportfolios_enabled?
@tabs << { :id => TAB_EPORTFOLIOS, :label => I18n.t('#tabs.eportfolios', "ePortfolios"), :css_class => 'eportfolios', :href => :dashboard_eportfolios_path, :no_args => true } if user.eportfolios_enabled?
if user && opts[:root_account]
opts[:root_account].context_external_tools.active.having_setting('user_navigation').each do |tool|
@tabs << {

View File

@ -0,0 +1,11 @@
class DropUserBio < ActiveRecord::Migration
tag :postdeploy
def self.up
remove_column :users, :bio
end
def self.down
add_column :users, :bio, :text
end
end

View File

@ -0,0 +1,15 @@
class CreateUserProfilesTable < ActiveRecord::Migration
tag :predeploy
def self.up
create_table :user_profiles do |t|
t.text :bio
t.string :title
t.references :user, :limit => 8
end
end
def self.down
drop_table :user_profiles
end
end

View File

@ -1109,7 +1109,7 @@ describe User do
tool.save!
tool.has_user_navigation.should == false
user_model
tabs = UserProfile.new(@user).tabs_available(@user, :root_account => Account.default)
tabs = @user.profile.tabs_available(@user, :root_account => Account.default)
tabs.map{|t| t[:id] }.should_not be_include(tool.asset_string)
end
@ -1119,7 +1119,7 @@ describe User do
tool.save!
tool.has_user_navigation.should == true
user_model
tabs = UserProfile.new(@user).tabs_available(@user, :root_account => Account.default)
tabs = @user.profile.tabs_available(@user, :root_account => Account.default)
tabs.map{|t| t[:id] }.should be_include(tool.asset_string)
tab = tabs.detect{|t| t[:id] == tool.asset_string }
tab[:href].should == :user_external_tool_path
@ -1702,4 +1702,13 @@ describe User do
@user.quota.should eql(2 * User.default_storage_quota + 10.megabytes)
end
end
it "should build a profile if one doesn't already exist" do
user = User.create! :name => "John Johnson"
profile = user.profile
profile.id.should be_nil
profile.bio = "bio!"
profile.save!
user.profile.should == profile
end
end