From 5295e51437b8e0c1a1754169baa7d4d455e91cd8 Mon Sep 17 00:00:00 2001 From: Pascal Rettig Date: Tue, 5 Oct 2010 15:54:45 -0400 Subject: [PATCH 1/3] User Profile list --- .../user_profile/page_controller.rb | 28 +++++++++-- .../controllers/user_profile/page_feature.rb | 29 +++++++++++ .../controllers/user_profile/page_renderer.rb | 49 ++++++++++++++++--- .../app/models/user_profile_entry.rb | 5 ++ .../app/models/user_profile_type.rb | 33 +++++++++++++ 5 files changed, 133 insertions(+), 11 deletions(-) diff --git a/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb b/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb index 4215f9ce..66aa07d6 100644 --- a/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb +++ b/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb @@ -6,24 +6,44 @@ class UserProfile::PageController < ParagraphController editor_for :display_profile, :name => "Display Profile", :feature => :user_profile_page_display_profile, :inputs => { :user_profile => [ [:url, 'User URL', :path]] }, :outputs => [ [ :profile_content, "Profile Entry",:content] ] + editor_for :list_profiles, :name => 'List Profiles', :feature => :user_profile_page_list_profiles + class DisplayProfileOptions < HashModel # this needs to be set as a paragraph option.. they have to pick which profile they want displayed on the page attributes :profile_type_id => nil, :default_to_user => true - page_options :profile_type_id boolean_options :default_to_user validates_presence_of :profile_type_id options_form(fld(:profile_type_id,:select,:options => :profile_type_select_options), - fld(:default_to_user,:radio_buttons,:options => :yes_no)) + fld(:default_to_user,:yes_no)) def profile_type_select_options UserProfileType.select_options_with_nil end - def yes_no - [["Yes".t,true],["No".t,false]] + end + + + class ListProfilesOptions < HashModel + attributes :profile_type_id => nil, :order_by => 'newest', :registered_only => true, :per_page => 20 + + validates_presence_of :profile_type_id + integer_options :per_page + boolean_options :registered_only + + + has_options :order_by, [['Newest','newest'],['Updated','updated'],['Alphabetical','alpha']] + + options_form(fld(:profile_type_id,:select,:options => :profile_type_select_options), + fld(:order_by,:select, :options => :order_by_select_options), + fld(:per_page,:text_field), + fld(:registered_only,:yes_no,:description => 'Only show registered users (recommended)')) + + def profile_type_select_options + UserProfileType.select_options_with_nil end + end diff --git a/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb b/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb index 07f59492..72ef4001 100644 --- a/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb +++ b/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb @@ -29,6 +29,35 @@ def user_profile_page_display_profile_feature(data) end end + + feature :user_profile_page_list_profiles, :default_feature => <<-FEATURE + + + + + +FEATURE + + +def user_profile_page_list_profiles_feature(data) + webiva_custom_feature(:user_profile_page_list_profiles,data) do |c| + c.loop_tag('user') { |t| data[:users] } + c.user_details_tags('user') { |t| t.locals.user.end_user } + c.link_tag('user:') { |t| data[:user_profile_type].content_type.content_link(t.locals.user) } + c.expansion_tag('user:profile') { |t| t.locals.entry = t.locals.user.content_model_entry if data[:content_model] } + + c.content_model_fields_value_tags('user:profile',data[:user_profile_type].display_content_model_fields) if data[:content_model] + c.pagelist_tag('pages') { |t| data[:pages] } + end +end + feature :user_profile_page_profile_privacy, :default_feature => <<-FEATURE diff --git a/vendor/modules/user_profile/app/controllers/user_profile/page_renderer.rb b/vendor/modules/user_profile/app/controllers/user_profile/page_renderer.rb index 5f955b30..6be0d208 100644 --- a/vendor/modules/user_profile/app/controllers/user_profile/page_renderer.rb +++ b/vendor/modules/user_profile/app/controllers/user_profile/page_renderer.rb @@ -7,22 +7,57 @@ class UserProfile::PageRenderer < ParagraphRenderer features '/user_profile/page_feature' paragraph :display_profile + paragraph :list_profiles + def display_profile @options = paragraph_options(:display_profile) + @user_profile = find_profile + + + result = renderer_cache(@user_profile) do |cache| + if @user_profile + @profile_user = @user_profile.end_user + @content_model = @user_profile.content_model + @user_profile_type = @user_profile.user_profile_type + cache[:full_name] = @profile_user.full_name + end + + @url = site_node.node_path + + cache[:output] = user_profile_page_display_profile_feature + end + if @user_profile - @profile_user = @user_profile.end_user - @content_model = @user_profile.content_model - @user_profile_type = @user_profile.user_profile_type - set_title(@profile_user.full_name) - set_title(@profile_user.full_name,"profile") + set_title(result.full_name) + set_title(result.full_name,"profile") set_page_connection(:profile_content, ['UserProfileEntry',@user_profile.id]) set_content_node(@user_profile) end - @url = site_node.node_path + render_paragraph :text => result.output + end + + @@profile_order_by_options = { 'newest' => 'end_users.created_at DESC', + 'updated' => 'end_users.updated_at DESC', + 'alpha' => 'end_users.last_name, end_users.first_name' } + + def list_profiles + @options = paragraph_options(:list_profiles) + + result = renderer_cache(UserProfileEntry) do |cache| + @user_profile_type = UserProfileType.find_by_id(@options.profile_type_id) + + return render_paragraph :text => 'Configure Paragraph'.t if !@user_profile_type + + order_by = @@profile_order_by_options[@options.order_by] + @pages,@users = @user_profile_type.paginate_users(params[:page],:order => order_by, :registered => @options.registered_only) + @content_model = @user_profile_type.content_model + + cache[:output] = user_profile_page_list_profiles_feature + end - render_paragraph :feature => :user_profile_page_display_profile + render_paragraph :text => result.output end def find_profile diff --git a/vendor/modules/user_profile/app/models/user_profile_entry.rb b/vendor/modules/user_profile/app/models/user_profile_entry.rb index 18823214..eac23d1e 100644 --- a/vendor/modules/user_profile/app/models/user_profile_entry.rb +++ b/vendor/modules/user_profile/app/models/user_profile_entry.rb @@ -20,6 +20,7 @@ class UserProfileEntry < DomainModel } } + cached_content :identifier => :url content_node(:container_type => 'UserProfileType', :container_field => 'user_profile_type_id', :push_value => true, :except => Proc.new() { |e| e.url.blank? }) @@ -78,6 +79,10 @@ def content_model_entry @content_model_entry end + def content_model_entry_cache=(val) + @content_model_entry = val + end + def create_full_name self.end_user.full_name if self.end_user end diff --git a/vendor/modules/user_profile/app/models/user_profile_type.rb b/vendor/modules/user_profile/app/models/user_profile_type.rb index 347dd38b..8386bec8 100644 --- a/vendor/modules/user_profile/app/models/user_profile_type.rb +++ b/vendor/modules/user_profile/app/models/user_profile_type.rb @@ -72,6 +72,39 @@ def self.import_fields end + def paginate_users(page,options={}) + + if options[:registered_only] + conds = [ 'end_users.registered = 1'] + else + conds = nil + end + + pages,users = UserProfileEntry.paginate(page,:joins => [ :end_user ], :conditions => conds, :order => options[:order]) + + + if self.content_model + cls = self.content_model.model_class + + model_attributes = { self.content_model_field_name => users.map(&:end_user_id) } + + model_entries = cls.find(:all,:conditions => model_attributes).index_by(&(self.content_model_field_name.to_sym)) + + users.each do |usr| + entry = model_entries[usr.end_user_id] + if entry + usr.content_model_entry_cache = entry + else + usr.content_model_entry_cache = cls.new( self.content_model_field_name => usr.end_user_id) + end + end + end + + [ pages,users ] + + end + + protected def update_user_classes From 11f292cbe336055d8b56cecd5e80920942614d9a Mon Sep 17 00:00:00 2001 From: Pascal Rettig Date: Wed, 6 Oct 2010 19:26:03 -0400 Subject: [PATCH 2/3] User profile editor feature and list profile support --- app/controllers/editor/auth_controller.rb | 84 +++++++++---------- app/controllers/editor/auth_feature.rb | 5 ++ app/controllers/editor/auth_renderer.rb | 25 ++++++ app/models/node_engine/builtin_handler.rb | 1 - .../editor/auth/_user_edit_feature.rhtml | 13 +++ .../editor/auth/_user_edit_features.rhtml | 16 ++++ app/views/editor/auth/user_edit_account.rhtml | 47 ++++++++++- .../user_profile/admin_controller.rb | 4 + .../user_profile/page_controller.rb | 5 +- .../controllers/user_profile/page_feature.rb | 29 ------- .../controllers/user_profile/page_renderer.rb | 3 +- .../user_profile/user_edit_extension.rb | 50 +++++++++++ .../app/models/user_profile_type.rb | 10 +-- .../user_profile/page/_auth_user_edit.rhtml | 1 + .../db/20100402150514_initial_tables.rb | 2 +- 15 files changed, 212 insertions(+), 83 deletions(-) create mode 100644 app/views/editor/auth/_user_edit_feature.rhtml create mode 100644 app/views/editor/auth/_user_edit_features.rhtml create mode 100644 vendor/modules/user_profile/app/models/user_profile/user_edit_extension.rb create mode 100644 vendor/modules/user_profile/app/views/user_profile/page/_auth_user_edit.rhtml diff --git a/app/controllers/editor/auth_controller.rb b/app/controllers/editor/auth_controller.rb index acdaea56..2bd9c290 100644 --- a/app/controllers/editor/auth_controller.rb +++ b/app/controllers/editor/auth_controller.rb @@ -3,7 +3,7 @@ class Editor::AuthController < ParagraphController #:nodoc:all permit 'editor_editor' - user_actions [:add_feature, :add_login_feature] + user_actions [:add_feature, :add_login_feature, :add_user_edit_feature] # Editor for authorization paragraphs editor_header "Member Paragraphs", :paragraph_member @@ -215,7 +215,8 @@ class UserEditAccountOptions < HashModel :work_address_required_fields => [], :address_required_fields => [], :content_publication_id => nil, :content_publication_user_field => nil, - :access_token_id => nil, :user_level => 4 + :access_token_id => nil, :user_level => 4, + :features => [] page_options :success_page_id @@ -229,14 +230,33 @@ def validate self.required_fields = [] if @passed_hash[:required_fields].blank? self.optional_fields = [] if @passed_hash[:optional_fields].blank? if self.content_publication_id - if self.content_publication_user_field - errors.add(:content_publication_user_field) unless self.publication_field_options.rassoc self.content_publication_user_field - else - errors.add(:content_publication_user_field) unless self.content_publication_user_field - end + if self.content_publication_user_field + errors.add(:content_publication_user_field) unless self.publication_field_options.rassoc self.content_publication_user_field + else + errors.add(:content_publication_user_field) unless self.content_publication_user_field + end + end + if !self.features.is_a?(Array) + self.features = self.features.to_a.sort { |a,b| a[0] <=> b[0] }.map { |elm| obj = Handlers::ParagraphFeature.new(elm[1]); obj.to_hash } + + self.user_edit_features.each do |feature| + if !feature.options.valid? + self.errors.add_to_base('Feature Error') + end + end end end + def user_edit_features + @edut_features ||= self.features.map do |feature| + Handlers::ParagraphFeature.new(feature.merge({ :feature_type => 'editor_auth_user_edit_feature'})) + end + end + + def available_features + [['--Select a feature to add--','']] + get_handler_options(:editor,:auth_user_edit_feature) + end + def available_field_list { :email => [ 'Email'.t,:text_field, :email ], :password => [ 'Reset Password'.t, :password_field, :password ], @@ -419,41 +439,6 @@ def login_features end end - def edit_account - @options = EditAccountOptions.new(params[:edit_profile] || @paragraph.data || {}) - - if request.post? && @options.valid? - if @options.include_subscriptions.is_a?(Array) - @options.include_subscriptions = @options.include_subscriptions.find_all { |elem| !elem.blank? }.collect { |elem| elem.to_i } - else - @options.include_subscriptions = [] - end - @options.success_page = @options.success_page.to_i - @paragraph.data = @options.to_h - @paragraph.save - render_paragraph_update - return - end - - @content_publications = [ ['No Publication', 0 ] ] + ContentPublication.find(:all,:conditions => 'publication_type = "create"',:order => 'content_models.name, content_publications.name', - :include => :content_model ).collect { |pub| [ pub.content_model.name + ' - ' + pub.name, pub.id ] } - - @pages = [[ '--Select Page--'.t, nil ]] + SiteNode.page_options() - - @fields = %w{username gender first_name last_name dob address work_address} - @field_options = [ [ 'Required', 'required' ], [ 'Optional','optional' ], ['Do not Display','off' ] ] - @subscriptions = UserSubscription.find_select_options(:all,:order => 'name') - end - - class EditAccountOptions < HashModel - default_options :success_page => nil, :form_display => 'normal', :first_name => 'required', :last_name => 'required', - :gender => 'required', :username => 'off', :dob => 'off', :address => 'off', :work_address => 'off', :add_tags => '', - :include_subscriptions => [], :country => 'United States', :reset_password => 'show', - :address_type => 'us', :edit_button => nil - validates_presence_of :success_page - integer_options :success_page - end - def enter_vip @options = EnterVipOptions.new(params[:enter_vip] || @paragraph.data || {}) @@ -555,4 +540,19 @@ def add_login_feature end end + + def add_user_edit_feature + @info = get_handler_info(:editor,:auth_user_edit_feature,params[:feature_handler]) + + if @info && myself.editor? + @feature = Handlers::ParagraphFeature.new({ }) + @feature.feature_handler = @info[:identifier] + @feature.feature_type = 'editor_auth_user_edit_feature' + render :partial => 'user_edit_feature', :locals => { :feature => @feature, :idx => params[:index] } + else + render :nothing => true + end + + end + end diff --git a/app/controllers/editor/auth_feature.rb b/app/controllers/editor/auth_feature.rb index 61413917..31807ae3 100644 --- a/app/controllers/editor/auth_feature.rb +++ b/app/controllers/editor/auth_feature.rb @@ -144,6 +144,11 @@ def user_edit_account_feature(data) end c.button_tag('edit:submit') + + data[:options].user_edit_features.each do |feature| + feature.feature_instance.feature_tags(c,data[:feature]) + end + end end diff --git a/app/controllers/editor/auth_renderer.rb b/app/controllers/editor/auth_renderer.rb index a8af69ad..f1e905f6 100644 --- a/app/controllers/editor/auth_renderer.rb +++ b/app/controllers/editor/auth_renderer.rb @@ -218,6 +218,14 @@ def user_edit_account end end + @feature = { } + + + @options.user_edit_features.each do |feature| + feature.feature_instance.generate(params,@usr) + end + + if request.post? && ( params[:user] || params[:model] ) && !editor? && myself.id params[:user] ||= {} handle_image_upload(params[:user],:domain_file_id) @@ -252,6 +260,12 @@ def user_edit_account all_valid = false unless @model.errors.length == 0 end + @options.user_edit_features.each do |feature| + all_valid=false unless feature.feature_instance.valid? + end + + + # if there are no errors on anything # save the user, @failed = true unless all_valid @@ -286,6 +300,11 @@ def user_edit_account @model.save if @model + @options.user_edit_features.each do |feature| + feature.feature_instance.post_process(@usr) + end + + if @options.access_token_id tkn = AccessToken.find_by_id(@options.access_token_id) @usr.add_token!(tkn) if tkn @@ -313,6 +332,12 @@ def user_edit_account end @reset_password = flash['reset_password'] + + @options.user_edit_features.each do |feature| + feature.feature_instance.feature_data(@feature) + end + + render_paragraph :feature => :user_edit_account end diff --git a/app/models/node_engine/builtin_handler.rb b/app/models/node_engine/builtin_handler.rb index d6ea3fef..89a83499 100644 --- a/app/models/node_engine/builtin_handler.rb +++ b/app/models/node_engine/builtin_handler.rb @@ -68,7 +68,6 @@ def before_page @output.status = 'Lock' @output.redirect = redirection - @output.paction = engine.user.action("/lock/lockout",:identifier => redirection) return @output end end diff --git a/app/views/editor/auth/_user_edit_feature.rhtml b/app/views/editor/auth/_user_edit_feature.rhtml new file mode 100644 index 00000000..00556036 --- /dev/null +++ b/app/views/editor/auth/_user_edit_feature.rhtml @@ -0,0 +1,13 @@ +
+
+ '/> +
+' id='handle_<%= idx %>' align='absmiddle' /> +<%= feature.name %>
+ +<% cms_fields_for "user_edit_account[features][#{idx}][feature_options]", feature.options do |ff| -%> + <%= render :partial => feature.options_partial, :locals => { :f => ff, :prefix => "user_edit[features][#{idx}][feature_options]", :options => feature.options } %> +<% end -%> + +
+ diff --git a/app/views/editor/auth/_user_edit_features.rhtml b/app/views/editor/auth/_user_edit_features.rhtml new file mode 100644 index 00000000..3fed1819 --- /dev/null +++ b/app/views/editor/auth/_user_edit_features.rhtml @@ -0,0 +1,16 @@ + + + + +Add a feature: +

