aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-05-07 15:25:50 +0200
committerZog2018-05-07 15:25:50 +0200
commitfb4d1c66cb4c0cd83e183a13ca5f9ea44803631b (patch)
tree635d6315e5dbc734ad2ebd68b525358ba91e9a65
parentfac03f56f2e84705cd30fc31d8007cc64f77d500 (diff)
downloadchouette-core-fb4d1c66cb4c0cd83e183a13ca5f9ea44803631b.tar.bz2
Refs #6960; Add owners to workgroups
And define policies
-rw-r--r--app/models/workgroup.rb1
-rw-r--r--app/policies/workgroup_policy.rb19
-rw-r--r--db/migrate/20180507130455_add_owner_to_workgroups.rb7
-rw-r--r--spec/policies/workgroup_policy_spec.rb44
4 files changed, 71 insertions, 0 deletions
diff --git a/app/models/workgroup.rb b/app/models/workgroup.rb
index 247873869..a264247c7 100644
--- a/app/models/workgroup.rb
+++ b/app/models/workgroup.rb
@@ -1,6 +1,7 @@
class Workgroup < ApplicationModel
belongs_to :line_referential
belongs_to :stop_area_referential
+ belongs_to :owner, class_name: "Organisation"
has_many :workbenches
has_many :calendars
diff --git a/app/policies/workgroup_policy.rb b/app/policies/workgroup_policy.rb
new file mode 100644
index 000000000..01914bb51
--- /dev/null
+++ b/app/policies/workgroup_policy.rb
@@ -0,0 +1,19 @@
+class WorkgroupPolicy < ApplicationPolicy
+ class Scope < Scope
+ def resolve
+ scope
+ end
+ end
+
+ def create?
+ false
+ end
+
+ def desrtroy?
+ false
+ end
+
+ def update?
+ record.owner == user.organisation
+ end
+end
diff --git a/db/migrate/20180507130455_add_owner_to_workgroups.rb b/db/migrate/20180507130455_add_owner_to_workgroups.rb
new file mode 100644
index 000000000..2ed601492
--- /dev/null
+++ b/db/migrate/20180507130455_add_owner_to_workgroups.rb
@@ -0,0 +1,7 @@
+class AddOwnerToWorkgroups < ActiveRecord::Migration
+ def change
+ add_column :workgroups, :owner_id, :bigint
+ add_column :workbenches, :owner_compliance_control_set_ids, :hstore
+ remove_column :workgroups, :import_compliance_control_set_ids
+ end
+end
diff --git a/spec/policies/workgroup_policy_spec.rb b/spec/policies/workgroup_policy_spec.rb
new file mode 100644
index 000000000..19f6c29d1
--- /dev/null
+++ b/spec/policies/workgroup_policy_spec.rb
@@ -0,0 +1,44 @@
+RSpec.describe WorkgroupPolicy, type: :policy do
+
+ let( :record ){ build_stubbed :workgroup }
+
+ permissions :create? do
+ it "should not allow for creation" do
+ expect_it.not_to permit(user_context, record)
+ end
+ end
+
+ permissions :update? do
+ it "should not allow for update" do
+ expect_it.not_to permit(user_context, record)
+ end
+
+ context "for the owner" do
+ before do
+ record.owner = user.organisation
+ end
+
+ it "should allow for update" do
+ expect_it.to permit(user_context, record)
+ end
+ end
+ end
+
+ permissions :destroy? do
+ it "should not allow for destroy" do
+ expect_it.not_to permit(user_context, record)
+ end
+
+ context "for the owner" do
+ before do
+ record.owner = user.organisation
+ end
+
+ it "should not allow for destroy" do
+ expect_it.not_to permit(user_context, record)
+ end
+ end
+ end
+
+
+end