!@user.nil?
end
+ ##
+ # ensure that there is a "this_user" instance variable
+ def lookup_this_user
+ unless @this_user = User.active.find_by_display_name(params[:display_name])
+ render_unknown_user params[:display_name]
+ end
+ end
+
##
# render a "no such user" page
def render_unknown_user(name)
before_filter :authorize_web
before_filter :set_locale
before_filter :require_user, :only => [:new, :edit, :comment, :hide, :hidecomment]
+ before_filter :lookup_this_user, :only => [:view, :comments]
before_filter :check_database_readable
before_filter :check_database_writable, :only => [:new, :edit]
before_filter :require_administrator, :only => [:hide, :hidecomment]
end
def view
- user = User.active.find_by_display_name(params[:display_name])
-
- if user
- @entry = user.diary_entries.visible.where(:id => params[:id]).first
- if @entry
- @title = t 'diary_entry.view.title', :user => params[:display_name], :title => @entry.title
- else
- @title = t 'diary_entry.no_such_entry.title', :id => params[:id]
- render :action => 'no_such_entry', :status => :not_found
- end
+ @entry = @this_user.diary_entries.visible.where(:id => params[:id]).first
+ if @entry
+ @title = t 'diary_entry.view.title', :user => params[:display_name], :title => @entry.title
else
- render_unknown_user params[:display_name]
+ @title = t 'diary_entry.no_such_entry.title', :id => params[:id]
+ render :action => 'no_such_entry', :status => :not_found
end
end
end
def comments
- @this_user = User.active.find_by_display_name(params[:display_name])
-
- if @this_user
- @comment_pages, @comments = paginate(:diary_comments,
- :conditions => { :user_id => @this_user },
- :order => 'created_at DESC',
- :per_page => 20)
- @page = (params[:page] || 1).to_i
- else
- render_unknown_user params[:display_name]
- end
+ @comment_pages, @comments = paginate(:diary_comments,
+ :conditions => { :user_id => @this_user },
+ :order => 'created_at DESC',
+ :per_page => 20)
+ @page = (params[:page] || 1).to_i
end
private
##
before_filter :authorize_web
before_filter :set_locale
before_filter :require_user
+ before_filter :lookup_this_user, :only => [:new]
before_filter :check_database_readable
before_filter :check_database_writable, :only => [:new, :reply, :mark]
# clicks send.
# The display_name param is the display name of the user that the message is being sent to.
def new
- @to_user = User.find_by_display_name(params[:display_name])
- if @to_user
- if params[:message]
- if @user.sent_messages.where("sent_on >= ?", Time.now.getutc - 1.hour).count >= MAX_MESSAGES_PER_HOUR
- flash[:error] = t 'message.new.limit_exceeded'
- else
- @message = Message.new(params[:message])
- @message.to_user_id = @to_user.id
- @message.from_user_id = @user.id
- @message.sent_on = Time.now.getutc
-
- if @message.save
- flash[:notice] = t 'message.new.message_sent'
- Notifier.message_notification(@message).deliver
- redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
- end
- end
+ if params[:message]
+ if @user.sent_messages.where("sent_on >= ?", Time.now.getutc - 1.hour).count >= MAX_MESSAGES_PER_HOUR
+ flash[:error] = t 'message.new.limit_exceeded'
else
- if params[:title]
- # ?title= is set when someone reponds to this user's diary
- # entry. Then we pre-fill out the subject and the <title>
- @title = @subject = params[:title]
- else
- # The default /message/new/$user view
- @title = t 'message.new.title'
+ @message = Message.new(params[:message])
+ @message.to_user_id = @this_user.id
+ @message.from_user_id = @user.id
+ @message.sent_on = Time.now.getutc
+
+ if @message.save
+ flash[:notice] = t 'message.new.message_sent'
+ Notifier.message_notification(@message).deliver
+ redirect_to :controller => 'message', :action => 'inbox', :display_name => @user.display_name
end
end
else
- render_unknown_user params[:display_name]
+ if params[:title]
+ # ?title= is set when someone reponds to this user's diary
+ # entry. Then we pre-fill out the subject and the <title>
+ @title = @subject = params[:title]
+ else
+ # The default /message/new/$user view
+ @title = t 'message.new.title'
+ end
end
end
end
end
- ##
- # ensure that there is a "this_user" instance variable
- def lookup_this_user
- unless @this_user = User.find_by_display_name(params[:display_name])
- render_unknown_user params[:display_name]
- end
- end
-
##
# ensure that there is a "user_block" instance variable
def lookup_user_block
end
end
- ##
- # ensure that there is a "this_user" instance variable
- def lookup_this_user
- unless @this_user = User.find_by_display_name(params[:display_name])
- render_unknown_user params[:display_name]
- end
- end
-
##
# require that the given role is valid. the role is a URL
# parameter, so should always be present.