+ +
+<% @options.user_edit_features.each_with_index do |feature,idx| -%> + <%= render :partial => 'user_edit_feature', :locals => { :feature => feature, :idx => idx } %> +<% end -%> +
+ + diff --git a/app/views/editor/auth/user_edit_account.rhtml b/app/views/editor/auth/user_edit_account.rhtml index a01e003a..030127f2 100644 --- a/app/views/editor/auth/user_edit_account.rhtml +++ b/app/views/editor/auth/user_edit_account.rhtml @@ -1,6 +1,48 @@ + + + +
<% paragraph_options_form_for 'User Edit Account Options', :user_edit_account, @options do |f| %> -<% tabled_ajax_tabs ['Options','Fields','Actions'],'Options' do |t| %> +<% tabled_ajax_tabs ['Options','Fields','Edit Features','Actions'],'Options' do |t| %> <% t.tabled_tab do %> <%= f.header 'Registration Control' -%> <%= f.select :mail_template_id, [['--Select Template--'.t,nil]] + MailTemplate.select_options %> @@ -24,6 +66,9 @@ <%= f.select :content_publication_user_field, @options.publication_field_options() if @options.publication %> <%= f.ordered_array :include_subscriptions, UserSubscription.select_options %> <% end -%> +<% t.tab do %> + <%= render :partial => 'user_edit_features' -%> +<% end -%> <% t.tab do %>
<%= render :partial => '/editor/includes/actions' %> diff --git a/vendor/modules/user_profile/app/controllers/user_profile/admin_controller.rb b/vendor/modules/user_profile/app/controllers/user_profile/admin_controller.rb index 887a9dfa..6fd514a2 100644 --- a/vendor/modules/user_profile/app/controllers/user_profile/admin_controller.rb +++ b/vendor/modules/user_profile/app/controllers/user_profile/admin_controller.rb @@ -13,6 +13,10 @@ class UserProfile::AdminController < ModuleController register_handler :model, :end_user, "UserProfileUserHandler", :actions => [:after_save] register_handler :members, :view, "UserProfile::ManageController" + register_handler :editor, :auth_user_edit_feature, "UserProfile::UserEditExtension" + + + register_permissions :user_profile, [ [ :manage, 'Manage User Profile', 'Manage User Profile' ], [ :config, 'Configure User Profile', 'Configure User Profile' ] ] diff --git a/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb b/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb index 66aa07d6..d582e95b 100644 --- a/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb +++ b/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb @@ -26,11 +26,11 @@ def profile_type_select_options class ListProfilesOptions < HashModel - attributes :profile_type_id => nil, :order_by => 'newest', :registered_only => true, :per_page => 20 + attributes :profile_type_id => nil, :order_by => 'newest', :registered_only => true, :per_page => 20, :hide_protected => false validates_presence_of :profile_type_id integer_options :per_page - boolean_options :registered_only + boolean_options :registered_only, :hide_protected has_options :order_by, [['Newest','newest'],['Updated','updated'],['Alphabetical','alpha']] @@ -38,6 +38,7 @@ class ListProfilesOptions < HashModel options_form(fld(:profile_type_id,:select,:options => :profile_type_select_options), fld(:order_by,:select, :options => :order_by_select_options), fld(:per_page,:text_field), + fld(:hide_protected,:yes_no,:description => 'Hide protected users'), fld(:registered_only,:yes_no,:description => 'Only show registered users (recommended)')) def profile_type_select_options diff --git a/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb b/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb index 72ef4001..9436b5e6 100644 --- a/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb +++ b/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb @@ -58,34 +58,5 @@ def user_profile_page_list_profiles_feature(data) end end - feature :user_profile_page_profile_privacy, :default_feature => <<-FEATURE - - -
- - - - - - -
- - -Please re-enter the URL, no profile exists for the name entered - - FEATURE - - - def user_profile_page_profile_privacy_feature(data) - webiva_feature(:user_profile_page_profile_privacy,data) do |c| - c.user_details_tags('user') { |t| t.locals.user } - c.expansion_tag("myself") { |t| t.locals.user == myself } - c.form_for_tag('profile_options','profile_options') { |t| data[:profile_entry_options] } - c.field_tag('profile_options:protected', :control => :check_box) - c.field_tag('profile_options:private', :control => :check_box) - end - end end - - diff --git a/vendor/modules/user_profile/app/controllers/user_profile/page_renderer.rb b/vendor/modules/user_profile/app/controllers/user_profile/page_renderer.rb index 6be0d208..3f933194 100644 --- a/vendor/modules/user_profile/app/controllers/user_profile/page_renderer.rb +++ b/vendor/modules/user_profile/app/controllers/user_profile/page_renderer.rb @@ -68,7 +68,8 @@ def find_profile if url.blank? && @options.default_to_user UserProfileEntry.find_by_end_user_id_and_user_profile_type_id(myself.id, @options.profile_type_id) else - UserProfileEntry.find_by_url_and_user_profile_type_id(url, @options.profile_type_id) + profile = UserProfileEntry.find_by_url_and_user_profile_type_id(url, @options.profile_type_id) + profile && profile.published? ? profile : nil end end diff --git a/vendor/modules/user_profile/app/models/user_profile/user_edit_extension.rb b/vendor/modules/user_profile/app/models/user_profile/user_edit_extension.rb new file mode 100644 index 00000000..bbd37418 --- /dev/null +++ b/vendor/modules/user_profile/app/models/user_profile/user_edit_extension.rb @@ -0,0 +1,50 @@ + + +class UserProfile::UserEditExtension < Handlers::ParagraphFormExtension + + def self.editor_auth_user_edit_feature_handler_info + { + :name => 'User Profile Publication', + :paragraph_options_partial => '/user_profile/page/auth_user_edit' + } + end + + + # Paragraph Setup options + def self.paragraph_options(val={ }) + opts = HashModel.new(val) + end + + + # Generates called with the paragraph parameters + def generate(params,user) + @user = user + + @entry = UserProfileEntry.fetch_first_entry(user) + @entry.attributes = (params[:user_profile]||{}).slice(:published,:protected) if @entry + end + + # Called before the feature is displayed + def feature_data(data) + data[:user_profile] = @entry + end + + # Adds any feature related tags + def feature_tags(c,data) + c.fields_for_tag('edit:user_profile','user_profile') { |t| data[:user_profile]} + c.field_tag('edit:user_profile:published', :control => :check_box, :single => true) + c.field_tag('edit:user_profile:protected', :control => :check_box, :single => true) + end + + # Validate the submitted data + def valid? + true + end + + # After everything has been validated + # Perform the actual form submission + def post_process(user) + @entry.save if @entry + end + +end diff --git a/vendor/modules/user_profile/app/models/user_profile_type.rb b/vendor/modules/user_profile/app/models/user_profile_type.rb index 8386bec8..52b7e3be 100644 --- a/vendor/modules/user_profile/app/models/user_profile_type.rb +++ b/vendor/modules/user_profile/app/models/user_profile_type.rb @@ -74,13 +74,11 @@ def self.import_fields def paginate_users(page,options={}) - if options[:registered_only] - conds = [ 'end_users.registered = 1'] - else - conds = nil - end + conds = { :published => 1 } + conds['end_users.registered'] = 1 if options[:registered_only] + conds[:protected] = 0 if options[:hide_protected] - pages,users = UserProfileEntry.paginate(page,:joins => [ :end_user ], :conditions => conds, :order => options[:order]) + pages,users = UserProfileEntry.paginate(page,:joins => [ :end_user ], :conditions => conds, :order => options[:order], :include => :end_user) if self.content_model diff --git a/vendor/modules/user_profile/app/views/user_profile/page/_auth_user_edit.rhtml b/vendor/modules/user_profile/app/views/user_profile/page/_auth_user_edit.rhtml new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/vendor/modules/user_profile/app/views/user_profile/page/_auth_user_edit.rhtml @@ -0,0 +1 @@ + diff --git a/vendor/modules/user_profile/db/20100402150514_initial_tables.rb b/vendor/modules/user_profile/db/20100402150514_initial_tables.rb index 0a54acf1..0c293054 100644 --- a/vendor/modules/user_profile/db/20100402150514_initial_tables.rb +++ b/vendor/modules/user_profile/db/20100402150514_initial_tables.rb @@ -18,7 +18,7 @@ def self.up t.integer :user_profile_type_id t.integer :end_user_id t.string :url - t.boolean :published, :default => true + t.boolean :published, :default => false t.boolean :protected, :default => false t.integer :content_model_id end From b3cbbb53ccea9a10f1c9960f4b7a1abf3f227460 Mon Sep 17 00:00:00 2001 From: Pascal Rettig Date: Wed, 6 Oct 2010 19:41:04 -0400 Subject: [PATCH 3/3] Initial spec and detail page changes --- .../user_profile/page_controller.rb | 4 +++- .../controllers/user_profile/page_feature.rb | 8 ++++++- .../user_profile/page_renderer_spec.rb | 21 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb b/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb index d582e95b..f2204965 100644 --- a/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb +++ b/vendor/modules/user_profile/app/controllers/user_profile/page_controller.rb @@ -26,16 +26,18 @@ def profile_type_select_options class ListProfilesOptions < HashModel - attributes :profile_type_id => nil, :order_by => 'newest', :registered_only => true, :per_page => 20, :hide_protected => false + attributes :profile_type_id => nil, :order_by => 'newest', :registered_only => true, :per_page => 20, :hide_protected => false, :profile_detail_page_id => nil validates_presence_of :profile_type_id integer_options :per_page + page_options :profile_detail_page_id boolean_options :registered_only, :hide_protected has_options :order_by, [['Newest','newest'],['Updated','updated'],['Alphabetical','alpha']] options_form(fld(:profile_type_id,:select,:options => :profile_type_select_options), + fld(:profile_detail_page_id, :page_selector, :description => 'Leave blank for cannonical url'), fld(:order_by,:select, :options => :order_by_select_options), fld(:per_page,:text_field), fld(:hide_protected,:yes_no,:description => 'Hide protected users'), diff --git a/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb b/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb index 9436b5e6..853feb4e 100644 --- a/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb +++ b/vendor/modules/user_profile/app/controllers/user_profile/page_feature.rb @@ -50,7 +50,13 @@ def user_profile_page_list_profiles_feature(data) webiva_custom_feature(:user_profile_page_list_profiles,data) do |c| c.loop_tag('user') { |t| data[:users] } c.user_details_tags('user') { |t| t.locals.user.end_user } - c.link_tag('user:') { |t| data[:user_profile_type].content_type.content_link(t.locals.user) } + c.link_tag('user:') do |t| + if data[:options].profile_detail_page_url + "#{data[:options].profile_detail_page_url}/#{t.locals.user.url}" + else + data[:user_profile_type].content_type.content_link(t.locals.user) + end + end c.expansion_tag('user:profile') { |t| t.locals.entry = t.locals.user.content_model_entry if data[:content_model] } c.content_model_fields_value_tags('user:profile',data[:user_profile_type].display_content_model_fields) if data[:content_model] diff --git a/vendor/modules/user_profile/spec/controllers/user_profile/page_renderer_spec.rb b/vendor/modules/user_profile/spec/controllers/user_profile/page_renderer_spec.rb index ebcaf9ea..d138d49d 100644 --- a/vendor/modules/user_profile/spec/controllers/user_profile/page_renderer_spec.rb +++ b/vendor/modules/user_profile/spec/controllers/user_profile/page_renderer_spec.rb @@ -16,6 +16,7 @@ end renderer_builder '/user_profile/page/display_profile' + renderer_builder '/user_profile/page/list_profiles' it "should be able to display the profile page" do @rnd = display_profile_renderer({:profile_type_id => @prof_type.id},:user_profile => [:url,'svend-karlson']) @@ -28,6 +29,26 @@ renderer_get @rnd response.should include_text('no profile exists') end + + + it "should display a list of profile" do + subpage = SiteVersion.default.root.push_subpage('/profile_page') + + UserProfileEntry.fetch_first_entry(@usr).update_attributes(:published => false) + + @usr2 = EndUser.push_target("tester1@webiva.org",:name => 'Svend 3') + UserProfileEntry.fetch_first_entry(@usr2).update_attributes(:published => true) + @usr3 = EndUser.push_target("tester2@webiva.org",:name => 'Svend 2') + UserProfileEntry.fetch_first_entry(@usr3).update_attributes(:published => true) + @rnd = list_profiles_renderer({:profile_type_id => @prof_type.id, :profile_detail_page_id => subpage.id}) + renderer_get @rnd + + response.should include_text('Svend 3') + response.should_not include_text('Svend Karlson') + + + + end end