我正在处理此脚本 - > http://www.redmine.org/plugins/default_members< - Sajin Andrei
我已经完全修改了钩子以满足我的需求,但我意识到它实际上添加了作为已定义组成员的每个用户。
我想要做的是将整个组添加到项目中,这样如果我将其他人添加到同一组中,我就不必更新每个项目。
这是我的代码:
# Debuggin [Default: commented/disabled]
#require 'logger'
class DefmembersHook < Redmine::Hook::ViewListener
def controller_projects_new_after_save(context={ })
#log = Logger.new('/usr/local/share/redmine/log/plugin.log')
params = context[:params]
project = context[:project]
roles = Role.find_all_givable
setting_group = Setting.plugin_redmine_default_members[:group] ? Setting.plugin_redmine_default_members[:group] : 'Manager'
groups ||= setting_group.split(",")
groups.each do |gp|
#log.error "gp: #{gp}"
group = Group.find(:first, :conditions => ["LOWER(lastname) = ?", gp.to_s.downcase])
#log.error "group: #{group}"
users = User.active.in_group(group).all(:limit => 100)
users.each do |user|
if user[:lastname] != 'Admin' && user[:lastname] != 'Anonymous'
#log.error "inizio per #{user}"
rs = Role.find_by_name(group.to_s)
#log.error "rs: #{rs}"
m = Member.new(:user => user, :roles => [rs])
project.members << m
#log.error "fine per #{user}"
end
end
end
end
end
并且实际上正在按照Sajin Andrei的意图工作,从一个组中添加单个用户。
我想做这样的事情
m = Member.new(:group => group, :roles => [rs])
project.members << m
但它不起作用(显然)...... 希望有人可以提供帮助
答案 0 :(得分:1)
找到了解决方案:
# Modificata da CARLO RUGGIERO per RETINA
# Permette di aggiungere interi gruppi ad un progetto in automatico!
class DefmembersHook < Redmine::Hook::ViewListener
def controller_projects_new_after_save(context={ })
params = context[:params]
project = context[:project]
#roles = Role.find_all_givable
setting_group = Setting.plugin_redmine_default_members[:group] ? Setting.plugin_redmine_default_members[:group] : 'Manager'
groups ||= setting_group.split(",")
groups.each do |gp|
group = Group.find(:first, :conditions => ["LOWER(lastname) = ?", gp.to_s.downcase])
rs = Role.find_by_name(group.to_s)
project.members << Member.new(:principal => group, :roles => [rs])
end
end
end
问题是:user 标记只接受用户元素 将其更改为:校长我已将其付诸实践
m = Member.new(:principal => group, :roles => [rs])
project.members << m
希望有人发现这个有用的