From 56306be42c3cb6bfd0501d69e0f3a1842c8f5989 Mon Sep 17 00:00:00 2001 From: hukl Date: Sun, 8 Feb 2009 15:16:22 +0100 Subject: lots of concept refinements --- app/models/node.rb | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'app/models/node.rb') diff --git a/app/models/node.rb b/app/models/node.rb index cd02657..bc48ac4 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -10,7 +10,6 @@ class Node < ActiveRecord::Base # Class methods - # Returns a page for a given node. If no revision is supplied, it returns # the last / current one. If a specific revision number is supplied, the # corresponding revision of that page is returned. Get the current / latest @@ -37,28 +36,34 @@ class Node < ActiveRecord::Base # Instance Methods + # check if there is a page which has a nil :published_at column + # if there is one - it is considered a draft def draft - - # check if there is a page which has a nil :published_at column - # if there is one - it is considered a draft else a new revision is - # created - if draft = pages.find_by_published_at(nil) draft + end + end + + def find_or_create_draft user + if draft && draft.user == user + draft + elsif draft && draft.user != user + raise "Page is locked" else - # make a new fresh page with node reference - draft = Page.create( head.attributes ) + self.pages.create! :user_id => user.id end - - draft end def publish_draft! - self.head = self.draft - self.save! - - self.head.published_at = Time.now - self.head.save! + if self.draft + self.head = self.draft + self.save! + + self.head.published_at = Time.now + self.head.save! + else + nil + end end # returns an array with all parts of a unique_name rather than a string -- cgit v1.3