mno-enterprise-core 3.3.3 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/app/controllers/mno_enterprise/application_controller.rb +1 -1
- data/app/models/mno_enterprise/impac/dashboard.rb +4 -7
- data/app/models/mno_enterprise/impac/kpi.rb +13 -0
- data/app/models/mno_enterprise/impac/widget.rb +15 -4
- data/app/models/mno_enterprise/sub_tenant.rb +8 -0
- data/app/models/mno_enterprise/user.rb +4 -1
- data/app/pdf/mno_enterprise/invoice_pdf.rb +2 -2
- data/config/locales/templates/dashboard/organization/en.yml +1 -0
- data/config/locales/templates/dashboard/organization/id.yml +1 -0
- data/config/locales/templates/dashboard/organization/zh.yml +1 -0
- data/lib/accountingjs_serializer.rb +1 -1
- data/lib/generators/mno_enterprise/install/templates/config/settings.yml +6 -2
- data/lib/mno_enterprise/concerns/models/ability.rb +56 -27
- data/lib/mno_enterprise/concerns/models/organization.rb +7 -3
- data/lib/mno_enterprise/testing_support/factories/sub_tenants.rb +14 -0
- data/lib/mno_enterprise/testing_support/factories/users.rb +4 -0
- data/lib/mno_enterprise/testing_support/mno_enterprise_api_test_helper.rb +1 -1
- data/lib/mno_enterprise/testing_support/organizations_shared_helpers.rb +2 -1
- data/lib/mno_enterprise/testing_support/shared_contexts/jpi_v1_admin_controller.rb +13 -0
- data/lib/mno_enterprise/testing_support/shared_contexts/jpi_v1_admin_impac_controller.rb +73 -0
- data/lib/mno_enterprise/version.rb +1 -1
- data/spec/models/mno_enterprise/ability_spec.rb +60 -2
- metadata +30 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cf176f50a3ce889c72e80a547eb8bcad4edb87467e74c858572c0bd6deece662
|
4
|
+
data.tar.gz: da051544d51089e2d354864e25434184788d0d1dd30c4774c87e79358ad26a12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1be7040ae608b7c404339a89a4098c526ac1e82e7eedbde0849f8857c27f2d928104068bdf649d26667a3bb22fe665d81be887a8ad9b3ef5639181cb7ff2762b
|
7
|
+
data.tar.gz: 1af8e04e29fb60df75c7fcc64803f062c67cb05931b0ae6bf0474920a38ad0ffe81f428b37109ef3181c2cfd92f1e2c7864ffc318c5a4385a9c64bb1b4adc8f7
|
@@ -22,13 +22,13 @@ module MnoEnterprise
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# Return all the organizations linked to this dashboard and to which the user has access
|
25
|
-
# If the dashboard is a template, return all the current user's
|
25
|
+
# If the dashboard is a template, return all the current user's organizations
|
26
26
|
def organizations(org_list = nil)
|
27
27
|
if org_list
|
28
28
|
return org_list if dashboard_type == 'template'
|
29
|
-
org_list.to_a.select { |e|
|
29
|
+
org_list.to_a.select { |e| organization_ids.include?(e.uid) || organization_ids.include?(e.id) }
|
30
30
|
else
|
31
|
-
MnoEnterprise::Organization.where('uid.in' =>
|
31
|
+
MnoEnterprise::Organization.where('uid.in' => organization_ids).to_a
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -44,10 +44,7 @@ module MnoEnterprise
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def to_audit_event
|
47
|
-
{
|
48
|
-
name: name,
|
49
|
-
organization_id: (owner_type == 'Organization') ? owner_id : nil
|
50
|
-
}
|
47
|
+
{ name: name }
|
51
48
|
end
|
52
49
|
|
53
50
|
def copy(owner, name, organization_ids)
|
@@ -7,5 +7,18 @@ module MnoEnterprise
|
|
7
7
|
belongs_to :widget, class_name: 'MnoEnterprise::Impac::Widget'
|
8
8
|
has_many :alerts, class_name: 'MnoEnterprise::Impac::Alert'
|
9
9
|
|
10
|
+
def organizations(orgs = nil)
|
11
|
+
if orgs.present?
|
12
|
+
orgs.select { |org| organization_ids.include?(org.uid) }.to_a
|
13
|
+
else
|
14
|
+
MnoEnterprise::Organization.where('uid.in' => organization_ids).to_a
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def organization_ids
|
21
|
+
@organization_ids ||= (settings.present? && settings['organization_ids']).to_a
|
22
|
+
end
|
10
23
|
end
|
11
24
|
end
|
@@ -2,21 +2,32 @@ module MnoEnterprise
|
|
2
2
|
class Impac::Widget < BaseResource
|
3
3
|
|
4
4
|
# TODO: remove :widget_category when mnohub migrated to new model
|
5
|
-
attributes :name, :width, :widget_category, :settings, :endpoint
|
5
|
+
attributes :name, :width, :widget_category, :settings, :endpoint, :layouts
|
6
6
|
|
7
7
|
belongs_to :dashboard, class_name: 'MnoEnterprise::Impac::Dashboard'
|
8
8
|
has_many :kpis, class_name: 'MnoEnterprise::Impac::Kpi'
|
9
9
|
|
10
10
|
def to_audit_event
|
11
|
-
|
12
|
-
|
13
|
-
organization = MnoEnterprise::Organization.find_by(uid: settings['organization_ids'].first)
|
11
|
+
if organization_ids.present?
|
12
|
+
organization = MnoEnterprise::Organization.find_by(uid: organization_ids.first)
|
14
13
|
{ name: name, organization_id: organization.id }
|
15
14
|
else
|
16
15
|
{ name: name }
|
17
16
|
end
|
17
|
+
end
|
18
18
|
|
19
|
+
def organizations(orgs = nil)
|
20
|
+
if orgs.present?
|
21
|
+
orgs.select { |org| organization_ids.include?(org.uid) }.to_a
|
22
|
+
else
|
23
|
+
MnoEnterprise::Organization.where('uid.in' => organization_ids).to_a
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
27
|
+
private
|
28
|
+
|
29
|
+
def organization_ids
|
30
|
+
@organization_ids ||= (settings.present? && settings['organization_ids']).to_a
|
31
|
+
end
|
21
32
|
end
|
22
33
|
end
|
@@ -37,6 +37,7 @@
|
|
37
37
|
# website :string(255)
|
38
38
|
# api_key :string(255)
|
39
39
|
# api_secret :string(255)
|
40
|
+
# mnoe_sub_tenant_id :string
|
40
41
|
#
|
41
42
|
|
42
43
|
module MnoEnterprise
|
@@ -51,7 +52,7 @@ module MnoEnterprise
|
|
51
52
|
:last_sign_in_ip, :confirmation_token, :confirmed_at, :confirmation_sent_at, :unconfirmed_email,
|
52
53
|
:failed_attempts, :unlock_token, :locked_at, :name, :surname, :company, :phone, :phone_country_code,
|
53
54
|
:geo_country_code, :geo_state_code, :geo_city, :website, :orga_on_create, :sso_session, :current_password_required, :admin_role,
|
54
|
-
:api_key, :api_secret, :developer, :kpi_enabled, :external_id, :meta_data, :password_valid
|
55
|
+
:api_key, :api_secret, :developer, :kpi_enabled, :external_id, :meta_data, :password_valid, :mnoe_sub_tenant_id, :client_ids
|
55
56
|
|
56
57
|
define_model_callbacks :validation #required by Devise
|
57
58
|
|
@@ -83,6 +84,8 @@ module MnoEnterprise
|
|
83
84
|
has_many :dashboards, class_name: 'MnoEnterprise::Impac::Dashboard'
|
84
85
|
has_many :alerts, class_name: 'MnoEnterprise::Impac::Alert'
|
85
86
|
|
87
|
+
has_many :clients, class_name: 'MnoEnterprise::Organization'
|
88
|
+
|
86
89
|
#================================
|
87
90
|
# Callbacks
|
88
91
|
#================================
|
@@ -39,7 +39,7 @@ module MnoEnterprise
|
|
39
39
|
|
40
40
|
# Financial values
|
41
41
|
@data[:invoice_price] = @invoice.price
|
42
|
-
@data[:invoice_currency] = @invoice.price.
|
42
|
+
@data[:invoice_currency] = @invoice.price.currency.to_s
|
43
43
|
@data[:invoice_currency_name] = @invoice.price.currency.name
|
44
44
|
@data[:invoice_credit_paid] = @invoice.credit_paid
|
45
45
|
@data[:invoice_total_payable] = @invoice.total_payable
|
@@ -119,7 +119,7 @@ module MnoEnterprise
|
|
119
119
|
|
120
120
|
# Format a money object
|
121
121
|
def money(m)
|
122
|
-
"#{m.format(symbol: false)} #{m.
|
122
|
+
"#{m.format(symbol: false)} #{m.currency.to_s}"
|
123
123
|
end
|
124
124
|
|
125
125
|
# Add a repeated header to the document
|
@@ -12,7 +12,7 @@ module AccountingjsSerializer
|
|
12
12
|
'subunit_symbol' => subunit_symbol(money.currency),
|
13
13
|
'subunit_format' => subunit_symbol_first(money.currency) ? "%s%v" : "%v%s",
|
14
14
|
'subunit_to_unit' => money.currency.subunit_to_unit,
|
15
|
-
'iso_code' => money.
|
15
|
+
'iso_code' => money.currency.to_s
|
16
16
|
}
|
17
17
|
}
|
18
18
|
end
|
@@ -60,6 +60,8 @@ devise:
|
|
60
60
|
|
61
61
|
# Admin Panel Config
|
62
62
|
admin_panel:
|
63
|
+
account_manager:
|
64
|
+
enabled: false
|
63
65
|
apps_management:
|
64
66
|
enabled: true
|
65
67
|
audit_log:
|
@@ -71,11 +73,13 @@ admin_panel:
|
|
71
73
|
enabled: true
|
72
74
|
finance:
|
73
75
|
enabled: true
|
76
|
+
impersonation:
|
77
|
+
disabled: false
|
74
78
|
# Ability to enable Intercom on the admin panel
|
75
79
|
# Intercom needs to be properly setup for the dashboard
|
76
80
|
intercom:
|
77
81
|
enabled: false
|
78
|
-
impersonation:
|
79
|
-
disabled: false
|
80
82
|
staff:
|
81
83
|
enabled: true
|
84
|
+
sub_tenant:
|
85
|
+
enabled: false
|
@@ -19,7 +19,7 @@ module MnoEnterprise::Concerns::Models::Ability
|
|
19
19
|
#==================================================================
|
20
20
|
# Instance methods
|
21
21
|
#==================================================================
|
22
|
-
def initialize(user)
|
22
|
+
def initialize(user, session)
|
23
23
|
user ||= MnoEnterprise::User.new
|
24
24
|
|
25
25
|
#===================================================
|
@@ -68,7 +68,8 @@ module MnoEnterprise::Concerns::Models::Ability
|
|
68
68
|
#===================================================
|
69
69
|
# Impac
|
70
70
|
#===================================================
|
71
|
-
|
71
|
+
orgs_with_acl = user.organizations.active.include_acl(session[:impersonator_user_id]).to_a
|
72
|
+
impac_abilities(orgs_with_acl)
|
72
73
|
|
73
74
|
#===================================================
|
74
75
|
# Admin abilities
|
@@ -103,42 +104,69 @@ module MnoEnterprise::Concerns::Models::Ability
|
|
103
104
|
# https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
|
104
105
|
end
|
105
106
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
# Enables / disables Impac! Angular capabilities
|
108
|
+
def impac_abilities(orgs_with_acl)
|
109
|
+
can :create_impac_dashboards, MnoEnterprise::Impac::Dashboard do |d|
|
110
|
+
orgs = d.organizations(orgs_with_acl)
|
111
|
+
orgs.present? && orgs.all? do |org|
|
112
|
+
org.acl[:related] && org.acl[:related][:dashboards] && org.acl[:related][:dashboards][:create]
|
110
113
|
end
|
111
114
|
end
|
112
115
|
|
113
|
-
can :
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
owner && !!user.role(owner)
|
118
|
-
elsif dashboard.owner_type == "User"
|
119
|
-
# The current user is the owner of the dashboard that has the kpi attached to
|
120
|
-
dashboard.owner_id == user.id
|
121
|
-
else
|
122
|
-
false
|
116
|
+
can :update_impac_dashboards, MnoEnterprise::Impac::Dashboard do |d|
|
117
|
+
orgs = d.organizations(orgs_with_acl)
|
118
|
+
orgs.present? && orgs.all? do |org|
|
119
|
+
org.acl[:related] && org.acl[:related][:dashboards] && org.acl[:related][:dashboards][:update]
|
123
120
|
end
|
124
121
|
end
|
125
122
|
|
126
|
-
can :
|
127
|
-
|
128
|
-
|
123
|
+
can :destroy_impac_dashboards, MnoEnterprise::Impac::Dashboard do |d|
|
124
|
+
orgs = d.organizations(orgs_with_acl)
|
125
|
+
orgs.present? && orgs.all? do |org|
|
126
|
+
org.acl[:related] && org.acl[:related][:dashboards] && org.acl[:related][:dashboards][:destroy]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
can :create_impac_widgets, MnoEnterprise::Impac::Widget do |w|
|
131
|
+
orgs = w.organizations(orgs_with_acl)
|
132
|
+
orgs.present? && orgs.all? do |org|
|
133
|
+
org.acl[:related] && org.acl[:related][:widgets] && org.acl[:related][:widgets][:create]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
can :update_impac_widgets, MnoEnterprise::Impac::Widget do |w|
|
138
|
+
orgs = w.organizations(orgs_with_acl)
|
139
|
+
orgs.present? && orgs.all? do |org|
|
140
|
+
org.acl[:related] && org.acl[:related][:widgets] && org.acl[:related][:widgets][:update]
|
141
|
+
end
|
129
142
|
end
|
130
143
|
|
131
|
-
can :
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
authorize! :manage_dashboard, kpi.dashboard
|
144
|
+
can :destroy_impac_widgets, MnoEnterprise::Impac::Widget do |w|
|
145
|
+
orgs = w.organizations(orgs_with_acl)
|
146
|
+
orgs.present? && orgs.all? do |org|
|
147
|
+
org.acl[:related] && org.acl[:related][:widgets] && org.acl[:related][:widgets][:destroy]
|
136
148
|
end
|
137
149
|
end
|
138
150
|
|
139
|
-
can :
|
140
|
-
|
141
|
-
|
151
|
+
can :create_impac_kpis, MnoEnterprise::Impac::Kpi do |k|
|
152
|
+
orgs = k.organizations(orgs_with_acl)
|
153
|
+
orgs.present? && orgs.all? do |org|
|
154
|
+
org.acl[:related] && org.acl[:related][:kpis] && org.acl[:related][:kpis][:create]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
can :update_impac_kpis, MnoEnterprise::Impac::Kpi do |k|
|
159
|
+
orgs = k.organizations(orgs_with_acl)
|
160
|
+
orgs.present? && orgs.all? do |org|
|
161
|
+
org.acl[:related] && org.acl[:related][:kpis] && org.acl[:related][:kpis][:update]
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
can :destroy_impac_kpis, MnoEnterprise::Impac::Kpi do |k|
|
166
|
+
orgs = k.organizations(orgs_with_acl)
|
167
|
+
orgs.present? && orgs.all? do |org|
|
168
|
+
org.acl[:related] && org.acl[:related][:kpis] && org.acl[:related][:kpis][:destroy]
|
169
|
+
end
|
142
170
|
end
|
143
171
|
end
|
144
172
|
|
@@ -146,6 +174,7 @@ module MnoEnterprise::Concerns::Models::Ability
|
|
146
174
|
def admin_abilities(user)
|
147
175
|
if user.admin_role.to_s.casecmp('admin').zero? || user.admin_role.to_s.casecmp('staff').zero?
|
148
176
|
can :manage_app_instances, MnoEnterprise::Organization
|
177
|
+
can :manage_sub_tenant, MnoEnterprise::SubTenant
|
149
178
|
end
|
150
179
|
end
|
151
180
|
end
|
@@ -37,12 +37,16 @@ module MnoEnterprise::Concerns::Models::Organization
|
|
37
37
|
included do
|
38
38
|
attributes :uid, :name, :account_frozen, :free_trial_end_at, :soa_enabled, :mails, :logo,
|
39
39
|
:latitude, :longitude, :geo_country_code, :geo_state_code, :geo_city, :geo_tz, :geo_currency,
|
40
|
-
:meta_data, :industry, :size, :financial_year_end_month
|
40
|
+
:meta_data, :industry, :size, :financial_year_end_month, :acl
|
41
41
|
|
42
42
|
scope :in_arrears, -> { where(in_arrears?: true) }
|
43
|
-
|
44
43
|
scope :active, -> { where(account_frozen: false) }
|
45
|
-
|
44
|
+
scope :include_acl, ->(imp_id) do
|
45
|
+
tap do |x|
|
46
|
+
x.params[:include_acl?] = true
|
47
|
+
x.params[:account_manager_id] = imp_id if Settings.admin_panel.account_manager.enabled?
|
48
|
+
end
|
49
|
+
end
|
46
50
|
default_scope lambda { where(account_frozen: false) }
|
47
51
|
|
48
52
|
#================================
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Read about factories at https://github.com/thoughtbot/factory_girl
|
2
|
+
|
3
|
+
# This is an API resource factory generating a Hash to be used in API stubs
|
4
|
+
# Use as such: build(:api_user)
|
5
|
+
# See http://stackoverflow.com/questions/10032760/how-to-define-an-array-hash-in-factory-girl
|
6
|
+
FactoryGirl.define do
|
7
|
+
|
8
|
+
factory :sub_tenant, class: MnoEnterprise::SubTenant do
|
9
|
+
sequence(:id)
|
10
|
+
name 'SubTenant'
|
11
|
+
# Properly build the resource with Her
|
12
|
+
initialize_with { new(attributes).tap { |e| e.clear_attribute_changes! } }
|
13
|
+
end
|
14
|
+
end
|
@@ -51,6 +51,10 @@ FactoryGirl.define do
|
|
51
51
|
kpi_enabled true
|
52
52
|
end
|
53
53
|
|
54
|
+
trait :with_clients do
|
55
|
+
clients { [build(:organization).attributes] }
|
56
|
+
end
|
57
|
+
|
54
58
|
# Properly build the resource with Her
|
55
59
|
initialize_with { new(attributes).tap { |e| e.clear_attribute_changes! } }
|
56
60
|
end
|
@@ -24,7 +24,7 @@ module MnoEnterpriseApiTestHelper
|
|
24
24
|
end
|
25
25
|
return hash
|
26
26
|
when res.kind_of?(Money)
|
27
|
-
return { cents: res.cents, currency: res.
|
27
|
+
return { cents: res.cents, currency: res.currency.to_s }
|
28
28
|
when res.respond_to?(:iso8601)
|
29
29
|
return res.iso8601
|
30
30
|
else
|
@@ -54,7 +54,8 @@ module MnoEnterprise::TestingSupport::OrganizationsSharedHelpers
|
|
54
54
|
'name' => organization.name,
|
55
55
|
'soa_enabled' => organization.soa_enabled,
|
56
56
|
'account_frozen' => organization.account_frozen,
|
57
|
-
'payment_restriction' => organization.payment_restriction
|
57
|
+
'payment_restriction' => organization.payment_restriction,
|
58
|
+
'financial_year_end_month' => organization.financial_year_end_month
|
58
59
|
}
|
59
60
|
|
60
61
|
if admin
|
@@ -0,0 +1,13 @@
|
|
1
|
+
RSpec.shared_context MnoEnterprise::Jpi::V1::Admin::BaseResourceController do
|
2
|
+
include MnoEnterprise::TestingSupport::SharedExamples::JpiV1Admin
|
3
|
+
|
4
|
+
render_views
|
5
|
+
routes { MnoEnterprise::Engine.routes }
|
6
|
+
before { request.env["HTTP_ACCEPT"] = 'application/json' }
|
7
|
+
|
8
|
+
# user is stubbed in the controller?
|
9
|
+
before do
|
10
|
+
api_stub_for(get: "/users/#{user.id}", response: from_api(user))
|
11
|
+
sign_in(user)
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module MnoEnterprise::TestingSupport::SharedContexts::JpiV1AdminImpacController
|
2
|
+
def hash_for_kpi(kpi)
|
3
|
+
{
|
4
|
+
"id" => kpi.id,
|
5
|
+
"element_watched" => kpi.element_watched,
|
6
|
+
"endpoint" => kpi.endpoint
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
shared_context 'MnoEnterprise::Jpi::V1::Admin::Impac' do
|
11
|
+
shared_context "#{described_class}: dashboard dependencies stubs" do
|
12
|
+
before do
|
13
|
+
# Not ideal but this is a nested context
|
14
|
+
if described_class == MnoEnterprise::Jpi::V1::Admin::Impac::DashboardsController
|
15
|
+
api_stub_for(
|
16
|
+
get: "/organizations?filter[uid.in][]=#{org.uid}",
|
17
|
+
response: from_api([org])
|
18
|
+
)
|
19
|
+
end
|
20
|
+
if described_class == MnoEnterprise::Jpi::V1::Admin::Impac::DashboardTemplatesController
|
21
|
+
api_stub_for(
|
22
|
+
get: "/users/#{user.id}/organizations",
|
23
|
+
response: from_api([org])
|
24
|
+
)
|
25
|
+
end
|
26
|
+
api_stub_for(
|
27
|
+
get: "/dashboards/#{dashboard.id}/widgets",
|
28
|
+
response: from_api([widget])
|
29
|
+
)
|
30
|
+
api_stub_for(
|
31
|
+
get: "/dashboards/#{dashboard.id}/kpis",
|
32
|
+
response: from_api([d_kpi])
|
33
|
+
)
|
34
|
+
api_stub_for(
|
35
|
+
get: "/widgets/#{widget.id}/kpis",
|
36
|
+
response: from_api([w_kpi])
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:user) { build(:user, :admin, :with_organizations) }
|
42
|
+
let(:org) { build(:organization, users: [user]) }
|
43
|
+
let(:metadata) { { hist_parameters: { from: '2015-01-01', to: '2015-03-31', period: 'MONTHLY' } } }
|
44
|
+
let(:dashboard) { build(:impac_dashboard, dashboard_type: 'dashboard', organization_ids: [org.uid], currency: 'EUR', settings: metadata) }
|
45
|
+
let(:widget) { build(:impac_widget, dashboard: dashboard, owner: user) }
|
46
|
+
let(:d_kpi) { build(:impac_kpi, dashboard: dashboard) }
|
47
|
+
let(:w_kpi) { build(:impac_kpi, widget: widget) }
|
48
|
+
|
49
|
+
let(:hash_for_widget) do
|
50
|
+
{
|
51
|
+
"id" => widget.id,
|
52
|
+
"name" => widget.name,
|
53
|
+
"endpoint" => widget.widget_category,
|
54
|
+
"width" => widget.width,
|
55
|
+
"kpis" => [hash_for_kpi(w_kpi)]
|
56
|
+
}
|
57
|
+
end
|
58
|
+
let(:hash_for_dashboard) do
|
59
|
+
{
|
60
|
+
"id" => dashboard.id,
|
61
|
+
"name" => dashboard.name,
|
62
|
+
"full_name" => dashboard.full_name,
|
63
|
+
"currency" => 'EUR',
|
64
|
+
"metadata" => metadata.deep_stringify_keys,
|
65
|
+
"data_sources" => [{ "id" => org.id, "uid" => org.uid, "label" => org.name}],
|
66
|
+
"kpis" => [hash_for_kpi(d_kpi)],
|
67
|
+
"widgets" => [hash_for_widget]
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
@@ -3,12 +3,35 @@ require 'cancan/matchers'
|
|
3
3
|
|
4
4
|
# TODO: add more ability tests
|
5
5
|
RSpec.describe MnoEnterprise::Ability, type: :model do
|
6
|
-
subject(:ability) { described_class.new(user) }
|
6
|
+
subject(:ability) { described_class.new(user, session) }
|
7
7
|
let(:user) { FactoryGirl.build(:user, admin_role: admin_role) }
|
8
|
+
let(:user2) { FactoryGirl.build(:user) }
|
9
|
+
let(:session) { { impersonator_user_id: user2.id } }
|
8
10
|
let(:admin_role) { nil }
|
9
11
|
let(:organization) { FactoryGirl.build(:organization) }
|
12
|
+
|
13
|
+
let(:org1) { FactoryGirl.build(:organization, acl: acl) }
|
14
|
+
let(:org2) { FactoryGirl.build(:organization, acl: acl) }
|
15
|
+
let(:acl) do
|
16
|
+
{
|
17
|
+
self: { show: false, update: false, destroy: false },
|
18
|
+
related: {
|
19
|
+
impac: { show: false },
|
20
|
+
dashboards: { show: false, create: false, update: false, destroy: false },
|
21
|
+
widgets: { show: false, create: false, update: false, destroy: false },
|
22
|
+
kpis: { show: false, create: false, update: false, destroy: false },
|
23
|
+
}
|
24
|
+
}
|
25
|
+
end
|
26
|
+
let(:orgs_with_acl) { [org1, org2] }
|
27
|
+
let(:orgs_ids) { orgs_with_acl.map(&:uid) }
|
10
28
|
|
11
|
-
before
|
29
|
+
before do
|
30
|
+
allow(user).to receive(:role).with(organization) { nil }
|
31
|
+
allow(user).to receive(:organizations).and_return(
|
32
|
+
double(:active, active: double(:include_acl, include_acl: orgs_with_acl))
|
33
|
+
)
|
34
|
+
end
|
12
35
|
|
13
36
|
context 'when User#admin_role is admin' do
|
14
37
|
let(:admin_role) { 'admin' }
|
@@ -23,4 +46,39 @@ RSpec.describe MnoEnterprise::Ability, type: :model do
|
|
23
46
|
context 'when no User#admin_role' do
|
24
47
|
it { is_expected.not_to be_able_to(:manage_app_instances, organization) }
|
25
48
|
end
|
49
|
+
|
50
|
+
describe 'Impac! abilities' do
|
51
|
+
%i(dashboards widgets kpis).each do |component|
|
52
|
+
%i(create update destroy).each do |action|
|
53
|
+
context "when at least one organization cannot #{action} #{component}" do
|
54
|
+
before { org1.acl[:related][component][action] = true }
|
55
|
+
|
56
|
+
it do
|
57
|
+
impac_component = FactoryGirl.build(
|
58
|
+
"impac_#{component}".singularize.to_sym,
|
59
|
+
settings: { organization_ids: orgs_ids },
|
60
|
+
organization_ids: orgs_ids
|
61
|
+
)
|
62
|
+
is_expected.not_to be_able_to("#{action}_impac_#{component}".to_sym, impac_component)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when all the organizations can #{action} #{component}" do
|
67
|
+
before do
|
68
|
+
org1.acl[:related][component][action] = true
|
69
|
+
org2.acl[:related][component][action] = true
|
70
|
+
end
|
71
|
+
|
72
|
+
it do
|
73
|
+
impac_component = FactoryGirl.build(
|
74
|
+
"impac_#{component}".singularize.to_sym,
|
75
|
+
settings: { organization_ids: orgs_ids },
|
76
|
+
organization_ids: orgs_ids
|
77
|
+
)
|
78
|
+
is_expected.to be_able_to("#{action}_impac_#{component}".to_sym, impac_component)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
26
84
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mno-enterprise-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Lachaume
|
@@ -9,28 +9,28 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-04-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "~>"
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '4.2'
|
21
18
|
- - ">="
|
22
19
|
- !ruby/object:Gem::Version
|
23
20
|
version: 4.2.0
|
21
|
+
- - "~>"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '4.2'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
27
|
requirements:
|
28
|
-
- - "~>"
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '4.2'
|
31
28
|
- - ">="
|
32
29
|
- !ruby/object:Gem::Version
|
33
30
|
version: 4.2.0
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: her
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
@@ -354,6 +354,7 @@ files:
|
|
354
354
|
- app/models/mno_enterprise/org_invite.rb
|
355
355
|
- app/models/mno_enterprise/organization.rb
|
356
356
|
- app/models/mno_enterprise/shared_entity.rb
|
357
|
+
- app/models/mno_enterprise/sub_tenant.rb
|
357
358
|
- app/models/mno_enterprise/team.rb
|
358
359
|
- app/models/mno_enterprise/tenant.rb
|
359
360
|
- app/models/mno_enterprise/tenant_invoice.rb
|
@@ -595,6 +596,7 @@ files:
|
|
595
596
|
- lib/mno_enterprise/testing_support/factories/invoices.rb
|
596
597
|
- lib/mno_enterprise/testing_support/factories/org_invite.rb
|
597
598
|
- lib/mno_enterprise/testing_support/factories/organizations.rb
|
599
|
+
- lib/mno_enterprise/testing_support/factories/sub_tenants.rb
|
598
600
|
- lib/mno_enterprise/testing_support/factories/team.rb
|
599
601
|
- lib/mno_enterprise/testing_support/factories/tenant.rb
|
600
602
|
- lib/mno_enterprise/testing_support/factories/tenant_invoice.rb
|
@@ -604,6 +606,8 @@ files:
|
|
604
606
|
- lib/mno_enterprise/testing_support/mnoe_faraday_test_adapter.rb
|
605
607
|
- lib/mno_enterprise/testing_support/organizations_shared_helpers.rb
|
606
608
|
- lib/mno_enterprise/testing_support/request_spec_helper.rb
|
609
|
+
- lib/mno_enterprise/testing_support/shared_contexts/jpi_v1_admin_controller.rb
|
610
|
+
- lib/mno_enterprise/testing_support/shared_contexts/jpi_v1_admin_impac_controller.rb
|
607
611
|
- lib/mno_enterprise/testing_support/shared_contexts/rake_task.rb
|
608
612
|
- lib/mno_enterprise/testing_support/shared_examples/jpi_v1_admin.rb
|
609
613
|
- lib/mno_enterprise/testing_support/user_action_shared.rb
|
@@ -661,40 +665,40 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
661
665
|
version: '0'
|
662
666
|
requirements: []
|
663
667
|
rubyforge_project:
|
664
|
-
rubygems_version: 2.
|
668
|
+
rubygems_version: 2.7.8
|
665
669
|
signing_key:
|
666
670
|
specification_version: 4
|
667
671
|
summary: Maestrano Enterprise - Core functionnality
|
668
672
|
test_files:
|
669
|
-
- spec/
|
670
|
-
- spec/
|
671
|
-
- spec/models/mno_enterprise/app_instance_spec.rb
|
672
|
-
- spec/models/mno_enterprise/impac/dashboard_spec.rb
|
673
|
-
- spec/models/mno_enterprise/credit_card_spec.rb
|
673
|
+
- spec/spec_helper.rb
|
674
|
+
- spec/config/initializers/audit_log_spec.rb
|
674
675
|
- spec/models/mno_enterprise/deletion_request_spec.rb
|
675
|
-
- spec/models/mno_enterprise/
|
676
|
+
- spec/models/mno_enterprise/credit_card_spec.rb
|
676
677
|
- spec/models/mno_enterprise/ability_spec.rb
|
677
|
-
- spec/models/mno_enterprise/
|
678
|
+
- spec/models/mno_enterprise/app_instance_spec.rb
|
679
|
+
- spec/models/mno_enterprise/organization_spec.rb
|
678
680
|
- spec/models/mno_enterprise/shared_entity_spec.rb
|
679
|
-
- spec/models/mno_enterprise/
|
681
|
+
- spec/models/mno_enterprise/identity_spec.rb
|
682
|
+
- spec/models/mno_enterprise/impac/dashboard_spec.rb
|
680
683
|
- spec/models/mno_enterprise/base_resource_spec.rb
|
681
|
-
- spec/
|
682
|
-
- spec/
|
684
|
+
- spec/models/mno_enterprise/invoice_spec.rb
|
685
|
+
- spec/models/mno_enterprise/app_spec.rb
|
686
|
+
- spec/models/mno_enterprise/user_spec.rb
|
683
687
|
- spec/lib/mno_enterprise/mail_adapters/smtp_adapter_spec.rb
|
684
|
-
- spec/lib/mno_enterprise/mail_adapters/mandrill_adapter_spec.rb
|
685
|
-
- spec/lib/mno_enterprise/mail_adapters/sparkpost_adapter_spec.rb
|
686
688
|
- spec/lib/mno_enterprise/mail_adapters/adapter_spec.rb
|
687
|
-
- spec/lib/mno_enterprise/
|
689
|
+
- spec/lib/mno_enterprise/mail_adapters/sparkpost_adapter_spec.rb
|
690
|
+
- spec/lib/mno_enterprise/mail_adapters/mandrill_adapter_spec.rb
|
688
691
|
- spec/lib/mno_enterprise/core_engine_spec.rb
|
692
|
+
- spec/lib/mno_enterprise/mail_client_spec.rb
|
693
|
+
- spec/lib/mno_enterprise/smtp_client_spec.rb
|
689
694
|
- spec/lib/mno_enterprise/impac_client_spec.rb
|
690
695
|
- spec/lib/devise/model/remote_authenticable_spec.rb
|
696
|
+
- spec/lib/mandrill_client_spec.rb
|
691
697
|
- spec/lib/her_extension/her_orm_adapter.rb
|
692
698
|
- spec/lib/her_extension/model/relation_spec.rb
|
693
|
-
- spec/
|
694
|
-
- spec/rails_helper.rb
|
699
|
+
- spec/mno_enterprise_spec.rb
|
695
700
|
- spec/controllers/mno_enterprise/i18n_spec.rb
|
696
701
|
- spec/controllers/mno_enterprise/angular_csrf_spec.rb
|
697
702
|
- spec/controllers/mno_enterprise/application_controller_spec.rb
|
698
|
-
- spec/
|
699
|
-
- spec/mno_enterprise_spec.rb
|
703
|
+
- spec/rails_helper.rb
|
700
704
|
- spec/helpers/image_helper_spec.rb
|