app/models/dc_policy.rb in drg_cms-0.4.39 vs app/models/dc_policy.rb in drg_cms-0.4.53

- old
+ new

@@ -19,13 +19,20 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #++ +######################################################################## +# Mongoid::Document model for dc_policy documents embedded into dc_sites collection documents. +# +# DcPolicy documents define policies for accessing data on web site. Policies define which +# user roles (defined in dc_policy_roles collection) has no access, can view or edit data (sees CMS menu) on +# current active web page. Policies can then be applied to individual documents belonging to the web site. +# +# Document defined as default, holds top level policy which is inherited by all +# other policies. Default policy is also used when document has no access policy assigned. ######################################################################### -# -######################################################################### class DcPolicy include Mongoid::Document include Mongoid::Timestamps field :name, type: String @@ -33,29 +40,27 @@ field :is_default, type: Boolean, default: false field :active, type: Boolean, default: true field :updated_by, type: BSON::ObjectId field :message, type: String, default: '' - #embeds_many :dc_policy_rules embeds_many :dc_policy_rules, as: :policy_rules embedded_in :dc_site validates :name, :length => { :minimum => 4 } validates :message, :length => { :minimum => 5 } -# index name: 1 -# index 'dc_policy_rules._id' => 1 - +=begin ######################################################################### -# +# Returns values for permissions ready to be used in select field. ######################################################################### -def self.values_for_permissions +def self.values_for_permissions [['NO_ACCESS',0],['CAN_VIEW',1],['CAN_CREATE',2],['CAN_EDIT',4],['CAN_EDIT_ALL',8],['CAN_DELETE',16],['CAN_DELETE_ALL',32],['CAN_ADMIN',64],['SUPERADMIN',128]] end + ######################################################################### -# returns all possible policy rules for use in select input field +# Returns all possible policy rules for use in select input field ######################################################################### def self.choices4_policies() rez = [] all.each do |policy| rez << [policy.name, nil] @@ -63,11 +68,11 @@ rez << ['-- ' + rule.name, rule._id] end end rez end - + ######################################################################### # Returns policy rules for the site. Since it is called from policy_role form # which can be embedded in lots of tables (collections) table name of parent # is also send as parameter. ######################################################################### @@ -88,7 +93,8 @@ def self.policy_rule_name_for(id) pol = find_by('dc_policy_rules._id' => BSON::ObjectId.from_string(id)) return 'Invalid policy name!' if pol.nil? pol.dc_policy_rules.find(id).name end - +=end + end