Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAEWDGT-58 Implement noscript fallback for user management, OAEWDGT-169 Implement functionality to delete users from the system #112

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions app/assets/javascripts/admin.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
$(function() {

$('.wl-no-script').hide();

var reject_widget = function() {
$( "#admin_action_buttons" ).hide();
$(".widget_confirmation").hide();
$("#reject_confirm").show();
$('#admin_action_buttons').hide();
$('.widget_confirmation').hide();
$('#reject_confirm').show();
};

var finalize_rejection = function( versionid ) {
Expand Down
10 changes: 9 additions & 1 deletion app/assets/stylesheets/admin.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
margin: 0;
li {
display: inline-block;
float: left;
margin: 12px 0;
width: 33%;
}
Expand All @@ -80,6 +79,15 @@
float: right;
margin-right: 60px;
}
a.wl-button {
margin: auto;
}
}
.wl-save-fallback {
font: 13px/1.231 Arial,Helvetica,sans-serif;
font-weight: bold;
height: 15px;
width: 25px;
}
.admin-table {
color: #333;
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ def user_update
user.admin = params["chk_user_admin" + params[:user_id]]
user.reviewer = params["chk_user_reviewer" + params[:user_id]]
user.save
head :ok
redirect_to request.referer
end

def delete_user
User.find(params[:id]).destroy
redirect_to request.referer
end

def options
Expand Down
10 changes: 7 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
class User < ActiveRecord::Base
include ValidatesAsImage
before_save :calculate_fields
after_destroy :destroy_inactive_widgets

has_attached_file :avatar,
:styles => {
:thumb => ["50x50!", :png],
:medium => ["100x100!", :png],
:large => ["800x800", :png] },
:default_url => "register_default_image.jpg"
has_many :widgets
has_many :downloads
has_many :widgets, :dependent => :destroy
has_many :downloads, :dependent => :destroy

# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable,
Expand Down Expand Up @@ -62,5 +63,8 @@ def calculate_fields
self.name = "#{self.first_name} #{self.last_name}"
self.url_title = "#{self.first_name.to_s.downcase}-#{self.last_name.to_s.downcase}"
end

def destroy_inactive_widgets
Widget.where("user_id = ?", self.id).destroy_all
Rating.where("user_id = ?", self.id).destroy_all
end
end
19 changes: 15 additions & 4 deletions app/views/admin/_user.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<% @users.each do |user| %>
<li>
<%= form_tag("/admin/users/update", :method => "POST", :remote => true) do %>
<% @users.each_with_index do |user, index| %>
<% if index % 3 == 0 %>
<div class="wl-push">
<% end %>
<li class="wl-left">
<%= form_for user, :url => "/admin/users/update", :method => "POST", :remote => true do |f| %>
<%= image_tag user.avatar.url(:thumb), :alt => "#{user.name}'s Photo", :class => "wl-left"%>
<%= link_to user.name, user_path(:id => user.id, :url_title => user.url_title), :class => "wl-bold wl-regular-link", :target => "_blank" %><br/>
<%= link_to user.name, user_path(:id => user.id, :url_title => user.url_title), :class => "wl-bold wl-regular-link", :target => "_blank" %>
-
<%= link_to "Delete", admin_delete_user_path(user), :confirm => "Are you sure you want to delete this user?", :class => "wl-bold wl-regular-link", :method => "delete" %>
<span class="wl-no-script">-</span>
<%= button_tag "Save", :class => "wl-no-script wl-button wl-link-button wl-regular-link wl-save-fallback" %>
<br/>
<input type="hidden" name="user_id" value="<%= user.id %>">
<label class="label" for="chk_user_admin<%= user.id %>">Administrator:</label>
<% if user_signed_in? && current_user.id != user.id %>
Expand All @@ -18,4 +26,7 @@
<% end %>
<% end %>
</li>
<% if (index + 1) % 3 == 0 %>
</div>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
# Admin section
match '/admin/users' => 'admin#users', :as => :admin_users
match '/admin/users/admin' => 'admin#adminusers', :as => :admin_admin_users
match '/admin/users/delete/:id' => 'admin#delete_user', :as => :admin_delete_user
match '/admin/options' => 'admin#options', :as => :admin_options
match '/admin/languages/edit/:id' => 'admin#edit_language', :as => :admin_edit_language
post '/admin/languages/save' => 'admin#save_language', :as => :admin_add_edit_language
Expand Down