mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-22 05:50:47 +02:00
#1955: Use existing user parameter in taggable models instead of passing it
This commit is contained in:
parent
5394973346
commit
f6d1f243c5
5 changed files with 12 additions and 12 deletions
|
@ -106,7 +106,7 @@ class TodosController < ApplicationController
|
|||
if @todo.errors.empty?
|
||||
@todo.add_predecessor_list(p.predecessor_list)
|
||||
@saved = @todo.save
|
||||
@todo.tag_with(tag_list, current_user) if @saved && tag_list.present?
|
||||
@todo.tag_with(tag_list) if @saved && tag_list.present?
|
||||
@todo.block! if @todo.uncompleted_predecessors?
|
||||
else
|
||||
@saved = false
|
||||
|
@ -194,7 +194,7 @@ class TodosController < ApplicationController
|
|||
todo.block!
|
||||
end
|
||||
|
||||
todo.tag_with(tag_list, current_user) if @saved && tag_list.present?
|
||||
todo.tag_with(tag_list) if @saved && tag_list.present?
|
||||
|
||||
@todos << todo
|
||||
@not_done_todos << todo if p.new_context_created || p.new_project_created
|
||||
|
@ -1218,7 +1218,7 @@ end
|
|||
|
||||
def update_tags
|
||||
if params[:tag_list]
|
||||
@todo.tag_with(params[:tag_list], current_user)
|
||||
@todo.tag_with(params[:tag_list])
|
||||
@todo.tags.reload #force a reload for proper rendering
|
||||
end
|
||||
end
|
||||
|
|
|
@ -129,7 +129,7 @@ module RecurringTodos
|
|||
end
|
||||
|
||||
def save_tags
|
||||
@recurring_todo.tag_with(@filterred_attributes[:tag_list], @user) if @filterred_attributes[:tag_list].present?
|
||||
@recurring_todo.tag_with(@filterred_attributes[:tag_list]) if @filterred_attributes[:tag_list].present?
|
||||
@recurring_todo.reload
|
||||
end
|
||||
|
||||
|
|
|
@ -349,7 +349,7 @@ class Todo < ApplicationRecord
|
|||
def add_tags=(params)
|
||||
unless params[:tag].nil?
|
||||
tag_list = params[:tag].inject([]) { |list, value| list << value[:name] }
|
||||
tag_with tag_list.join(", "), user
|
||||
tag_with tag_list.join(", ")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ class TodoFromRichMessage
|
|||
todo.project_id = project_id unless project_id.nil?
|
||||
todo.show_from = show_from if show_from.is_a? Time
|
||||
todo.due = due if due.is_a? Time
|
||||
todo.tag_with tags, @user unless tags.nil? || tags.empty?
|
||||
todo.tag_with tags unless tags.nil? || tags.empty?
|
||||
todo.starred = star
|
||||
todo
|
||||
end
|
||||
|
|
|
@ -26,13 +26,13 @@ module IsTaggable
|
|||
end
|
||||
|
||||
# Replace the existing tags on <tt>self</tt>. Accepts a string of tagnames, an array of tagnames, or an array of Tags.
|
||||
def tag_with(list, user)
|
||||
def tag_with(list)
|
||||
list = tag_cast_to_string(list)
|
||||
|
||||
# Transactions may not be ideal for you here; be aware.
|
||||
Tag.transaction do
|
||||
current = tags.to_a.map(&:name)
|
||||
_add_tags(list - current, user)
|
||||
_add_tags(list - current)
|
||||
_remove_tags(current - list)
|
||||
end
|
||||
|
||||
|
@ -46,12 +46,12 @@ module IsTaggable
|
|||
# Add tags to <tt>self</tt>. Accepts a string of tagnames, an array of tagnames, or an array of Tags.
|
||||
#
|
||||
# We need to avoid name conflicts with the built-in ActiveRecord association methods, thus the underscores.
|
||||
def _add_tags(incoming, user)
|
||||
def _add_tags(incoming)
|
||||
tag_cast_to_string(incoming).each do |tag_name|
|
||||
# added following check to prevent empty tags from being saved (which will fail)
|
||||
if tag_name.present?
|
||||
begin
|
||||
tag = user.tags.where(:name => tag_name).first_or_create
|
||||
tag = self.user.tags.where(:name => tag_name).first_or_create
|
||||
raise Tag::Error, "tag could not be saved: #{tag_name}" if tag.new_record?
|
||||
tags << tag
|
||||
rescue ActiveRecord::StatementInvalid => e
|
||||
|
@ -62,9 +62,9 @@ module IsTaggable
|
|||
end
|
||||
|
||||
# Removes tags from <tt>self</tt>. Accepts a string of tagnames, an array of tagnames, or an array of Tags.
|
||||
def _remove_tags outgoing
|
||||
def _remove_tags(outgoing)
|
||||
outgoing = tag_cast_to_string(outgoing)
|
||||
tags.destroy(*(tags.select{|tag| outgoing.include? tag.name}))
|
||||
tags.destroy(*(self.user.tags.select{|tag| outgoing.include? tag.name}))
|
||||
end
|
||||
|
||||
def get_tag_name_from_item(item)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue