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

Ajax

开发平台:

Others

  1. class AddUsersRights < 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 ProfilesToRight < 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.     create_table :rights, :force => true do |t|
  19.       t.column :name, :string
  20.       t.column :description, :string
  21.     end
  22.     create_table :profiles_to_rights, :force => true do |t|
  23.       t.column :profile_id, :int
  24.       t.column :right_id, :int
  25.     end
  26.     Right.transaction do
  27.       admin = Profile.find_by_label('admin')
  28.       publisher = Profile.find_by_label('publisher')
  29.       contributor = Profile.find_by_label('contributor')
  30.       # Global admin rights
  31.       right = Right.create(:name => 'admin', :description => 'Global administration')
  32.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  33.       # Article rights
  34.       right = Right.create(:name => 'content_create', :description => 'Create article')
  35.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  36.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  37.       right = Right.create(:name => 'content_edit', :description => 'Edit article')
  38.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  39.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  40.       right = Right.create(:name => 'content_delete', :description => 'Delete article')
  41.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  42.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  43.       # Categories rights
  44.       right = Right.create(:name => 'category_create', :description => 'Create a category')
  45.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  46.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  47.       right = Right.create(:name => 'category_edit', :description => 'Edit a category')
  48.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  49.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  50.       right = Right.create(:name => 'category_delete', :description => 'Delete a category')
  51.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  52.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  53.       # Page rights
  54.       right = Right.create(:name => 'page_create', :description => 'Create a category')
  55.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  56.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  57.       right = Right.create(:name => 'page_edit', :description => 'Edit a category')
  58.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  59.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  60.       right = Right.create(:name => 'page_delete', :description => 'Delete a category')
  61.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  62.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  63.       # Feedback
  64.       right = Right.create(:name => 'feedback_create', :description => 'Add a comment')
  65.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  66.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  67.       ProfilesToRight.create(:profile_id => contributor.id, :right_id => right.id)
  68.       right = Right.create(:name => 'feedback_self_edit', :description => 'Edit self comments')
  69.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  70.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  71.       ProfilesToRight.create(:profile_id => contributor.id, :right_id => right.id)
  72.       right = Right.create(:name => 'feedback_edit', :description => 'Edit any comment')
  73.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  74.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  75.       ProfilesToRight.create(:profile_id => contributor.id, :right_id => right.id)
  76.       right = Right.create(:name => 'feedback_self_delete', :description => 'Delete self comments')
  77.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  78.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  79.       ProfilesToRight.create(:profile_id => contributor.id, :right_id => right.id)
  80.       right = Right.create(:name => 'feedback_delete', :description => 'Delete any comment')
  81.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  82.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  83.       ProfilesToRight.create(:profile_id => contributor.id, :right_id => right.id)
  84.       # Users
  85.       right = Right.create(:name => 'user_create', :description => 'Create users')
  86.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  87.       right = Right.create(:name => 'user_edit', :description => 'Edit users')
  88.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  89.       right = Right.create(:name => 'user_self_edit', :description => 'Edit self account')
  90.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  91.       ProfilesToRight.create(:profile_id => publisher.id, :right_id => right.id)
  92.       ProfilesToRight.create(:profile_id => contributor.id, :right_id => right.id)
  93.       right = Right.create(:name => 'user_delete', :description => 'Delete users')
  94.       ProfilesToRight.create(:profile_id => admin.id, :right_id => right.id)
  95.     end
  96.   end
  97.   def self.down
  98.     drop_table :rights
  99.     drop_table :profiles_to_rights
  100.   end
  101. end