diff --git a/app/controllers/invitations_controller.rb b/app/controllers/invitations_controller.rb
index e750fb1..8485cb3 100644
--- a/app/controllers/invitations_controller.rb
+++ b/app/controllers/invitations_controller.rb
@@ -30,6 +30,12 @@ class InvitationsController < ApplicationController
end
def create
+ if !@user.can_invite?
+ flash[:error] = "Your account cannot send invitations"
+ redirect_to "/settings"
+ return
+ end
+
i = Invitation.new
i.user_id = @user.id
i.email = params[:email]
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index c7db870..4a6e178 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,5 +1,7 @@
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
@showing_user = User.where(:username => params[:username]).first!
@@ -37,6 +39,32 @@ class UsersController < ApplicationController
@title = "Pass Along an Invitation"
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
buser = User.where(:username => params[:username]).first
if !buser
diff --git a/app/models/user.rb b/app/models/user.rb
index aa882de..7927195 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -18,6 +18,8 @@ class User < ActiveRecord::Base
:class_name => "User"
belongs_to :banned_by_user,
:class_name => "User"
+ belongs_to :disabled_invite_by_user,
+ :class_name => "User"
has_many :invitations
has_many :votes
has_many :voted_stories, -> { where('votes.comment_id' => nil) },
@@ -108,6 +110,33 @@ class User < ActiveRecord::Base
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)
self.banned_at = Time.now
self.banned_by_user_id = banner.id
@@ -252,6 +281,10 @@ class User < ActiveRecord::Base
banned_at?
end
+ def can_invite?
+ !disabled_invite_at?
+ end
+
def is_new?
Time.now - self.created_at <= NEW_USER_DAYS.days
end
@@ -318,6 +351,21 @@ class User < ActiveRecord::Base
true
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
received_messages.where(:deleted_by_recipient => false)
end
diff --git a/app/views/settings/index.html.erb b/app/views/settings/index.html.erb
index c737a79..2d11ef0 100644
--- a/app/views/settings/index.html.erb
+++ b/app/views/settings/index.html.erb
@@ -212,7 +212,11 @@
Invite a New User
- <%= render :partial => "users/invitationform" %>
+ <% if @user.can_invite? %>
+ <%= render :partial => "users/invitationform" %>
+ <% else %>
+ You cannot send invitations.
+ <% end %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index ce2ad6a..258dd40 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -35,6 +35,9 @@
<% end %>
<%= @showing_user.is_admin? ? "administrator" :
(@showing_user.is_moderator? ? "moderator" : "user") %>
+ <% if !@showing_user.can_invite? %>
+ with invites disabled
+ <% end %>
@@ -187,11 +190,11 @@
- 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.
+ <%= form_tag user_ban_path, :method => :post do %>
+ <%= submit_tag "Enable invitations for User" %> +
+ <% end %> + <% else %> + <%= form_tag user_disable_invite_path, :method => :post do %> ++ +
+ <%= submit_tag "Disable invites" %> +
+ <% end %> + <% end %> <% end %>