Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
added basic workflow email stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Dec 4, 2008
1 parent c61f916 commit d10dbc5
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 15 deletions.
16 changes: 12 additions & 4 deletions app/models/ansuz_mailer.rb
@@ -1,11 +1,19 @@
class AnsuzMailer < ActionMailer::Base
def page_review_notifications(page, sent_at = Time.now)
subject 'Someone has submitted a page for review'
recipients 'knewter@gmail.com'
from 'knewter@gmail.com'
subject "[#{page}] has been submitted for review."
recipients User.content_approvers.map(&:email)
from OUTGOING_ADMIN_EMAIL
sent_on sent_at

body :url => edit_admin_page_url(page)
body :url => edit_admin_page_url(page), :page => page
end

def page_publication_notifications(page, sent_at = Time.now)
subject "[#{page}] has been approved."
recipients User.authors.map(&:email)
from OUTGOING_ADMIN_EMAIL
sent_on sent_at

body :page => page, :url => url_for(:controller => "page", :action => "indexer", :path => page.path.collect(&:name))
end
end
23 changes: 18 additions & 5 deletions app/models/page.rb
Expand Up @@ -25,15 +25,15 @@ class Page < ActiveRecord::Base
aasm_column :status
aasm_initial_state :draft
aasm_state :reviewing, :enter => :inform_reviewers
aasm_state :published
aasm_state :published, :enter => :inform_authors
aasm_state :draft

aasm_event :submit_for_review do
transitions :to => :reviewing, :from => [:draft]
transitions :to => :reviewing, :from => [:draft, :reviewing]
end

aasm_event :publish do
transitions :to => :published, :from => [:reviewing, :draft]
transitions :to => :published, :from => [:reviewing, :draft, :published]
end

acts_as_tree :order => 'page_order'
Expand All @@ -53,6 +53,10 @@ def inform_reviewers
AnsuzMailer.deliver_page_review_notifications(self)
end

def inform_authors
AnsuzMailer.deliver_page_publication_notifications(self)
end

public
def linked_children
children.select{|x| x.linked? }
Expand Down Expand Up @@ -99,9 +103,18 @@ def publishable_children
self.children.find :all, :conditions => ["status=? AND linked = ?", 'published', true]
end

def path
ancestor_pages + [self]
end

def ancestor_pages
the_ancestors = self.ancestors.reverse
the_ancestors.delete_at 0
the_ancestors
end

def ancestor_path
path = self.ancestors.reverse
path.delete_at 0
path = ancestor_pages
return "/pages/" unless path.length > 0
"/pages/" + path.collect(&:name).join('/') + "/"
end
Expand Down
9 changes: 5 additions & 4 deletions app/models/role.rb
Expand Up @@ -8,10 +8,11 @@ class Role < ActiveRecord::Base

validates_uniqueness_of :name, :scope => [:authorizable_id, :authorizable_type]

STATIC_ROLES = ["admin", "initial_reviewer", "final_reviewer", "author"]
PUBLISHING_ROLES = ["admin", "final_reviewer"]
AUTHORING_ROLES = ["admin", "author"]
DRAFT_VIEWING_ROLES = ["admin", "final_reviewer", "initial_reviewer", "author"]
STATIC_ROLES = ["admin", "initial_reviewer", "final_reviewer", "author"]
PUBLISHING_ROLES = ["admin", "final_reviewer"]
CONTENT_APPROVER_ROLES = ["admin", "final_reviewer", "initial_reviewer"]
AUTHORING_ROLES = ["admin", "author"]
DRAFT_VIEWING_ROLES = ["admin", "final_reviewer", "initial_reviewer", "author"]

named_scope :root, :conditions => "authorizable_type IS NULL and authorizable_id IS NULL"

Expand Down
8 changes: 8 additions & 0 deletions app/models/user.rb
Expand Up @@ -35,8 +35,12 @@ class User < ActiveRecord::Base
validates_length_of :login, :within => 3..40
validates_length_of :email, :within => 3..100
validates_uniqueness_of :login, :email, :case_sensitive => false

before_save :encrypt_password

named_scope :content_approvers, { :include => { :roles => {} }, :conditions => ["roles.name IN (?)", Role::CONTENT_APPROVER_ROLES] }
named_scope :authors, { :include => { :roles => {} }, :conditions => ["roles.name IN (?)", Role::AUTHORING_ROLES] }

# Authenticates a user by their login name and unencrypted password. Returns the user or nil.
def self.authenticate(login, password)
u = find_by_login(login) # need to get the salt
Expand Down Expand Up @@ -99,6 +103,10 @@ def can_author_content?
has_a_role_from? Role::AUTHORING_ROLES
end

def can_approve_content?
has_a_role_from? Role::CONTENT_APPROVER_ROLES
end

def has_a_role_from? roles_array
roles_array.detect{|r| has_role? r}
end
Expand Down
3 changes: 3 additions & 0 deletions app/views/ansuz_mailer/page_publication_notifications.erb
@@ -0,0 +1,3 @@
[<%= @page %>] has been approved.

<%= @url %>
2 changes: 1 addition & 1 deletion app/views/ansuz_mailer/page_review_notifications.erb
@@ -1,3 +1,3 @@
Someone has submitted a page for review. You can find it here:
Review [<%= @page %>]

<%= @url %>
2 changes: 1 addition & 1 deletion app/views/content/_page.html.erb
Expand Up @@ -4,7 +4,7 @@
<% if logged_in? && get_setting('show_inline_edit_links') %>
<% if current_user.can_author_content? %>
<%= link_to "[Edit]", edit_admin_page_path(:id => page.id, :anchor => "page-plugin-#{plugin.id}") %>
<% elsif current_user.can_publish? %>
<% elsif current_user.can_approve_content? %>
<%= link_to "[Manage Content]", edit_admin_page_path(:id => page.id, :anchor => "page-plugin-#{plugin.id}") %>
<% end %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/initializers/email_constants.rb
@@ -0,0 +1 @@
OUTGOING_ADMIN_EMAIL = 'test@ansuz.com'

0 comments on commit d10dbc5

Please sign in to comment.