|
22 | 22 | run 'mkdir app/hyperstack/stores' |
23 | 23 | run 'mkdir app/hyperstack/models' |
24 | 24 | run 'mkdir app/hyperstack/operations' |
| 25 | +run 'mkdir app/policies' |
25 | 26 |
|
26 | 27 | # ----------------------------------- Add .keep files |
27 | 28 |
|
@@ -50,6 +51,36 @@ class HyperComponent |
50 | 51 | config.import 'hyperstack/component/jquery', client_only: true # remove this line if you don't need jquery |
51 | 52 | config.import 'hyperstack/hotloader', client_only: true if Rails.env.development? |
52 | 53 | end |
| 54 | +
|
| 55 | +# useful for debugging |
| 56 | +module Hyperstack |
| 57 | + def self.on_error(*args) |
| 58 | + ::Rails.logger.debug "\033[0;31;1mHYPERSTACK APPLICATION ERROR: #{args.join(", ")}\n"\ |
| 59 | + "To further investigate you may want to add a debugging "\ |
| 60 | + "breakpoint in config/initializers/hyperstack.rb\033[0;30;21m" |
| 61 | + end |
| 62 | +end if Rails.env.development? |
| 63 | +CODE |
| 64 | + |
| 65 | +# ----------------------------------- Add a default policy |
| 66 | +file 'app/policies/application_policy.rb', <<-CODE |
| 67 | +# Policies regulate access to your public models |
| 68 | +# The following policy will open up full access (but only in development) |
| 69 | +# The policy system is very flexible and powerful. See the documentation |
| 70 | +# for complete details. |
| 71 | +class Hyperstack::ApplicationPolicy |
| 72 | + # Allow any session to connect: |
| 73 | + always_allow_connection |
| 74 | + # Send all attributes from all public models |
| 75 | + regulate_all_broadcasts { |policy| policy.send_all } |
| 76 | + # Allow all changes to public models |
| 77 | + allow_change(to: :all, on: [:create, :update, :destroy]) { true } |
| 78 | + # allow remote access to all scopes - i.e. you can count or get a list of ids |
| 79 | + # for any scope or relationship |
| 80 | + ApplicationRecord.regulate_scope :all |
| 81 | +end unless Rails.env.production? |
| 82 | +# don't forget to provide a policy before production... |
| 83 | +raise "You need to define a Hyperstack policy for production" if Rails.env.production? |
53 | 84 | CODE |
54 | 85 |
|
55 | 86 | # ----------------------------------- Add NPM modules |
|
0 commit comments