Merge pull request #293 from nyanpasu/master
Allow admin/moderator to disable user from inviting
This commit is contained in:
commit
30166dd120
|
@ -30,6 +30,12 @@ class InvitationsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
if !@user.can_invite?
|
||||||
|
flash[:error] = "Your account cannot send invitations"
|
||||||
|
redirect_to "/settings"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
i = Invitation.new
|
i = Invitation.new
|
||||||
i.user_id = @user.id
|
i.user_id = @user.id
|
||||||
i.email = params[:email]
|
i.email = params[:email]
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
before_filter :require_logged_in_moderator, :only => [ :ban, :unban ]
|
before_filter :require_logged_in_moderator, :only => [ :enable_invitation,
|
||||||
|
:disable_invitation,
|
||||||
|
:ban, :unban ]
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@showing_user = User.where(:username => params[:username]).first!
|
@showing_user = User.where(:username => params[:username]).first!
|
||||||
|
@ -37,6 +39,32 @@ class UsersController < ApplicationController
|
||||||
@title = "Pass Along an Invitation"
|
@title = "Pass Along an Invitation"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def disable_invitation
|
||||||
|
target = User.where(:username => params[:username]).first
|
||||||
|
if !target
|
||||||
|
flash[:error] = "Invalid user."
|
||||||
|
redirect_to "/"
|
||||||
|
else
|
||||||
|
target.disable_invite_by_user_for_reason!(@user, params[:reason])
|
||||||
|
|
||||||
|
flash[:success] = "User has had invite capability disabled."
|
||||||
|
redirect_to user_path(:user => target.username)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def enable_invitation
|
||||||
|
target = User.where(:username => params[:username]).first
|
||||||
|
if !target
|
||||||
|
flash[:error] = "Invalid user."
|
||||||
|
redirect_to "/"
|
||||||
|
else
|
||||||
|
target.enable_invite_by_user!(@user)
|
||||||
|
|
||||||
|
flash[:success] = "User has had invite capability enabled."
|
||||||
|
redirect_to user_path(:user => target.username)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def ban
|
def ban
|
||||||
buser = User.where(:username => params[:username]).first
|
buser = User.where(:username => params[:username]).first
|
||||||
if !buser
|
if !buser
|
||||||
|
|
|
@ -18,6 +18,8 @@ class User < ActiveRecord::Base
|
||||||
:class_name => "User"
|
:class_name => "User"
|
||||||
belongs_to :banned_by_user,
|
belongs_to :banned_by_user,
|
||||||
:class_name => "User"
|
:class_name => "User"
|
||||||
|
belongs_to :disabled_invite_by_user,
|
||||||
|
:class_name => "User"
|
||||||
has_many :invitations
|
has_many :invitations
|
||||||
has_many :votes
|
has_many :votes
|
||||||
has_many :voted_stories, -> { where('votes.comment_id' => nil) },
|
has_many :voted_stories, -> { where('votes.comment_id' => nil) },
|
||||||
|
@ -108,6 +110,33 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def disable_invite_by_user_for_reason!(disabler, reason)
|
||||||
|
self.disabled_invite_at = Time.now
|
||||||
|
self.disabled_invite_by_user_id = disabler.id
|
||||||
|
self.disabled_invite_reason = reason
|
||||||
|
|
||||||
|
msg = Message.new
|
||||||
|
msg.deleted_by_author = true
|
||||||
|
msg.author_user_id = disabler.id
|
||||||
|
msg.recipient_user_id = self.id
|
||||||
|
msg.subject = "Your invite privileges have been revoked"
|
||||||
|
msg.body = "The reason given:\n" <<
|
||||||
|
"\n" <<
|
||||||
|
"> *#{reason}*\n" <<
|
||||||
|
"\n" <<
|
||||||
|
"*This is an automated message.*"
|
||||||
|
msg.save
|
||||||
|
|
||||||
|
m = Moderation.new
|
||||||
|
m.moderator_user_id = disabler.id
|
||||||
|
m.user_id = self.id
|
||||||
|
m.action = "Disabled invitations"
|
||||||
|
m.reason = reason
|
||||||
|
m.save!
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def ban_by_user_for_reason!(banner, reason)
|
def ban_by_user_for_reason!(banner, reason)
|
||||||
self.banned_at = Time.now
|
self.banned_at = Time.now
|
||||||
self.banned_by_user_id = banner.id
|
self.banned_by_user_id = banner.id
|
||||||
|
@ -252,6 +281,10 @@ class User < ActiveRecord::Base
|
||||||
banned_at?
|
banned_at?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def can_invite?
|
||||||
|
!disabled_invite_at?
|
||||||
|
end
|
||||||
|
|
||||||
def is_new?
|
def is_new?
|
||||||
Time.now - self.created_at <= NEW_USER_DAYS.days
|
Time.now - self.created_at <= NEW_USER_DAYS.days
|
||||||
end
|
end
|
||||||
|
@ -318,6 +351,21 @@ class User < ActiveRecord::Base
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def enable_invite_by_user!(mod)
|
||||||
|
self.disabled_invite_at = nil
|
||||||
|
self.disabled_invite_by_user_id = nil
|
||||||
|
self.disabled_invite_reason = nil
|
||||||
|
self.save!
|
||||||
|
|
||||||
|
m = Moderation.new
|
||||||
|
m.moderator_user_id = mod.id
|
||||||
|
m.user_id = self.id
|
||||||
|
m.action = "Enabled invitations"
|
||||||
|
m.save!
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def undeleted_received_messages
|
def undeleted_received_messages
|
||||||
received_messages.where(:deleted_by_recipient => false)
|
received_messages.where(:deleted_by_recipient => false)
|
||||||
end
|
end
|
||||||
|
|
|
@ -212,7 +212,11 @@
|
||||||
Invite a New User
|
Invite a New User
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= render :partial => "users/invitationform" %>
|
<% if @user.can_invite? %>
|
||||||
|
<%= render :partial => "users/invitationform" %>
|
||||||
|
<% else %>
|
||||||
|
You cannot send invitations.
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
@ -35,6 +35,9 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= @showing_user.is_admin? ? "administrator" :
|
<%= @showing_user.is_admin? ? "administrator" :
|
||||||
(@showing_user.is_moderator? ? "moderator" : "user") %>
|
(@showing_user.is_moderator? ? "moderator" : "user") %>
|
||||||
|
<% if !@showing_user.can_invite? %>
|
||||||
|
with invites disabled
|
||||||
|
<% end %>
|
||||||
</span>
|
</span>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
@ -187,11 +190,11 @@
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= form_tag user_ban_path, :method => :post do %>
|
|
||||||
<p>
|
<p>
|
||||||
Banning a user will send an e-mail to the user with the reason below,
|
Banning or disabling invites for a user will send an e-mail to the user with the reason below,
|
||||||
with your e-mail address as the Reply-To so the user can respond.
|
with your e-mail address as the Reply-To so the user can respond.
|
||||||
</p>
|
</p>
|
||||||
|
<%= form_tag user_ban_path, :method => :post do %>
|
||||||
<p>
|
<p>
|
||||||
|
|
||||||
<div class="boxline">
|
<div class="boxline">
|
||||||
|
@ -204,5 +207,26 @@
|
||||||
</p>
|
</p>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% if !@showing_user.can_invite? %>
|
||||||
|
<%= form_tag user_enable_invite_path, :method => :post do %>
|
||||||
|
<p>
|
||||||
|
<%= submit_tag "Enable invitations for User" %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
<% else %>
|
||||||
|
<%= form_tag user_disable_invite_path, :method => :post do %>
|
||||||
|
<p>
|
||||||
|
|
||||||
|
<div class="boxline">
|
||||||
|
<%= label_tag :reason, "Reason:", :class => "required" %>
|
||||||
|
<%= text_field_tag :reason, "", :size => 40 %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= submit_tag "Disable invites" %>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -95,6 +95,8 @@ Lobsters::Application.routes.draw do
|
||||||
|
|
||||||
post "/users/:username/ban" => "users#ban", :as => "user_ban"
|
post "/users/:username/ban" => "users#ban", :as => "user_ban"
|
||||||
post "/users/:username/unban" => "users#unban", :as => "user_unban"
|
post "/users/:username/unban" => "users#unban", :as => "user_unban"
|
||||||
|
post "/users/:username/disable_invitation" => "users#disable_invitation", :as => "user_disable_invite"
|
||||||
|
post "/users/:username/enable_invitation" => "users#enable_invitation", :as => "user_enable_invite"
|
||||||
|
|
||||||
get "/settings" => "settings#index"
|
get "/settings" => "settings#index"
|
||||||
post "/settings" => "settings#update"
|
post "/settings" => "settings#update"
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
class AddDisabledInvitesToUsers < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :users, :disabled_invite_at, :datetime
|
||||||
|
add_column :users, :disabled_invite_by_user_id, :integer
|
||||||
|
add_column :users, :disabled_invite_reason, :string, {limit: 200}
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160406160019) do
|
ActiveRecord::Schema.define(version: 20160515162433) do
|
||||||
|
|
||||||
create_table "comments", force: true do |t|
|
create_table "comments", force: true do |t|
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
|
@ -212,6 +212,9 @@ ActiveRecord::Schema.define(version: 20160406160019) do
|
||||||
t.boolean "show_avatars", default: false
|
t.boolean "show_avatars", default: false
|
||||||
t.boolean "show_story_previews", default: false
|
t.boolean "show_story_previews", default: false
|
||||||
t.boolean "show_submitted_story_threads", default: true
|
t.boolean "show_submitted_story_threads", default: true
|
||||||
|
t.datetime disabled_invite_at
|
||||||
|
t.integer disabled_invite_by_user_id
|
||||||
|
t.string disabled_invite_reason, limit: 200
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "users", ["mailing_list_mode"], name: "mailing_list_enabled", using: :btree
|
add_index "users", ["mailing_list_mode"], name: "mailing_list_enabled", using: :btree
|
||||||
|
|
Loading…
Reference in a new issue