Skip to content

Commit

Permalink
Fix sudo.
Browse files Browse the repository at this point in the history
  • Loading branch information
sudara committed Dec 9, 2013
1 parent d6935c5 commit da0bcf2
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 22 deletions.
16 changes: 16 additions & 0 deletions app/assets/stylesheets/application/alonetone.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1085,4 +1085,20 @@ h2.stats {

.listen_details a {
line-height: 14px;
}

// sudo bar

.sudo_bar{
background-color:red;
height:25px;
line-height:25px;
padding-left:55px;
text-align:left;
font-size: 12px;
color: #fff;
a{
text-decoration: underline;
color:white;
}
}
19 changes: 12 additions & 7 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,22 @@ def dangerous_action?

def change_user_to(user)
current_user_session.destroy
UserSession.create!(user)
flash[:ok] = "Sudo to #{user.name}"
user.reset_persistence_token! if !user.persistence_token.present?
session = UserSession.create(user)
flash[:ok] = "Changed user to #{user.name}"
redirect_back_or_default
end

def sudo_to_user
return false unless params[:id]
user = User.where(:login => params[:id]).first
logger.warn("SUDO: #{current_user.name} is sudoing to #{user.name}")
@sudo = session[:sudo] = current_user.id
change_user_to user
raise "No user specified" unless params[:id]
new_user = User.where(:login => params[:id]).first
if new_user.present?
logger.warn("SUDO: #{current_user.name} is sudoing to #{new_user.name}")
@sudo = session[:sudo] = current_user.id
change_user_to new_user
else
flash[:warn] = "Well, that user doesn't exist, broseph"
end
end

def return_from_sudo_if_sudoed
Expand Down
5 changes: 5 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<body>
<div id="container">

<% if @sudo %>
<div class="sudo_bar">
Sudo'd as <%= current_user.name %>. <%= link_to 'Return to admin.', sudo_user_path(@sudo) %></span>
</div>
<% end %>
<div id="top_bar">
<%= render :partial => 'shared/top_bar', :current_user => current_user %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_comments.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
</div>
<div class="footer_box">
<%= link_to 'view all comments &rArr;'.html_safe, user_comments_path(@user.login),
:class => 'view_all', :title => "all comments about #{h @user.name}'s music" %>
:class => 'view_all', :title => "all comments about #{@user.name}'s music" %>
</div>
4 changes: 0 additions & 4 deletions app/views/shared/_top_bar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
<%= link_to ' ', '/radio/popular', :id => 'radio_button'%>
<%= link_to ' ', about_path, :id => 'about_button'%>
<%= link_to ' ', about_path(:howto), :id => 'halp_button'%>
<% if @sudo %>
<span class="important">Sudo'd as <%= current_user.name %>. <%= link_to 'return to admin account', sudo_user_path(@user) %></span>
<% end %>
</div>
<div id="top_bar_right">
<% if logged_in? %>
Expand Down
12 changes: 6 additions & 6 deletions app/views/users/_user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
</div>
<div id="user_links">
<ul class="user_links">
<%= user_nav_item "Home", user_home_path(@user), :title => "#{h @user.name} on alonetone" %>
<%= user_nav_item "Tracks", user_tracks_path(@user), :title => "#{h @user.name}'s uploaded mp3s on alonetone" if @user.assets_count > 0 %>
<%= user_nav_item "Playlists", user_playlists_path(@user.login), :title => "#{h @user.name}'s albums and playlists on alonetone" if @user.has_public_playlists? || (authorized_as(@user) && @user.playlists.include_private.count > 0) %>
<%= user_nav_item "Favorites", user_playlist_path(@user, @user.favorites),:title => "#{h @user.name}'s favorite tracks on alonetone" if @user.favorites.present? %>
<%= user_nav_item "Profile", profile_path(@user), :title => "#{h @user.name}'s profile on alonetone" if @user.bio %>
<%= user_nav_item "Home", user_home_path(@user), :title => "#{@user.name} on alonetone" %>
<%= user_nav_item "Tracks", user_tracks_path(@user), :title => "#{@user.name}'s uploaded mp3s on alonetone" if @user.assets_count > 0 %>
<%= user_nav_item "Playlists", user_playlists_path(@user.login), :title => "#{@user.name}'s albums and playlists on alonetone" if @user.has_public_playlists? || (authorized_as(@user) && @user.playlists.include_private.count > 0) %>
<%= user_nav_item "Favorites", [@user, @user.favorites], :title => "#{@user.name}'s favorite tracks on alonetone" if @user.favorites.present? %>
<%= user_nav_item "Profile", profile_path(@user), :title => "#{@user.name}'s profile on alonetone" if @user.bio %>
<%= user_nav_item "Email", "mailto:#{@user.email}",:added_class => "contact" if admin? %>
<%= user_nav_item "iTunes", "http://#{@user.itunes}",:added_class => "contact" if @user.itunes.present? %>
<%= user_nav_item "Twitter", "http://twitter.com/#{@user.twitter}", :added_class => 'contact' if @user.twitter.present? %>
<%= user_nav_item "Sudo", sudo_user_path(@user),:added_class => "contact" if (admin? || @sudo)%>
<%= user_nav_item "Sudo", sudo_user_path(@user), :added_class => "contact" if (admin? || @sudo)%>
</ul>
</div>
</div>
6 changes: 3 additions & 3 deletions app/views/users/index.rss.builder
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ xml.rss "version" => "2.0",

for @user in @users do
xml.item do
xml.title "#{h @user.name} on alonetone"
xml.author "#{h @user.name}"
xml.title "#{@user.name} on alonetone"
xml.author "#{@user.name}"
xml.link user_home_url(@user)
xml.description "#{image_tag(@user.avatar(:large))}
<br/>#{h @user.name}
<br/>#{@user.name}
#{ @user.printable_bio if @user.bio }
#{(@user.assets_count > 0) ? ('has '+ pluralize(@user.assets_count.to_s, 'track') + ' on alonetone <br/>') : ''}<br/>
#{ link_to 'view more',user_home_url(@user)}"
Expand Down
2 changes: 1 addition & 1 deletion lib/authlogic_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def current_user_session

def current_user
return @current_user if defined?(@current_user)
@current_user= current_user_session && current_user_session.user
@current_user= current_user_session && current_user_session.record
end


Expand Down

0 comments on commit da0bcf2

Please sign in to comment.