068_fix_grants.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:5k
源码类别:

Ajax

开发平台:

Others

  1. class FixGrants < ActiveRecord::Migration
  2.   class Right < ActiveRecord::Base
  3.     include BareMigration
  4.     # there's technically no need for these serialize declaration because in
  5.     # this script active_config and staged_config will always be NULL anyway.
  6.     serialize :active_config
  7.     serialize :staged_config
  8.   end
  9.   class ProfilesRight < ActiveRecord::Base
  10.     include BareMigration
  11.     # there's technically no need for these serialize declaration because in
  12.     # this script active_config and staged_config will always be NULL anyway.
  13.     serialize :active_config
  14.     serialize :staged_config
  15.   end
  16.   def self.up
  17.     STDERR.puts "Creating users rights"
  18.     drop_table :profiles_to_rights
  19.     create_table :profiles_rights, :force => true do |t|
  20.       t.column :profile_id, :int
  21.       t.column :right_id, :int
  22.     end
  23.     Right.transaction do
  24.       admin = Profile.find_by_label('admin')
  25.       publisher = Profile.find_by_label('publisher')
  26.       contributor = Profile.find_by_label('contributor')
  27.       # Global admin rights
  28.       right = Right.find_by_name('admin')
  29.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  30.       # Article rights
  31.       right = Right.find_by_name('content_create')
  32.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  33.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  34.       right = Right.find_by_name('content_edit')
  35.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  36.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  37.       right = Right.find_by_name('content_delete')
  38.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  39.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  40.       # Categories rights
  41.       right = Right.find_by_name('category_create')
  42.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  43.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  44.       right = Right.find_by_name('category_edit')
  45.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  46.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  47.       right = Right.find_by_name('category_delete')
  48.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  49.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  50.       # Page rights
  51.       right = Right.find_by_name('page_create')
  52.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  53.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  54.       right = Right.find_by_name('page_edit')
  55.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  56.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  57.       right = Right.find_by_name('page_delete')
  58.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  59.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  60.       # Feedback
  61.       right = Right.find_by_name('feedback_create')
  62.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  63.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  64.       ProfilesRight.create(:profile_id => contributor.id, :right_id => right.id)
  65.       right = Right.find_by_name('feedback_self_edit')
  66.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  67.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  68.       ProfilesRight.create(:profile_id => contributor.id, :right_id => right.id)
  69.       right = Right.find_by_name('feedback_edit')
  70.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  71.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  72.       ProfilesRight.create(:profile_id => contributor.id, :right_id => right.id)
  73.       right = Right.find_by_name('feedback_self_delete')
  74.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  75.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  76.       ProfilesRight.create(:profile_id => contributor.id, :right_id => right.id)
  77.       right = Right.find_by_name('feedback_delete')
  78.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  79.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  80.       ProfilesRight.create(:profile_id => contributor.id, :right_id => right.id)
  81.       # Users
  82.       right = Right.find_by_name('user_create')
  83.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  84.       right = Right.find_by_name('user_edit')
  85.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  86.       right = Right.find_by_name('user_self_edit')
  87.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  88.       ProfilesRight.create(:profile_id => publisher.id, :right_id => right.id)
  89.       ProfilesRight.create(:profile_id => contributor.id, :right_id => right.id)
  90.       right = Right.find_by_name('user_delete')
  91.       ProfilesRight.create(:profile_id => admin.id, :right_id => right.id)
  92.     end
  93.   end
  94.   def self.down
  95.     drop_table :rights
  96.     drop_table :profiles_rights
  97.   end
  98. end