Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi Tag controller action now accepts lists also #4606

Merged
merged 5 commits into from
Jan 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/controllers/subscription_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ def digest
end

def multiple_add
unless params[:names]
if !params[:names] || params[:names] == ''
flash[:notice] = "Please enter tags for subscription in the url."
redirect_to "/subscriptions" + "?_=" + Time.now.to_i.to_s
return
end
if params[:names].is_a? String
tag_list = params[:names].split(',')
else
tag_list = params[:names]
end
tag_list = params[:names].split(',')
# should be logged in to subscribe
if current_user
# assume tag, for now
Expand Down Expand Up @@ -170,8 +175,8 @@ def multiple_add
# user or node subscription
end
else
flash[:warning] = "You must be logged in to subscribe for email updates."
redirect_to "/login"
flash[:warning] = "You must be logged in to subscribe for email updates!"
redirect_to "/login?return_to=" + request.fullpath
end
end

Expand Down
1 change: 0 additions & 1 deletion app/views/tag/_tags.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<ul class= "list-inline">
<% tags.each do |tag| %>
<% if tag.class == NodeTag %>

<% if power_tag ^ tag.name.include?(':') # XOR operator??? %>
<li><span id="tag_<%= tag.tid %>" class="label <%= label_name %>" style="cursor:pointer" data-toggle="popover" data-trigger="focus" data-count=0 data-placement="top" data-content="<p style='text-align:center;'><a href='/tag/<%= tag.name %>'><%= Tag.tagged_node_count(tag.name) || 0 %> notes</a> - <a href='/contributors/<%= tag.name %>'><%= Tag.contributors(tag.name).count %> people <br></a></p> <p style='text-align:center;font-size:12px;'><%if tag.description %><%= tag.description %> |<% end %> created by <a href='/profile/<%= tag.try(:author).try(:username) %>'><%= tag.try(:author).try(:username) %></a> <%= time_ago_in_words(Time.at(tag.date)) %> ago </p> <div style='text-align:center;'><a href='/subscribe/tag/<%= tag.name %>' class='btn btn-primary'>Follow</a></div>" data-html="true" title="<%= tag.name %>">
<%= tag.name %>
Expand Down
5 changes: 3 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@
get 'subscriptions' => 'subscription#index'
get 'subscriptions/digest' => 'subscription#digest'
get 'subscribe/multiple/:type/:names' => 'subscription#multiple_add'
put 'subscribe/multiple/:type/:names' => 'subscription#multiple_add'

post 'subscribe/multiple/:type/:names' => 'subscription#multiple_add'
get 'subscribe/multiple/:type' => 'subscription#multiple_add'
post 'subscribe/multiple/:type' => 'subscription#multiple_add'
get 'wiki/stale' => 'wiki#stale'
get 'wiki/new' => 'wiki#new'
get 'wiki/replace/:id' => 'wiki#replace'
Expand Down
14 changes: 14 additions & 0 deletions test/functional/subscription_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@ def setup
assert users(:bob).following(:kites)
assert users(:bob).following(:balloon)
end

test 'should not subscribe to multiple tags in case of empty string' do
UserSession.create(users(:bob))
assert users(:bob).following(:awesome)
get :multiple_add, params: { type: 'tag', names: '' }
assert_response :redirect
assert_equal "Please enter tags for subscription in the url.", flash[:notice]
end

test 'user is not logged in and tries to subscribe multiple tags' do
get :multiple_add, params: { type: 'tag', names: 'kites,balloon' }
assert_redirected_to '/login?return_to=/subscribe/multiple/tag/kites,balloon'
assert_equal "You must be logged in to subscribe for email updates!", flash[:warning]
end
end