Skip to content

Commit f54aeea

Browse files
committed
extract admin panel to a partial
1 parent d853d60 commit f54aeea

File tree

5 files changed

+31
-44
lines changed

5 files changed

+31
-44
lines changed

app/controllers/application_controller.rb

-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ def ensure_and_reconcile_tracking_code
107107

108108
def sign_out
109109
record_event("signed out")
110-
@current_user = nil
111-
session[:current_user] = nil
112110
cookies.delete(:signedin)
113111
reset_session
114112
end

app/controllers/sessions_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def force
1616
#REMOVEME
1717
head(:forbidden) unless current_user.admin?
1818
sign_out
19-
sign_in(@user = User.find_by_username(params[:username]))
20-
redirect_to(badge_url(username: params[:username]))
19+
sign_in(User.find(params[:id]))
20+
redirect_to(root_url)
2121
end
2222

2323
def create
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-if is_admin?
2+
.hint-box
3+
ul.hint
4+
li= mail_to(user.email)
5+
li= "Total Views: #{user.total_views}"
6+
li= "Last Request: #{time_ago_in_words(user.last_request_at || Time.at(0))} ago"
7+
li= "Login Count: #{user.login_count}"
8+
li= "Achievements last reviewed #{time_ago_in_words(user.achievements_checked_at)} ago"
9+
li= "Score: #{user.score}"
10+
- if user.banned?
11+
li
12+
Banned:
13+
= user.banned_at.to_s(:long)
14+
li.admin-action= link_to("Impersonate", "/sessions/force?id=#{user.id}")
15+
li.admin-action
16+
- if user.banned?
17+
=link_to("Unban this user", user_unbans_path(user), method: :post)
18+
- else
19+
=link_to("Ban this user", user_bans_path(user), method: :post)
20+
li.admin-action= link_to_if(user.twitter,'Clear Twitter!', clear_provider_path(user, :provider => 'twitter'), :confirm => 'Are you sure?')
21+
li.admin-action= link_to_if(user.github,'Clear GitHub!', clear_provider_path(user, :provider => 'github'), :confirm => 'Are you sure?')
22+
-if user.linkedin || user.linkedin_id
23+
li.admin-action
24+
=link_to('Clear LinkedIn!', clear_provider_path(user, :provider => 'linkedin'), :confirm => 'Are you sure?')
25+
li.admin-action
26+
=link_to('Delete Facts', clear_provider_path(user, :provider => 'facts'), :confirm => 'Are you sure?', :method => :delete)
27+
li.admin-action= link_to('Delete User', user_path(user), :confirm => 'Are you sure?', :method => :delete)

app/views/users/edit.html.slim

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
.save= submit_tag 'Save', class: 'button'
171171

172172
-if @user.membership.present?
173-
#team_section.editsection class="#{@user.membership.admin? ? '' : 'hide'}"
173+
#team_section.editsection.hide
174174
p.team-title
175175
|Updating team
176176
= link_to(@user.team.name, teamname_url(slug: @user.team.slug, full: :preview))

app/views/users/show.html.haml

+1-39
Original file line numberDiff line numberDiff line change
@@ -199,42 +199,4 @@
199199
%h4 HTML code
200200
=text_area_tag 'HTML', html_embed_code_with_count
201201

202-
-if is_admin?
203-
.hint-box
204-
%ul.hint
205-
%li=mail_to(@user.email)
206-
%li
207-
==Total Views: #{@user.total_views}
208-
%li
209-
==Last Request: #{time_ago_in_words(@user.last_request_at || Time.at(0))} ago
210-
%li
211-
==Login Count: #{@user.login_count}
212-
%li
213-
==Achievements last reviewed #{time_ago_in_words(@user.achievements_checked_at)} ago
214-
%li
215-
==Score: #{@user.score}
216-
- if @user.banned?
217-
%li
218-
Banned:
219-
= @user.banned_at.to_s(:long)
220-
%li.admin-action
221-
=link_to("Impersonate", "/sessions/force?username=#{@user.username}")
222-
%li.admin-action
223-
- if @user.banned?
224-
=link_to("Unban this user", user_unbans_path(@user), method: :post)
225-
- else
226-
=link_to("Ban this user", user_bans_path(@user), method: :post)
227-
-if @user.twitter
228-
%li.admin-action
229-
=link_to('Clear Twitter!', clear_provider_path(@user, :provider => 'twitter'), :confirm => 'Are you sure?')
230-
-if @user.github
231-
%li.admin-action
232-
=link_to('Clear GitHub!', clear_provider_path(@user, :provider => 'github'), :confirm => 'Are you sure?')
233-
-if @user.linkedin || @user.linkedin_id
234-
%li.admin-action
235-
=link_to('Clear LinkedIn!', clear_provider_path(@user, :provider => 'linkedin'), :confirm => 'Are you sure?')
236-
237-
%li.admin-action
238-
=link_to('Delete Facts', clear_provider_path(@user, :provider => 'facts'),:confirm => 'Are you sure?', :method => :delete)
239-
%li.admin-action
240-
=link_to('Delete User', user_path(@user),:confirm => 'Are you sure?', :method => :delete)
202+
= render('show_admin_panel', user: @user) if is_admin?

0 commit comments

Comments
 (0)