commit
6c669aab6e
@ -0,0 +1,5 @@ |
||||
.no-padding-bottom |
||||
padding-bottom: 0 !important |
||||
|
||||
.display-inline |
||||
display: inline !important |
@ -0,0 +1,84 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
## |
||||
# Intended to be used by the UsersController to enforce the user limit. |
||||
module Concerns::UserLimits |
||||
def enforce_user_limit(redirect_to: users_path, hard: OpenProject::Enterprise.fail_fast?) |
||||
if user_limit_reached? |
||||
if hard |
||||
show_user_limit_error! |
||||
|
||||
redirect_back fallback_location: redirect_to |
||||
else |
||||
show_user_limit_warning! |
||||
end |
||||
|
||||
true |
||||
else |
||||
false |
||||
end |
||||
end |
||||
|
||||
def enforce_activation_user_limit(redirect_to: signin_path) |
||||
if user_limit_reached? |
||||
show_user_limit_activation_error! |
||||
|
||||
redirect_back fallback_location: redirect_to |
||||
|
||||
true |
||||
else |
||||
false |
||||
end |
||||
end |
||||
|
||||
def show_user_limit_activation_error! |
||||
flash[:error] = I18n.t(:error_enterprise_activation_user_limit) |
||||
end |
||||
|
||||
def show_user_limit_warning! |
||||
flash[:warning] = user_limit_warning |
||||
end |
||||
|
||||
def show_user_limit_error! |
||||
flash[:error] = user_limit_warning |
||||
end |
||||
|
||||
def user_limit_warning |
||||
warning = I18n.t( |
||||
:warning_user_limit_reached, |
||||
upgrade_url: OpenProject::Enterprise.upgrade_path |
||||
) |
||||
|
||||
warning.html_safe |
||||
end |
||||
|
||||
def user_limit_reached? |
||||
OpenProject::Enterprise.user_limit_reached? |
||||
end |
||||
end |
@ -0,0 +1,67 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module OpenProject |
||||
module Enterprise |
||||
class << self |
||||
def token |
||||
EnterpriseToken.current.presence |
||||
end |
||||
|
||||
def upgrade_path |
||||
url_helpers.enterprise_path |
||||
end |
||||
|
||||
def user_limit |
||||
Hash(token.restrictions)[:active_user_count] if token |
||||
end |
||||
|
||||
def active_user_count |
||||
User.active.count |
||||
end |
||||
|
||||
## |
||||
# Indicates if there are more active users than the support token allows for. |
||||
# |
||||
# @return [Boolean] True if and only if there is a support token the user limit of which is exceeded. |
||||
def user_limit_reached? |
||||
active_user_count >= user_limit if user_limit |
||||
end |
||||
|
||||
def fail_fast? |
||||
Hash(OpenProject::Configuration["enterprise"])["fail_fast"] |
||||
end |
||||
|
||||
private |
||||
|
||||
def url_helpers |
||||
@url_helpers ||= OpenProject::StaticRouting::StaticUrlHelpers.new |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,80 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
require 'open_project/passwords' |
||||
|
||||
describe OpenProject::Enterprise do |
||||
describe "#user_limit_reached?" do |
||||
let(:user_limit) { 2 } |
||||
|
||||
before do |
||||
allow(OpenProject::Enterprise).to receive(:user_limit).and_return(user_limit) |
||||
end |
||||
|
||||
context "with fewer active users than the limit allows" do |
||||
before do |
||||
FactoryGirl.create :user |
||||
|
||||
expect(User.active.count).to eq 1 |
||||
end |
||||
|
||||
it "is false" do |
||||
expect(subject).not_to be_user_limit_reached |
||||
end |
||||
end |
||||
|
||||
context "with equal or more active users than the limit allows" do |
||||
shared_examples "user limit is reached" do |
||||
let(:num_active_users) { 0 } |
||||
|
||||
before do |
||||
(1..num_active_users).each { |_i| FactoryGirl.create :user } |
||||
|
||||
expect(User.active.count).to eq num_active_users |
||||
end |
||||
|
||||
it "is true" do |
||||
expect(subject).to be_user_limit_reached |
||||
end |
||||
end |
||||
|
||||
context "(equal)" do |
||||
it_behaves_like "user limit is reached" do |
||||
let(:num_active_users) { user_limit } |
||||
end |
||||
end |
||||
|
||||
context "(more)" do |
||||
it_behaves_like "user limit is reached" do |
||||
let(:num_active_users) { user_limit + 1 } |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,73 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||
# Copyright (C) 2010-2013 the ChiliProject Team |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License |
||||
# as published by the Free Software Foundation; either version 2 |
||||
# of the License, or (at your option) any later version. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, |
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
# GNU General Public License for more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License |
||||
# along with this program; if not, write to the Free Software |
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe 'users/index', type: :view do |
||||
let!(:admin) { FactoryGirl.create :admin } |
||||
let!(:user) { FactoryGirl.create :user, firstname: "Scarlet", lastname: "Scallywag" } |
||||
|
||||
before do |
||||
assign(:users, [admin, user]) |
||||
assign(:status, "all") |
||||
assign(:groups, Group.all) |
||||
|
||||
allow(view).to receive(:current_user).and_return(admin) |
||||
|
||||
allow_any_instance_of(TableCell).to receive(:controller_name).and_return("users") |
||||
allow_any_instance_of(TableCell).to receive(:action_name).and_return("index") |
||||
end |
||||
|
||||
it 'renders the user table' do |
||||
render |
||||
|
||||
expect(rendered).to have_text(admin.name) |
||||
expect(rendered).to have_text("Scarlet Scallywag") |
||||
end |
||||
|
||||
context "with an Enterprise token" do |
||||
before do |
||||
allow(OpenProject::Enterprise).to receive(:token).and_return(Struct.new(:restrictions).new({active_user_count: 5})) |
||||
end |
||||
|
||||
it "shows the current number of active and allowed users" do |
||||
render |
||||
|
||||
# expected active users: admin and user from above |
||||
expect(rendered).to have_text("2/5 booked active users") |
||||
end |
||||
end |
||||
|
||||
context "without an Enterprise token" do |
||||
it "does not show the current number of active and allowed users" do |
||||
render |
||||
|
||||
expect(rendered).not_to have_text("booked active users") |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue