permissify 0.0.20 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,22 +8,49 @@ module SystemFixtures::Abilities
8
8
  # can organize permissions into categories that correspond to your client's/product team's view of app.
9
9
  # suggest playing with your Ability class and the builder methods in console.
10
10
 
11
- # NOTE : 'Role' and 'Product' references in following example are actually *class names*.
12
- # This is a name coupling (see Permissify::Union) that can be overriden.
13
-
14
- # applies_to_users_only = [User::PERMISSIFIED_ABILITY_APPLICABILITY]
15
- # add_category('Tabs', 'Tabs', applies_to_users_only, %w(Admin Dealers Corporations Brands Merchants))
11
+ # Can define PERMISSIFIED_ABILITY_APPLICABILITY in any model
12
+ # users_only = [Role::PERMISSIFIED_ABILITY_APPLICABILITY]
13
+ # products_only => [Product::PERMISSIFIED_ABILITY_APPLICABILITY]
14
+ # products_and_roles => users_only + products_only
15
+ #
16
+ # add_category('Tabs', 'Tabs', users_only, %w(Admin Dealers Corporations Brands Merchants))
16
17
  # { 'Roles' => 'Admin',
18
+ # 'Products' => 'Admin',
17
19
  # 'Admin Users' => 'Admin',
18
20
  # 'Dealers' => 'Dealer Admin',
19
21
  # 'Dealer Users' => 'Dealer Admin',
20
- # 'Corporation Users' => 'Corporation Admin',
21
22
  # 'Corporations' => 'Corporation Admin',
22
- # 'Brand Users' => 'Brand Admin',
23
+ # 'Corporation Users' => 'Corporation Admin',
23
24
  # 'Brands' => 'Brand Admin',
24
- # 'Merchant Users' => 'Merchant Admin',
25
+ # 'Brand Users' => 'Brand Admin',
25
26
  # 'Merchants' => 'Merchant Admin',
26
- # }.each{ |category, section| add_category(category, section, applies_to_users_only) }
27
+ # 'Merchant Users' => 'Merchant Admin',
28
+ # }.each{ |category, section| add_category(category, section, users_only) }
29
+ #
30
+ # { 'Corporation Products' => 'Corporation Admin',
31
+ # 'Brand Products' => 'Brand Admin',
32
+ # 'Merchant Products' => 'Merchant Admin',
33
+ # }.each{ |category, section| add_category(category, section, users_only, %w(View Update)) }
34
+
35
+ # add_category('Social Media', 'Social Media', products_and_roles, %w(Setup View Create Schedule Repeat))
36
+ # add_category('Facebook', 'Social Media', products_and_roles, %w(Post Comment Like Remove))
37
+ # add_category('Twitter', 'Social Media', products_and_roles, %w(Tweet Retweet Respond Remove))
38
+ #
39
+ #
40
+ # [ 'Online Ordering',
41
+ # 'Loyalty',
42
+ # 'Webpage Builder',
43
+ # 'eGift',
44
+ # 'Guest Management',
45
+ # 'Social Media 1',
46
+ # 'Social Media 2',
47
+ # 'Social Media 3',
48
+ # 'Marketing Engine',
49
+ # 'Social Marketing Engine',
50
+ # ].each do |feature_bit|
51
+ # add_category(feature_bit, 'Solutions', products_only, %w(On))
52
+ # end
53
+
27
54
  end
28
55
 
29
56
  end
@@ -4,7 +4,7 @@ module PermissifiedController # Interfaces : override/rewrite as needed for your
4
4
  PERMISSIFY = SPECIFY_PERMISSIFIED_MODEL_LIST_IN__APP__CONTROLLERS__PERMISSIFIED_CONTROLLER
5
5
 
6
6
  # PERMISSIFY = { User::PERMISSIFIED_ABILITY_APPLICABILITY => :current_user,
7
- # 'Product' => :current_entity, # Merchant::PERMISSIFIED_ABILITY_APPLICABILITY
7
+ # Product::PERMISSIFIED_ABILITY_APPLICABILITY => :current_entity,
8
8
  # }
9
9
 
10
10
  end
@@ -17,8 +17,9 @@ module Permissify
17
17
  end
18
18
 
19
19
  def copy_migrations
20
- migration_template "create_roles_tables.rb", "db/migrate/create_roles_tables.rb"
21
- # migration_template "create_something_else.rb", "db/migrate/create_something_else.rb"
20
+ %w(create_roles_tables.rb create_products_tables.rb).each do |migration_file|
21
+ migration_template migration_file, "db/migrate/#{migration_file}"
22
+ end
22
23
  end
23
24
 
24
25
  def generate_install
