From ecbfed930054d232008fee4317f7f551f0d77686 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 27 Dec 2011 21:49:08 +0400 Subject: [PATCH] [refs #54] Fix user_id validation into issues --- app/controllers/issues_controller.rb | 2 +- app/models/issue.rb | 8 ++++++-- app/views/issues/_list.html.haml | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index a6a4cb734..031ca5ff4 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -27,7 +27,7 @@ class IssuesController < ApplicationController @issue = Issue.new(params[:issue]) @issue.user_id = @user_id @issue.project_id = @project.id - if @issue.save! + if @issue.save flash[:notice] = I18n.t("flash.issue.saved") redirect_to project_issues_path(@project) else diff --git a/app/models/issue.rb b/app/models/issue.rb index 586175b89..78b41a8b0 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -7,7 +7,7 @@ class Issue < ActiveRecord::Base has_many :comments, :as => :commentable has_many :subscribes, :as => :subscribeable - validates :title, :body, :project_id, :user_id, :presence => true + validates :title, :body, :project_id, :presence => true #attr_readonly :serial_id @@ -17,6 +17,10 @@ class Issue < ActiveRecord::Base after_create :deliver_issue_assign_notification after_update :deliver_issue_assign_notification + def assign_uname + user.uname if user + end + protected def set_serial_id @@ -52,7 +56,7 @@ class Issue < ActiveRecord::Base def collect_recipient_ids recipients = self.project.relations.by_role('admin').where(:object_type => 'User').map { |rel| rel.read_attribute(:object_id) } - recipients = recipients | [self.user_id] + recipients = recipients | [self.user_id] if self.user_id recipients = recipients | [self.project.owner_id] if self.project.owner_type == 'User' recipients end diff --git a/app/views/issues/_list.html.haml b/app/views/issues/_list.html.haml index 41ec58acc..7415a221e 100644 --- a/app/views/issues/_list.html.haml +++ b/app/views/issues/_list.html.haml @@ -9,7 +9,7 @@ %td = link_to issue.title, show_issue_path(@project, issue.serial_id) %td - = link_to issue.user.uname, user_path(issue.user) + = link_to issue.user.uname, user_path(issue.user) if issue.user %td = issue.status %td.last