Skip to content

Commit

Permalink
[wip] publiclab#1951 Add "Join" button to people lists (publiclab#1954)
Browse files Browse the repository at this point in the history
* chg: added button to join the powertag group's tag

* add: added check to see if current_user is available before showing the button

* fix: added defined? to check if the curre_user variable is defined

* fix: added defined? check to see if the current_user variable is defined

* chg: modified redirection for the create action

* chg: added button for when the user is not currently logged in

* add: added current_user as a parameter

* fix: added defined? to check if the curre_user variable is defined

* chg: added button for when the user is not currently logged in

* text tweaks

* tweak

* Update user_tags_controller_test.rb

* Update wiki_controller_test.rb

* Update node_shared.rb

* Update application_helper.rb

* Hopefully fix test failures

* Update application_helper.rb
  • Loading branch information
jahl authored and jywarren committed Feb 1, 2018
1 parent b58eb14 commit 3d59089
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/controllers/user_tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create
else
flash[:notice] = I18n.t('user_tags_controller.tag_created', tag_name: @output[:saved][0][0]).html_safe
end
redirect_to info_path, id: params[:id]
redirect_to '/profile/' + user.username
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def insert_extras(body)
body = NodeShared.upgrades_grid(body)
body = NodeShared.notes_map(body)
body = NodeShared.notes_map_by_tag(body)
body = NodeShared.people_grid(body)
body = NodeShared.people_map(body)
body = NodeShared.people_grid(body, @current_user || nil) # <= to allow testing of insert_extras
body = NodeShared.graph_grid(body)
body = NodeShared.wikis_grid(body)
body
Expand Down
3 changes: 2 additions & 1 deletion app/models/concerns/node_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def self.people_map(body, _page = 1)


# in our interface, "users" are known as "people" because it's more human
def self.people_grid(body, _page = 1)
def self.people_grid(body, current_user = nil, _page = 1)
body.gsub(/[^\>`](\<p\>)?\[people\:(\S+)\]/) do |_tagname|
tagname = Regexp.last_match(2)
exclude = nil
Expand Down Expand Up @@ -285,6 +285,7 @@ def self.people_grid(body, _page = 1)
tagname: tagname,
randomSeed: rand(1000).to_s,
className: 'people-grid-' + tagname.parameterize,
current_user: current_user,
users: users
})
output
Expand Down
7 changes: 6 additions & 1 deletion app/views/grids/_people.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@
<% end %>
<% end %>
</table>

<% if !current_user.nil? %>
<p><a class="btn btn-primary" href="/profile/tags/create/<%= current_user.id %>?name=<%= tagname %>">Join this group</a></p>
<% else %>
<p><a class="btn btn-primary disabled" href="">Join this group</a></p>
<p><a href="/login">Login/Sign Up to join!</a></p>
<% end %>
<script>
(function(){
$(".<%= className %>-<%= randomSeed %> .show-all a").click(function() {
Expand Down
6 changes: 3 additions & 3 deletions test/functional/user_tags_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def setup
post :create, id: users(:bob).id, name: 'environment'
end
assert_equal 'environment tag created successfully', flash[:notice]
assert_redirected_to info_path
assert_redirected_to "/profile/#{users(:bob).username}"
end

test 'should create a new tags via xhr' do
Expand Down Expand Up @@ -51,14 +51,14 @@ def setup
# duplicate tag
post :create, id: users(:bob).id, name: 'environment'
assert_equal 'Error: tag already exists.', assigns[:output][:errors][0]
assert_redirected_to info_path
assert_redirected_to "/profile/#{users(:bob).username}"
end

test 'should not allow empty tag name' do
UserSession.create(users(:bob))
post :create, id: users(:bob).id, value: ''
assert_equal 'Error: value cannot be empty', assigns[:output][:errors][0]
assert_redirected_to info_path
assert_redirected_to "/profile/#{users(:bob).username}"
end

test 'admin should delete existing tag of normal user' do
Expand Down
2 changes: 2 additions & 0 deletions test/functional/wiki_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def teardown
assert_not_nil assigns(:revision)
# we subselect because for some reason the view is not returning the `<p>` and `</p>\n` wrapped
# ... messy, but couldn't find a way to disable simple_format() on the second parameter here.
@current_user = users(:bob) # required for below test
assert_select 'div#content', auto_link(insert_extras(revision.render_body), sanitize: false)[3..-6]
end

Expand All @@ -361,6 +362,7 @@ def teardown
assert_response :success
assert_not_nil assigns(:node)
assert_not_nil assigns(:revision)
@current_user = users(:bob) # required for below test
assert_select 'div#content', auto_link(insert_extras(revision.render_body), sanitize: false)[3..-6]
end

Expand Down

0 comments on commit 3d59089

Please sign in to comment.