@@ -0,0 +1,21 @@
1
+ class CreateProductsTables < ActiveRecord::Migration
2
+ def up
3
+
4
+ create_table :products, :force => true do |t|
5
+ t.string :name
6
+ t.text :permissions
7
+ t.datetime :deleted_at
8
+ end
9
+
10
+ create_table :merchants_products, :id => false, :force => true do |t|
11
+ t.integer :merchant_id, :null => false
12
+ t.integer :product_id, :null => false
13
+ end
14
+
15
+ end
16
+
17
+ def down
18
+ drop_table :products
19
+ drop_table :businesses_products
20
+ end
21
+ end
@@ -4,13 +4,15 @@ module Permissify
4
4
  source_root File.expand_path('../template', __FILE__)
5
5
 
6
6
  def generate_product
7
- copy_file "product.rb", "app/models/product.rb"
8
- copy_file "/interface/permissified_merchant.rb", "app/models/permissified_merchant.rb"
9
- copy_file "/interface/permissified_brand.rb", "app/models/permissified_brand.rb"
10
- # directory instead?
11
- # d app/models/permissfy_interfaces
12
- # f app/models/permissfy_interfaces/merchant.rb
13
- # f app/models/permissfy_interfaces/brand.rb
7
+
8
+ copy_file "product.rb", "app/models/product.rb"
9
+ copy_file "products.rb", "app/models/system_fixtures/products.rb"
10
+ copy_file "controller.rb","app/helpers/products_controller.rb"
11
+ copy_file "helper.rb", "app/helpers/products_helper.rb"
12
+
13
+ directory "interface", "app/models/permissified_products_interface"
14
+ directory "views", "app/views/products"
15
+
14
16
  end
15
17
  end
16
18
  end
@@ -0,0 +1,5 @@
1
+ class ProductsController < PermissionsController
2
+ def set_permissions_class; set_the_permissions_class(Products, :product, 'product_', 'Product', 'Products'); end
3
+ def set_permissions_object; @product = @permissions_object; end
4
+ end
5
+
@@ -0,0 +1,3 @@
1
+ module ProductsHelper
2
+ include PermissionsHelper
3
+ end
@@ -1,4 +1,4 @@
1
- module Permissified
1
+ module PermissifiedProductsInterface
2
2
  module Brand
3
3
  def permissible_products
4
4
  self.corporation.products + self.products
@@ -0,0 +1,7 @@
1
+ module PermissifiedProductsInterface
2
+ module Corporation
3
+ def permissible_products
4
+ self.products
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module PermissifiedProductsInterface
2
+ module Dealer
3
+ def permissible_products
4
+ self.products
5
+ end
6
+ end
7
+ end
@@ -1,4 +1,4 @@
1
- module Permissified
1
+ module PermissifiedProductsInterface
2
2
  module Merchant
3
3
  def permissible_products
4
4
  self.corporation.products + self.brand.products + self.products
@@ -1,30 +1,17 @@
1
1
  class Product < ActiveRecord::Base
2
+
3
+ include Permissify::Model
4
+
5
+ # TODO : see how much of the following stuff can be rolled into ModelClass :
2
6
  validates_presence_of :name
3
7
  validates_uniqueness_of :name
4
- before_create :initialize_permissions
5
- serialize :permissions
6
- include Permissify::Model
7
- # is_paranoid
8
- default_scope :conditions => {:deleted_at => nil}, :order => "products.name"
8
+ before_create :initialize_permissions
9
+ serialize :permissions
9
10
 
10
11
  class << self
11
12
  include Permissify::ModelClass
12
- include SystemFixtures::Products
13
-
14
- # TODO : this stuff should be plugged in by app
15
- def revenuepwr; locate(1, 'revenuePWR'); end
16
- def integrated_reservations; locate(3, 'Integrated Reservations'); end
17
- def pos_integration; locate(3, 'POS Integration'); end
18
- def standalone_reservations; locate(4, 'Standalone Reservations'); end
19
- def online_ordering; locate(5, 'Online Ordering'); end
20
- def loyalty; locate(6, 'Loyalty'); end
21
- def webpage_builder; locate(7, 'Webpage Builder'); end
22
- def egift; locate(8, 'eGift'); end
23
- def guest_management; locate(12, 'Guest Management'); end
24
- def mobile_marketing; locate(13, 'Mobile Marketing'); end
25
- def offers_and_incentives; locate(14, 'Offers & Incentives'); end
26
- def revenuepwr_lite; locate(15, 'revenuePWR Lite'); end
27
- def waitlist; locate(16, 'Waitlist'); end
28
- def consumer_driven_deals; locate(17, 'Consumer-Driven Deals'); end
13
+ include SystemFixtures::Products # app needs to provide this logic/specification : see example at app/models/system_fixtures/products.rb
14
+ PERMISSIFIED_ABILITY_APPLICABILITY = 'Product'
29
15
  end
