I'd like to add a custom filter field to "Add News" page in Redmine, so that when I add a new news I could select group of users the email should be sent to.
The field itself is a list of Redmine User groups and every user is assigned to at least 1 of them.
Has anybody done this? Any suggestions would be appreciated
I've located the 3 files related to the issue:
- /app/controller/news_controller.rb
- /app/models/news.rb
- /app/views/news/_form.html.erb
Environment: Redmine version 2.2.1.stable.11156 Ruby version 1.8.7 (x86_64-linux) Rails version 3.2.11 Environment production Database adapter MySQL Redmine plugins: no plugin installed
So far I've done only 1 modification in Redmine, which sends added news to all registered users. File: /app/modelsmailer.rb
Overview:
EDIT: Following your advice I moved mailer function to the controller:
def create
@news = News.new(:project => @project, :author => User.current)
@news.safe_attributes = params[:news]
@news.save_attachments(params[:attachments])
if @news.save
#news_added(@news)
if params[:group]
mail :to => GroupsUser.find(params[:group][:ids]).joins(:users).select("users.mail").compact,
:subject => "[#{@news.project.name}] #{l(:label_news)}: #{@news.title}"
else
render :new
end
end
end
But I'm getting error: NameError (uninitialized constant NewsController::GroupsUser): pointing to line
mail :to => GroupsUser.find