Skip to content

Commit

Permalink
Merge pull request #1980 from zz9pzza/issue_4211
Browse files Browse the repository at this point in the history
issue_4211 Record ip addresses on new works
  • Loading branch information
sarken committed Jan 9, 2015
2 parents cfc8c94 + 750346c commit 9fa5dd9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def new
@series = current_user.series.uniq
@unposted = current_user.unposted_work

@work.ip_address = request.remote_ip
# for clarity, add the collection and recipient
if params[:assignment_id] && (@challenge_assignment = ChallengeAssignment.find(params[:assignment_id])) && @challenge_assignment.offering_user == current_user
@work.challenge_assignments << @challenge_assignment
Expand Down Expand Up @@ -280,6 +281,7 @@ def create
@series = current_user.series.uniq
@collection = Collection.find_by_name(params[:work][:collection_names])

@work.ip_address = request.remote_ip
if params[:edit_button]
render :new
elsif params[:cancel_button]
Expand Down
16 changes: 14 additions & 2 deletions app/views/works/_meta.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,23 @@
</dd>
<% end %>

<dt class="stats"><%= ts("Stats") %>:</dt>
<dt class="stats"><%= ts("Stats:") %></dt>
<dd class="stats">
<% end %><!-- end of cache -->

<%= work_meta_list(@work, @chapter) %>
</dd>
</dd>
<% if logged_in_as_admin? %>
<dt class="ip">
<%= ts('IP Address:') %>
</dt>
<dd class="ip">
<% if @work.ip_address.nil? %>
<%= ts('No address recorded') %>
<% else %>
<%= @work.ip_address %>
<% end %>
</dd>
<% end %>
</dl>
</div>
11 changes: 11 additions & 0 deletions db/migrate/20150106211421_add_ip_address_to_works.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddIpAddressToWorks < ActiveRecord::Migration
def self.up
add_column :works, :ip_address, :string
add_index "works", "ip_address"
end

def self.down
remove_index "works", "ip_address"
remove_column :works, :ip_address
end
end

0 comments on commit 9fa5dd9

Please sign in to comment.