30
- end
16
+
17
+ end
@@ -0,0 +1,73 @@
1
+ module SystemFixtures::Products
2
+ SEED_SPECIFICATIONS = [
3
+ [1, 'Basic Service'],
4
+ [2, 'Online Ordering'],
5
+ [3, 'Loyalty'],
6
+ [4, 'Webpage Builder'],
7
+ [5, 'eGift'],
8
+ [6, 'Guest Management'],
9
+ [7, 'Marketing Engine']
10
+ [8, 'Social Media 1']
11
+ [9, 'Social Media 2']
12
+ [10, 'Social Media 3']
13
+ [11, 'Social Marketing Engine']
14
+ ]
15
+
16
+ def seeded?(tier); tier.id < 8; end
17
+ def seed; create_seeds :products, SEED_SPECIFICATIONS; end
18
+
19
+ def create_basic_service; create_with 1; end
20
+ def create_online_ordering; create_with 2; end
21
+ def create_loyalty; create_with 3; end
22
+ def create_webpage_builder; create_with 4; end
23
+ def create_egift; create_with 5; end
24
+ def create_guest_management; create_with 6; end
25
+ def create_marketing_engine; create_with 7; end
26
+ def create_social_media_1; create_with 8; end
27
+ def create_social_media_2; create_with 9; end
28
+ def create_social_media_3; create_with 10; end
29
+ def create_social_marketing_engine; create_with 10; end
30
+ def create_with(id); create_with_id(:product, id, SEED_SPECIFICATIONS.assoc(id)[1]); end
31
+
32
+ def basic_service_permissions
33
+ permissions = Ability.create_permissions_hash([], [], %w(Product Role))
34
+ permissions
35
+ end
36
+ def online_ordering_permissions; ph :online_ordering_on; end
37
+ def loyalty_permissions; ph :loyalty_on; end
38
+ def webpage_builder_permissions
39
+ permissions_hash = Ability.create_permissions_hash([], %w(email sms social_media), %w(Product Role)).merge(ph(:webpage_builder_on))
40
+ end
41
+ def egift_permissions; ph :egift_on; end
42
+ def guest_management_permissions; ph :guest_management_on; end
43
+ def marketing_engine_permissions; ph :marketing_engine_on; end
44
+
45
+ def social_media_1_permissions
46
+ permissions = Ability.create_permissions_hash([], %w(social_media facebook twitter), %w(Product Role))
47
+ permissions[:social_media_setup] = {'0' => '1'}
48
+ permissions[:social_media_view] = {'0' => '1'}
49
+ permissions
50
+ end
51
+ def social_media_2_permissions
52
+ permissions = social_media_1_permissions
53
+ permissions[:social_media_create] = {'0' => '1'}
54
+ permissions[:facebook_post] = {'0' => '1'}
55
+ permissions[:twitter_tweet] = {'0' => '1'}
56
+ permissions
57
+ end
58
+ def social_media_3_permissions
59
+ Ability.create_permissions_hash([], %w(social_media_repeat), %w(Product Role))
60
+ end
61
+ def social_marketing_engine_permissions
62
+ permissions = social_media_3_permissions
63
+ permissions[:marketing_engine_on] = {'0' => '1'}
64
+ permissions
65
+ end
66
+
67
+ def ph(permissions)
68
+ permissions_hash = {}
69
+ permissions = [permissions] unless permissions.kind_of?(Array)
70
+ permissions.each{|p| permissions_hash[p.to_s] = {"0"=>"1"}}
71
+ permissions_hash
72
+ end
73
+ end
@@ -0,0 +1,24 @@
1
+ <tr>
2
+ <td ><%= label :product, :name, "Name"%></td>
3
+ <td><%= text_field :product, :name, :maxlength => 255, :size => 46 %></td>
4
+ <td style="vertical-align:bottom;"><%= required_field %></td>
5
+ </tr>
6
+
7
+ <tr>
8
+ <td style="vertical-align:text-top;"><%= label :product, :description, "Description" %></td>
9
+ <td colspan="2"><%= text_area :product, :description, :rows => 2, :columns => 60 %></td>
10
+ </tr>
11
+
12
+ <tr>
13
+ <td style="vertical-align:text-top;"><%= "revenuePWR Instances" %></td>
14
+ <td>
15
+ <div class="checkCont">
16
+ <% Instance.find(:all, :conditions => ["id in (?)", @current_user.instances.collect(&:id)]).each do |i| %>
17
+ <label>
18
+ <%= check_box_tag "#{@permissions_object.class.to_s.underscore}[instance_ids][]", i.id, @permissions_object.instances.include?(i) %>
19
+ <%= i.name %>
20
+ </label><br/>
21
+ <% end %>
22
+ </div>
23
+ </td>
24
+ </tr>
@@ -16,7 +16,8 @@ class Role < ActiveRecord::Base
16
16
  class << self
17
17
  include Permissify::ModelClass
18
18
  include SystemFixtures::Roles
19
-
19
+ PERMISSIFIED_ABILITY_APPLICABILITY = 'Role'
20
+
20
21
  def force_seed_id(table, permissions_model, id)
21
22
  # not sure if this is still needed, may differ depending on db adapter (written against mysql)
22
23
  ActiveRecord::Base.connection.execute "UPDATE #{table}s SET id=#{id} WHERE id=#{permissions_model.id};"
@@ -32,10 +32,10 @@ module SystemFixtures::Roles
32
32
  Ability.create_permissions_hash
33
33
  end
34
34
  def system_admin_permissions
35
- Ability.create_permissions_hash 'roles'
35
+ Ability.create_permissions_hash %w(roles products)
36
36
  end
37
37
  def dealer_admin_permissions
38
- Ability.create_permissions_hash( [], %w(roles admin))
38
+ Ability.create_permissions_hash( [], %w(roles products admin))
39
39
  Ability.remove_permissions %w(tabs_admin dealers_create dealers_delete dealer_users_create dealer_users_delete)
40
40
  end
41
41
 
@@ -44,14 +44,14 @@ module SystemFixtures::Roles
44
44
  end
45
45
  def brand_admin_permissions
46
46
  msa_permissions %w(corporation brands_create brands_delete)
47
- Ability.remove_permissions %w(tabs_corporations)
47
+ Ability.remove_permissions %w(tabs_corporations brand_products_update merchant_products_update)
48
48
  end
49
49
  def merchant_admin_permissions
50
50
  msa_permissions %w(corporation brand)
51
- Ability.remove_permissions %w(tabs_brands tabs_corporations)
51
+ Ability.remove_permissions %w(tabs_brands tabs_corporations merchant_products_update)
52
52
  end
53
53
  def msa_permissions(exclude_abilities)
54
- no_abilities = exclude_abilities + %w(admin roles dealer)
54
+ no_abilities = exclude_abilities + %w(admin roles products dealer)
55
55
  Ability.create_permissions_hash([], no_abilities)
56
56
  Ability.remove_permissions %w(tabs_admin tabs_dealers)
57
57
  end
@@ -1,7 +1,7 @@
1
1
  <%- set_tag @permissions_object %>
2
2
  <h1 class="pageName">Edit <%= @permissions_header %></h1>
3
3
  <%= form_tag form_path, :method => :put, :remote => true do |f| %>
4
- <!-- %= error_messages_for :product_tier % -->
4
+ <!-- %= error_messages_for :product % -->
5
5
  <table style="border-spacing:8px;">
6
6
  <tbody>
7
7
  <%= render :partial => 'permissions_fields' %>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: permissify
3
3
  version: !ruby/object:Gem::Version
4
- hash: 55
4
+ hash: 53
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 20
10
- version: 0.0.20
9
+ - 21
10
+ version: 0.0.21
11
11
  platform: ruby
12
12
  authors:
13
13
  - Frederick Fix
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-06-18 00:00:00 Z
18
+ date: 2012-06-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -66,12 +66,20 @@ files:
66
66
  - lib/generators/permissify/controller/template/permissions_controller.rb
67
67
  - lib/generators/permissify/controller/USAGE
68
68
  - lib/generators/permissify/install/install_generator.rb
69
+ - lib/generators/permissify/install/templates/create_products_tables.rb
69
70
  - lib/generators/permissify/install/templates/create_roles_tables.rb
70
71
  - lib/generators/permissify/install/USAGE
71
72
  - lib/generators/permissify/product/product_generator.rb
72
- - lib/generators/permissify/product/template/interface/permissified_brand.rb
73
- - lib/generators/permissify/product/template/interface/permissified_merchant.rb
73
+ - lib/generators/permissify/product/template/controller.rb
74
+ - lib/generators/permissify/product/template/helper.rb
75
+ - lib/generators/permissify/product/template/interface/brand.rb
76
+ - lib/generators/permissify/product/template/interface/corporation.rb
77
+ - lib/generators/permissify/product/template/interface/dealer.rb
78
+ - lib/generators/permissify/product/template/interface/merchant.rb
74
79
  - lib/generators/permissify/product/template/product.rb
80
+ - lib/generators/permissify/product/template/products.rb
81
+ - lib/generators/permissify/product/template/views/_additional_index_columns.html.erb
82
+ - lib/generators/permissify/product/template/views/_permissions_fields.html.erb
75
83
  - lib/generators/permissify/product/USAGE
76
84
  - lib/generators/permissify/role/role_generator.rb
77
85
  - lib/generators/permissify/role/template/role.rb