2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# Copyright (C) 2010-2011 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2009-10-20 04:36:55 +04:00
|
|
|
module ObjectDaddyHelpers
|
2010-02-08 21:53:12 +03:00
|
|
|
# TODO: Remove these three once everyone has ported their code to use the
|
|
|
|
# new object_daddy version with protected attribute support
|
2010-01-23 19:50:41 +03:00
|
|
|
def User.generate_with_protected(attributes={})
|
2010-02-08 21:53:12 +03:00
|
|
|
User.generate(attributes)
|
2010-01-23 19:50:41 +03:00
|
|
|
end
|
|
|
|
|
2009-10-20 04:36:55 +04:00
|
|
|
def User.generate_with_protected!(attributes={})
|
2010-02-08 21:53:12 +03:00
|
|
|
User.generate!(attributes)
|
2010-01-23 19:50:41 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def User.spawn_with_protected(attributes={})
|
2010-02-08 21:53:12 +03:00
|
|
|
User.spawn(attributes)
|
2009-10-20 04:36:55 +04:00
|
|
|
end
|
|
|
|
|
2010-09-10 23:44:45 +04:00
|
|
|
def User.add_to_project(user, project, roles)
|
|
|
|
roles = [roles] unless roles.is_a?(Array)
|
|
|
|
Member.generate!(:principal => user, :project => project, :roles => roles)
|
|
|
|
end
|
|
|
|
|
2009-10-20 04:36:55 +04:00
|
|
|
# Generate the default Query
|
|
|
|
def Query.generate_default!(attributes={})
|
|
|
|
query = Query.spawn(attributes)
|
|
|
|
query.name ||= '_'
|
|
|
|
query.save!
|
|
|
|
query
|
|
|
|
end
|
|
|
|
|
|
|
|
# Generate an issue for a project, using it's trackers
|
|
|
|
def Issue.generate_for_project!(project, attributes={})
|
|
|
|
issue = Issue.spawn(attributes) do |issue|
|
|
|
|
issue.project = project
|
2010-09-10 07:09:02 +04:00
|
|
|
issue.tracker = project.trackers.first unless project.trackers.empty?
|
|
|
|
yield issue if block_given?
|
2009-10-20 04:36:55 +04:00
|
|
|
end
|
|
|
|
issue.save!
|
|
|
|
issue
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|