There is a ruby gem which handles a lot of stuff for you
General principles
---
items and profiles which have corresponding things on the server
Models
---
Item
---
database fields
<pre>
class AddImages < ActiveRecord::Migration
def self.up
create_table :test_images do |t|
t.string :photo_file_name
t.string :mm_key
t.string :mm_approved
t.string :mm_id
t.string :test_user_id
end
end
def self.down
drop_table :test_images
end
end
</pre>
Adding moderation to the model
<pre>
class Comment < ActiveRecord::Base
extend ModMonkey::Item::ActMethods
make_moderatable :content_type=>'text',
:profile_info => :identifier => lambda{|obj| obj.test_user.email,
:profile_url => lambda{|obj| SITE_URL+"/test_users/#{obj.test_user.id}"}
},
:item_url => lambda{|obj| SITE_URL+"/test_comments/#{obj.id}"},
:editable_attrs => [:body]
def mm_content
{ :body => self.body }
end
end
</pre>
optional attrs and methods
* content_type
* mm_content
* editable_attrs
* item_url
* profile_url
* asset_url
Specifying these values can be done via: lambdas, symbols or variables
callbacks created automatically for the following:
* create
* adds item to queue
* update
* updates item in queue
* delete
* removes item from queue
Though these are automatic, it is usually necessary to think about how failure is handled. Section on this in "Maintenance".
assumptions about moderated content and applying decisions
---
The default behaviour is to switch mm_approved on or off with a modified find. However this could be overridden to destroy the objects completely, or do some other strategy.
added methods
---
* reject
* approve
usually necessary to apply callbacks to these to cover:
* cascading
* banning user
* emailing notifications
---
Profile
---
database fields
<pre>
class CreateTestUsers < ActiveRecord::Migration
def self.up
create_table :test_users do |t|
t.string :email
t.boolean :banned
t.timestamps
end
end
def self.down
drop_table :test_users
end
end
</pre>
Adding moderatble functionality
---
<pre>
class User < ActiveRecord::Base
extend ModMonkey::Profile::ActMethods
make_moderatable
end
</pre>
methods called via the options given:
* ban
* unban
usually necessary to apply callbacks to these to cover:
* cascading
* banning user
* emailing notifications
---
Controllers
---
SECURITY
implementation - AOP
Items
---
<pre>
class TestImagesController < ApplicationController
extend ModMonkey::ControllerActMethods
make_moderatable
end
</pre>
mm_update
update action applies decision etc
Flags
---
Method which can be posted to to add a flag to the item in the queue. Can have an optional reason, if UI supports this.
---
Profile
---
<pre>
class TestUsersController < ApplicationController
extend ModMonkey::ProfileControllerActMethods
make_moderatable
end
</pre>
mm\_profile\_update checks permission and calls apply\_mod\_monkey\_params
all the callbacks for banning etc
- doesn't do cascading on the users content on this side, but does on the server ?
---
Routes
---
items which are moderated need to have a flags resource which can be posted to -
often helpful to have a helper in views
Gotchas
---
* login_required
Rake tasks
---
General principles
---
items and profiles which have corresponding things on the server
Models
---
Item
---
database fields
<pre>
class AddImages < ActiveRecord::Migration
def self.up
create_table :test_images do |t|
t.string :photo_file_name
t.string :mm_key
t.string :mm_approved
t.string :mm_id
t.string :test_user_id
end
end
def self.down
drop_table :test_images
end
end
</pre>
Adding moderation to the model
<pre>
class Comment < ActiveRecord::Base
extend ModMonkey::Item::ActMethods
make_moderatable :content_type=>'text',
:profile_info => :identifier => lambda{|obj| obj.test_user.email,
:profile_url => lambda{|obj| SITE_URL+"/test_users/#{obj.test_user.id}"}
},
:item_url => lambda{|obj| SITE_URL+"/test_comments/#{obj.id}"},
:editable_attrs => [:body]
def mm_content
{ :body => self.body }
end
end
</pre>
optional attrs and methods
* content_type
* mm_content
* editable_attrs
* item_url
* profile_url
* asset_url
Specifying these values can be done via: lambdas, symbols or variables
callbacks created automatically for the following:
* create
* adds item to queue
* update
* updates item in queue
* delete
* removes item from queue
Though these are automatic, it is usually necessary to think about how failure is handled. Section on this in "Maintenance".
assumptions about moderated content and applying decisions
---
The default behaviour is to switch mm_approved on or off with a modified find. However this could be overridden to destroy the objects completely, or do some other strategy.
added methods
---
* reject
* approve
usually necessary to apply callbacks to these to cover:
* cascading
* banning user
* emailing notifications
---
Profile
---
database fields
<pre>
class CreateTestUsers < ActiveRecord::Migration
def self.up
create_table :test_users do |t|
t.string :email
t.boolean :banned
t.timestamps
end
end
def self.down
drop_table :test_users
end
end
</pre>
Adding moderatble functionality
---
<pre>
class User < ActiveRecord::Base
extend ModMonkey::Profile::ActMethods
make_moderatable
end
</pre>
methods called via the options given:
* ban
* unban
usually necessary to apply callbacks to these to cover:
* cascading
* banning user
* emailing notifications
---
Controllers
---
SECURITY
implementation - AOP
Items
---
<pre>
class TestImagesController < ApplicationController
extend ModMonkey::ControllerActMethods
make_moderatable
end
</pre>
mm_update
update action applies decision etc
Flags
---
Method which can be posted to to add a flag to the item in the queue. Can have an optional reason, if UI supports this.
---
Profile
---
<pre>
class TestUsersController < ApplicationController
extend ModMonkey::ProfileControllerActMethods
make_moderatable
end
</pre>
mm\_profile\_update checks permission and calls apply\_mod\_monkey\_params
all the callbacks for banning etc
- doesn't do cascading on the users content on this side, but does on the server ?
---
Routes
---
items which are moderated need to have a flags resource which can be posted to -
often helpful to have a helper in views
Gotchas
---
* login_required
Rake tasks
---