mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01: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?
|
if @todo.errors.empty?
|
||||||
@todo.add_predecessor_list(p.predecessor_list)
|
@todo.add_predecessor_list(p.predecessor_list)
|
||||||
@saved = @todo.save
|
@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?
|
@todo.block! if @todo.uncompleted_predecessors?
|
||||||
else
|
else
|
||||||
@saved = false
|
@saved = false
|
||||||
|
|
@ -194,7 +194,7 @@ class TodosController < ApplicationController
|
||||||
todo.block!
|
todo.block!
|
||||||
end
|
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
|
@todos << todo
|
||||||
@not_done_todos << todo if p.new_context_created || p.new_project_created
|
@not_done_todos << todo if p.new_context_created || p.new_project_created
|
||||||
|
|
@ -1218,7 +1218,7 @@ end
|
||||||
|
|
||||||
def update_tags
|
def update_tags
|
||||||
if params[:tag_list]
|
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
|
@todo.tags.reload #force a reload for proper rendering
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ module RecurringTodos
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_tags
|
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
|
@recurring_todo.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -349,7 +349,7 @@ class Todo < ApplicationRecord
|
||||||
def add_tags=(params)
|
def add_tags=(params)
|
||||||
unless params[:tag].nil?
|
unless params[:tag].nil?
|
||||||
tag_list = params[:tag].inject([]) { |list, value| list << value[:name] }
|
tag_list = params[:tag].inject([]) { |list, value| list << value[:name] }
|
||||||
tag_with tag_list.join(", "), user
|
tag_with tag_list.join(", ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ class TodoFromRichMessage
|
||||||
todo.project_id = project_id unless project_id.nil?
|
todo.project_id = project_id unless project_id.nil?
|
||||||
todo.show_from = show_from if show_from.is_a? Time
|
todo.show_from = show_from if show_from.is_a? Time
|
||||||
todo.due = due if due.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.starred = star
|
||||||
todo
|
todo
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,13 @@ module IsTaggable
|
||||||
end
|
end
|
||||||
|
|
||||||
# Replace the existing tags on <tt>self</tt>. Accepts a string of tagnames, an array of tagnames, or an array of Tags.
|
# 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)
|
list = tag_cast_to_string(list)
|
||||||
|
|
||||||
# Transactions may not be ideal for you here; be aware.
|
# Transactions may not be ideal for you here; be aware.
|
||||||
Tag.transaction do
|
Tag.transaction do
|
||||||
current = tags.to_a.map(&:name)
|
current = tags.to_a.map(&:name)
|
||||||
_add_tags(list - current, user)
|
_add_tags(list - current)
|
||||||
_remove_tags(current - list)
|
_remove_tags(current - list)
|
||||||
end
|
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.
|
# 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.
|
# 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|
|
tag_cast_to_string(incoming).each do |tag_name|
|
||||||
# added following check to prevent empty tags from being saved (which will fail)
|
# added following check to prevent empty tags from being saved (which will fail)
|
||||||
if tag_name.present?
|
if tag_name.present?
|
||||||
begin
|
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?
|
raise Tag::Error, "tag could not be saved: #{tag_name}" if tag.new_record?
|
||||||
tags << tag
|
tags << tag
|
||||||
rescue ActiveRecord::StatementInvalid => e
|
rescue ActiveRecord::StatementInvalid => e
|
||||||
|
|
@ -62,9 +62,9 @@ module IsTaggable
|
||||||
end
|
end
|
||||||
|
|
||||||
# Removes tags from <tt>self</tt>. Accepts a string of tagnames, an array of tagnames, or an array of Tags.
|
# 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)
|
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
|
end
|
||||||
|
|
||||||
def get_tag_name_from_item(item)
|
def get_tag_name_from_item(item)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue