forked from e621ng/e621ng
added invites
This commit is contained in:
parent
c8afd34d15
commit
04103c3352
@ -1,9 +1,17 @@
|
||||
module Moderator
|
||||
class InvitationsController < ApplicationController
|
||||
before_filter :moderator_only
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def create
|
||||
User.find(params[:invitation][:user_id]).invite!(params[:invitation][:level])
|
||||
redirect_to moderator_invitations_path
|
||||
end
|
||||
|
||||
def index
|
||||
@users = User.where("inviter_id = ?", CurrentUser.id).paginate(params[:page])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,5 +1,7 @@
|
||||
module Moderator
|
||||
class IpAddrsController < ApplicationController
|
||||
before_filter :janitor_only
|
||||
|
||||
def index
|
||||
@search = IpAddrSearch.new(params[:search])
|
||||
end
|
||||
|
10
app/helpers/moderator/invitations_helper.rb
Normal file
10
app/helpers/moderator/invitations_helper.rb
Normal file
@ -0,0 +1,10 @@
|
||||
module Moderator
|
||||
module InvitationsHelper
|
||||
def level_select
|
||||
choices = []
|
||||
choices << ["Privileged", User::Levels::PRIVILEGED]
|
||||
choices << ["Contributor", User::Levels::CONTRIBUTOR]
|
||||
select(:invitation, :level, choices)
|
||||
end
|
||||
end
|
||||
end
|
@ -52,6 +52,16 @@ class User < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
module InvitationMethods
|
||||
def invite!(level)
|
||||
if level.to_i <= Levels::CONTRIBUTOR
|
||||
self.level = level
|
||||
self.inviter_id = CurrentUser.id
|
||||
save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module NameMethods
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
@ -304,6 +314,7 @@ class User < ActiveRecord::Base
|
||||
include BlacklistMethods
|
||||
include ForumMethods
|
||||
include LimitMethods
|
||||
include InvitationMethods
|
||||
|
||||
def initialize_default_image_size
|
||||
self.default_image_size = "Medium"
|
||||
|
13
app/views/moderator/invitations/index.html.erb
Normal file
13
app/views/moderator/invitations/index.html.erb
Normal file
@ -0,0 +1,13 @@
|
||||
<div id="c-moderator-invitations">
|
||||
<div id="a-index">
|
||||
<h1>Invitations</h1>
|
||||
|
||||
<ul>
|
||||
<% @users.each do |user| %>
|
||||
<li><%= link_to user.name, user_path(user) %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<%= numbered_paginator(@users) %>
|
||||
</div>
|
||||
</div>
|
19
app/views/moderator/invitations/new.html.erb
Normal file
19
app/views/moderator/invitations/new.html.erb
Normal file
@ -0,0 +1,19 @@
|
||||
<div id="c-moderator-invitations">
|
||||
<div id="a-new">
|
||||
<h1>New Invitation</h1>
|
||||
|
||||
<%= form_tag(moderator_invitations_path) do %>
|
||||
<div class="input">
|
||||
<label>User</label>
|
||||
<%= text_field :invitation, :user_name %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<label>Level</label>
|
||||
<%= level_select %>
|
||||
</div>
|
||||
|
||||
<%= submit_tag %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
@ -9,6 +9,7 @@ Danbooru::Application.routes.draw do
|
||||
get :search
|
||||
end
|
||||
end
|
||||
resources :invitations, :only => [:new, :create, :index]
|
||||
resource :tag
|
||||
namespace :post do
|
||||
resource :dashboard, :only => [:show]
|
||||
|
@ -5,6 +5,7 @@ Factory.define(:user) do |f|
|
||||
f.email {Faker::Internet.email}
|
||||
f.default_image_size "medium"
|
||||
f.base_upload_limit 10
|
||||
f.level 20
|
||||
end
|
||||
|
||||
Factory.define(:banned_user, :parent => :user) do |f|
|
||||
|
34
test/functional/moderator/invitations_controller_test.rb
Normal file
34
test/functional/moderator/invitations_controller_test.rb
Normal file
@ -0,0 +1,34 @@
|
||||
require 'test_helper'
|
||||
|
||||
module Moderator
|
||||
class InvitationsControllerTest < ActionController::TestCase
|
||||
context "The invitations controller" do
|
||||
setup do
|
||||
@mod = Factory.create(:moderator_user)
|
||||
CurrentUser.user = @mod
|
||||
CurrentUser.ip_addr = "127.0.0.1"
|
||||
MEMCACHE.flush_all
|
||||
|
||||
@user_1 = Factory.create(:user)
|
||||
@user_2 = Factory.create(:user, :inviter_id => @mod.id)
|
||||
end
|
||||
|
||||
should "render the new page" do
|
||||
get :new, {}, {:user_id => @mod.id}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "create a new invite" do
|
||||
post :create, {:invitation => {:user_id => @user_1.id, :level => User::Levels::CONTRIBUTOR}}, {:user_id => @mod.id}
|
||||
assert_redirected_to(moderator_invitations_path)
|
||||
@user_1.reload
|
||||
assert_equal(User::Levels::CONTRIBUTOR, @user_1.level)
|
||||
end
|
||||
|
||||
should "list invites" do
|
||||
get :index
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -13,6 +13,24 @@ class UserTest < ActiveSupport::TestCase
|
||||
CurrentUser.user = nil
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "that has been invited by a mod" do
|
||||
setup do
|
||||
@mod = Factory.create(:moderator_user)
|
||||
end
|
||||
|
||||
should "work" do
|
||||
@user.invite!(User::Levels::CONTRIBUTOR)
|
||||
@user.reload
|
||||
assert_equal(User::Levels::CONTRIBUTOR, @user.level)
|
||||
end
|
||||
|
||||
should "not allow invites up to janitor level or beyond" do
|
||||
@user.invite!(User::Levels::JANITOR)
|
||||
@user.reload
|
||||
assert_equal(User::Levels::MEMBER, @user.level)
|
||||
end
|
||||
end
|
||||
|
||||
should "not validate if the originating ip address is banned" do
|
||||
Factory.create(:ip_ban)
|
||||
|
Loading…
Reference in New Issue
Block a user