Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use resource on company #5

Merged
merged 5 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 21, 2013
  1. refs #7126 allow usage of resources per company

    Bfleischmann authored
Commits on Mar 22, 2013
  1. specs for use resource rules

    Bfleischmann authored
  2. turn allow_resources to use_resource on company

    Bfleischmann authored
  3. integration specs for use resources

    Bfleischmann authored
  4. use resources integration specs updated

    Bfleischmann authored
This page is out of date. Refresh to see the latest.
View
1  app/models/company.rb
@@ -15,6 +15,7 @@ class Company < ActiveRecord::Base
has_many :customers, :dependent => :destroy, :order => "lower(customers.name)"
has_many :users, :dependent => :destroy
+ has_one :admin, :class_name => "User", :conditions => "admin = 1"
has_many :projects, :dependent => :destroy, :order => "lower(projects.name)"
has_many :milestones
has_many :tasks, :class_name => "TaskRecord"
View
4 app/models/user.rb
@@ -371,6 +371,10 @@ def self.find_for_authentication(conditions={})
super(conditions)
end
+ def use_resources?
+ use_resources && company.use_resources
+ end
+
protected
def password_required?
View
2  app/views/companies/_navigation.html.erb
@@ -52,9 +52,11 @@
<li class="<%= active_class(selected, "task-properties") %>">
<a href="<%= properties_path %>">Task</a>
</li>
+ <% if current_user.use_resources? %>
<li class="<%= active_class(selected, "resource-type") %>">
<a href="<%= resource_types_path %>">Resource Types</a>
</li>
+ <% end %>
</ul>
</div>
View
7 app/views/companies/_settings.html.erb
@@ -13,6 +13,13 @@
</div>
<div class="control-group">
+ <label for="company_use_resources"><%=_ 'Use Resources' %></label>
+ <div class="controls">
+ <%= check_box 'company', 'use_resources' %>
+ </div>
+</div>
+
+<div class="control-group">
<label for="company_suppressed_email_addresses"><%= _('Suppressed email addresses') %></label>
<div class="controls">
<%= text_area 'company', 'suppressed_email_addresses', :rows => 5, :class => "input-xxlarge" %>
View
5 db/migrate/20130321130052_add_use_resources_to_company.rb
@@ -0,0 +1,5 @@
+class AddUseResourcesToCompany < ActiveRecord::Migration
+ def change
+ add_column :companies, :use_resources, :boolean, :default => true
+ end
+end
View
3  db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130320171946) do
+ActiveRecord::Schema.define(:version => 20130321130052) do
create_table "access_levels", :force => true do |t|
t.string "name"
@@ -32,6 +32,7 @@
t.string "logo_content_type"
t.integer "logo_file_size"
t.datetime "logo_updated_at"
+ t.boolean "use_resources", :default => true
end
add_index "companies", ["subdomain"], :name => "index_companies_on_subdomain", :unique => true
View
1  lang/hu_HU.rb
@@ -214,6 +214,7 @@
l.store "Tutorial", "Tutorial" # Jozsef
l.store "Use Chat", "Chat használata" # Jozsef
l.store "Use Wiki", "Wiki használata" # Jozsef
+ l.store "Use Resources", "Erőforrások használata" # Fleischmann Bonaventura
l.store "Username", "Felhasználó név" # Jozsef
l.store "Work Log", "Munkanapló" # Jozsef
l.store "Workload", "Terhelés" # Jozsef
View
6 spec/factories/companies.rb
@@ -0,0 +1,6 @@
+FactoryGirl.define do
+ factory :company do
+ sequence(:name) { |n| "Company#{n}" }
+ sequence(:subdomain) { |n| "Subdomain#{n}" }
+ end
+end
View
13 spec/factories/users.rb
@@ -0,0 +1,13 @@
+FactoryGirl.define do
+ factory :user do
+ association :company, :factory => :company
+ sequence(:name) { |n| "User #{n}" }
+ sequence(:username) { |n| "username#{n}" }
+ sequence(:email) { |n| "username#{n}@company.com" }
+ password "123456"
+
+ factory :admin do
+ admin 1
+ end
+ end
+end
View
0  spec/requests/triggers_spec.rb → spec/features/triggers_spec.rb
File renamed without changes
View
37 spec/features/use_resources_spec.rb
@@ -0,0 +1,37 @@
+require 'spec_helper'
+
+describe 'use resources' do
+ def login_as(username, password)
+ visit root_path
+ fill_in "Username", :with => username
+ fill_in "Password", :with => password
+ click_button "Login"
+ end
+
+ let(:company_use_resources) { true }
+ let(:user_use_resources) { true }
+ let(:company) { FactoryGirl.create(:company, :use_resources => company_use_resources) }
+ let(:admin) { FactoryGirl.create(:admin, :company => company, :use_resources => user_use_resources) }
+
+ it 'should display resources menu item if allowed' do
+ login_as(admin.username, admin.password)
+ page.should have_content(/resources/i)
+ end
+
+ context "when user not use resources" do
+ let(:user_use_resources) { false }
+ it 'should not display resources menu item if not allowed' do
+ login_as(admin.username, admin.password)
+ page.should_not have_content(/resources/i)
+ end
+ end
+
+ context "when company not use resources" do
+ let(:company_use_resources) { false }
+ it 'should not display resources menu item if not allowed' do
+ login_as(admin.username, admin.password)
+ page.should_not have_content(/resources/i)
+ end
+ end
+
+end
View
25 spec/models/user_spec.rb
@@ -80,6 +80,31 @@
t.reload.creator.should == @user.reload
end
end
+
+ describe "Use resources" do
+ subject{ FactoryGirl.create(:admin) }
+
+ it"should be true if company allow user allow" do
+ subject.use_resources = true
+ subject.use_resources?.should be_true
+ end
+
+ it "should be false if company allow user disallow" do
+ subject.use_resources?.should be_false
+ end
+
+ it "should be false if company disallow user allows" do
+ subject.company.use_resources = false
+ subject.use_resources?.should be_false
+ end
+
+ it "should be false if company disallow user disallow" do
+ subject.company.use_resources = false
+ subject.use_resources = false
+ subject.use_resources?.should be_false
+ end
+ end
+
end
Something went wrong with that request. Please try again.