Commit 70b9d8da authored by Pawel Chojnacki's avatar Pawel Chojnacki

Remove unecessary defaults for uniq ip block, cleanup refactoring leftovers

parent 8a9bc24e
......@@ -4,8 +4,8 @@ class AddUniqueIpsLimitToApplicationSettings < ActiveRecord::Migration
disable_ddl_transaction!
def up
add_column_with_default :application_settings, :unique_ips_limit_per_user, :integer, default: 10
add_column_with_default :application_settings, :unique_ips_limit_time_window, :integer, default: 3600
add_column :application_settings, :unique_ips_limit_per_user, :integer
add_column :application_settings, :unique_ips_limit_time_window, :integer
add_column_with_default :application_settings, :unique_ips_limit_enabled, :boolean, default: false
end
......
......@@ -111,11 +111,10 @@ ActiveRecord::Schema.define(version: 20170305203726) do
t.boolean "plantuml_enabled"
t.integer "max_pages_size", default: 100, null: false
t.integer "terminal_max_session_time", default: 0, null: false
(??) t.string "default_artifacts_expire_in", default: '0', null: false
t.integer "unique_ips_limit_per_user", default: 10, null: false
t.integer "unique_ips_limit_time_window", default: 3600, null: false
t.boolean "unique_ips_limit_enabled", default: false, null: false
t.string "default_artifacts_expire_in", default: "0", null: false
t.integer "unique_ips_limit_per_user"
t.integer "unique_ips_limit_time_window"
t.boolean "unique_ips_limit_enabled", default: false, null: false
end
create_table "audit_events", force: :cascade do |t|
......@@ -587,9 +586,9 @@ ActiveRecord::Schema.define(version: 20170305203726) do
end
add_index "labels", ["group_id", "project_id", "title"], name: "index_labels_on_group_id_and_project_id_and_title", unique: true, using: :btree
add_index "labels", ["type", "project_id"], name: "index_labels_on_type_and_project_id", using: :btree
add_index "labels", ["project_id"], name: "index_labels_on_project_id", using: :btree
add_index "labels", ["title"], name: "index_labels_on_title", using: :btree
add_index "labels", ["type", "project_id"], name: "index_labels_on_type_and_project_id", using: :btree
create_table "lfs_objects", force: :cascade do |t|
t.string "oid", null: false
......
......@@ -8,12 +8,13 @@ module Gitlab
if config.unique_ips_limit_enabled
ip = RequestContext.client_ip
unique_ips = update_and_return_ips_count(user_id, ip)
raise TooManyIps.new(user_id, ip, unique_ips) if unique_ips > config.unique_ips_limit_per_user
end
end
def limit_user!(user = nil)
user = yield if user.nil? && block_given?
user ||= yield if block_given?
limit_user_id!(user.id) unless user.nil?
user
end
......
module Gitlab
RequestStoreNotActive = Class.new(StandardError)
class RequestContext
class << self
def client_ip
......
......@@ -22,7 +22,7 @@ describe Gitlab::RequestContext, lib: true do
it { is_expected.to eq(ip) }
end
context 'before RequestContext mw run' do
context 'before RequestContext middleware run' do
it { is_expected.to be_nil }
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment