Skip to content

Commit

Permalink
Customize submitter widget form
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-hank committed Oct 1, 2021
1 parent a6390c8 commit beb7a07
Show file tree
Hide file tree
Showing 17 changed files with 541 additions and 1 deletion.
65 changes: 65 additions & 0 deletions app/assets/stylesheets/layouts/_submitter_widget.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,70 @@
.submitter_widget_notices {
/* @HACK:FIXME Firefox has problems with rendering an iframe */
width: calc(100% - 1px);

section.main.app {
background-color: #ffffff;
}

.main-inner {
margin: 0;
}

.inner-padding {
padding: 0;
}

section.notice-new {
header {
padding: 0;
}

section {
padding: 20px 5px;
}

header {
padding-bottom: 20px;
}

.buttons-wrapper {
padding: 45px 5px 0 5px;

.submit {
float: none;
display: inline-block;
}
}

section.notice-body {
#add-another {
display: inline-block;
}
}

section.works {
.body-wrapper {
width: 100%;
float: none;
}
}

section.role {
.body-wrapper {
width: 100%;
float: none;
margin-top: 0 !important;
}

label.half-width {
width: 180px;
}

.input {
width: 100%;
float: none;
padding: 0;
}
}
}
}
52 changes: 51 additions & 1 deletion app/controllers/submitter_widget_notices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,72 @@ class SubmitterWidgetNoticesController < NoticesController
def new
response.headers.delete 'X-Frame-Options'

@display_models = Notice.display_models - [Counternotice, DataProtection]
@widget_public_key = params[:widget_public_key]

(render :submission_disabled and return) unless allowed_to_submit?
(render :select_type and return) if params[:type].blank?
(render 'notices/submitter_widget/select_type' and return) if params[:type].blank?

build_new_notice

render 'notices/submitter_widget/new'
end

def create
response.headers.delete 'X-Frame-Options'

@widget_public_key = params[:widget_public_key]

unless authorized_to_create?
Rails.logger.warn "Could not auth user with params: #{params}"
flash.alert = 'Something went wrong. Contact a website administrator.'
redirect_to_new_form and return
end

@notice = NoticeBuilder.new(
get_notice_type(params), notice_params, current_user
).build

if @notice.valid?
@notice.save
@notice.mark_for_review
flash.notice = 'Notice created! Thank you, it will be reviewed and published on the Lumen database website.'
else
Rails.logger.warn "Could not create notice with params: #{params}"
flash.alert = 'Notice creation failed. See errors below.'
end

redirect_to_new_form
end

private

def build_entity_notice_roles(model_class)
model_class::DEFAULT_ENTITY_NOTICE_ROLES.each do |role|
next if %w[sender recipient].include?(role)

@notice.entity_notice_roles.build(name: role).build_entity(
kind: default_kind_based_on_role(role)
)
end
end

def allowed_to_submit?
widget_public_key &&
User.find_by_widget_public_key(widget_public_key.to_s)
end

def authorized_to_create?
allowed_to_submit?
end

def widget_public_key
key = 'widget_public_key'

params[key] || request.env["HTTP_X_#{key.upcase}"]
end

def redirect_to_new_form
redirect_to new_submitter_widget_notice_path(type: params[:notice][:type], widget_public_key: @widget_public_key)
end
end
5 changes: 5 additions & 0 deletions app/helpers/submitter_widget_notices_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module SubmitterWidgetNoticesHelper
def form_partial_for(instance)
"notices/submitter_widget/#{instance.class.name.tableize.singularize}_form"
end
end
33 changes: 33 additions & 0 deletions app/views/notices/submitter_widget/_counterfeit_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%= render 'notices/submitter_widget/form_components/header',
label: 'Counterfeit notice' %>
<%= simple_form_for(notice, url: submitter_widget_notices_path(widget_public_key: @widget_public_key)) do |form| %>
<section class="notice-body">
<h4><span>Step 1.</span> Describe the Notice</h4>
<%= render 'notices/submitter_widget/form_components/main_metadata', form: form %>
</section>

<section class="works">
<h4><span>Step 2.</span> Original Works in Question</h4>
<p>Enter information about the original work(s) and allegedly infringing counterfeit URL(s).</p>
<% form.object.works.each_with_index do |work, index| %>
<%= form.simple_fields_for(:works, work, child_index: index) do |works_form| %>
<div class="body-wrapper left">
<%= render(
partial: 'url_input_group',
locals: { notice: notice, assoc: :infringing_urls, works_form: works_form, index: index }
) %>
<%= works_form.input :kind, label: "Kind of Work", placeholder: "Movie, Music, Book" %>
</div>
<div class="body-wrapper right">
<%= works_form.input :description %>
</div>
<% index += 1 %>
<% end %>
<% end %>
</section>

<%= render 'notices/form_components/roles',
label: 'DMCA takedown notice',
form: form %>
<%= render 'notices/form_components/submit', form: form %>
<% end %>
31 changes: 31 additions & 0 deletions app/views/notices/submitter_widget/_court_order_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%= render 'notices/submitter_widget/form_components/header',
label: 'Court Order takedown notice' %>
<%= simple_form_for(notice, url: submitter_widget_notices_path(widget_public_key: @widget_public_key)) do |form| %>
<section class="notice-body">
<h4><span>Step 1.</span> Describe the Notice</h4>
<%= render 'notices/submitter_widget/form_components/main_metadata',
form: form %>
</section>

<section class="works">
<h4><span>Step 2.</span> Original Works in Question</h4>
<p>Enter information about the original work(s) and targeted URL(s).</p>
<% form.object.works.each_with_index do |work, index| %>
<%= form.simple_fields_for(:works) do |works_form| %>
<div class="body-wrapper left">
<%= render(
partial: 'url_input_group',
locals: { notice: notice, assoc: :infringing_urls, works_form: works_form, index: index }
) %>
</div>
<div class="body-wrapper right">
<%= works_form.input :description, label: 'Subject of Court Order' %>
</div>
<% end %>
<% end %>
<%= form.input :regulation_list, label: 'Laws Referenced by Court Order', placeholder: 'A comma separated list' %>
</section>

<%= render 'notices/form_components/roles', form: form %>
<%= render 'notices/form_components/submit', form: form %>
<% end %>
28 changes: 28 additions & 0 deletions app/views/notices/submitter_widget/_defamation_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%= render 'notices/submitter_widget/form_components/header',
label: 'Defamation takedown notice' %>
<%= simple_form_for(notice, url: submitter_widget_notices_path(widget_public_key: @widget_public_key)) do |form| %>
<section class="notice-body">
<h4><span>Step 1.</span> Describe the Notice</h4>
<%= render 'notices/submitter_widget/form_components/main_metadata', form: form %>
</section>

<section class="works">
<h4><span>Step 2.</span> URLs of Allegedly Defamatory Material</h4>
<p>Please do not include links to unnecessary material. <b>Any URLs you enter will be republished on this site.</b></p>
<% form.object.works.each_with_index do |work, index| %>
<%= form.simple_fields_for(:works) do |works_form| %>
<div class="body-wrapper left">
<%= render(
partial: 'url_input_group',
locals: { notice: notice, assoc: :infringing_urls, works_form: works_form, index: index }
) %>
</div>
<% end %>
<% end %>
</section>

<%= render 'notices/form_components/roles',
label: 'Defamation takedown notice',
form: form %>
<%= render 'notices/form_components/submit', form: form %>
<% end %>
35 changes: 35 additions & 0 deletions app/views/notices/submitter_widget/_dmca_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<%= render 'notices/submitter_widget/form_components/header',
label: 'DMCA takedown notice' %>
<%= simple_form_for(notice, url: submitter_widget_notices_path(widget_public_key: @widget_public_key)) do |form| %>
<section class="notice-body">
<h4><span>Step 1.</span> Describe the Notice</h4>
<%= render 'notices/submitter_widget/form_components/main_metadata', form: form %>
</section>

<section class="works">
<h4><span>Step 2.</span> Original Works in Question</h4>
<p>Enter information about the original work(s) and allegedly infringing URL(s).</p>
<% form.object.works.each_with_index do |work, index| %>
<%= form.simple_fields_for(:works, work, child_index: index) do |works_form| %>
<div class="body-wrapper left">
<% [:copyrighted_urls, :infringing_urls].each do |assoc| %>
<%= render(
partial: 'url_input_group',
locals: { notice: notice, assoc: assoc, works_form: works_form, index: index }
) %>
<% end %>
<%= works_form.input :kind, label: "Kind of Work", placeholder: "Movie, Music, Book" %>
</div>
<div class="body-wrapper right">
<%= works_form.input :description %>
</div>
<% index += 1 %>
<% end %>
<% end %>
</section>

<%= render 'notices/form_components/roles',
label: 'DMCA takedown notice',
form: form %>
<%= render 'notices/form_components/submit', form: form %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%= render 'notices/submitter_widget/form_components/header' %>
<%= simple_form_for(notice, url: submitter_widget_notices_path(widget_public_key: @widget_public_key)) do |form| %>
<section class="notice-body">
<h4><span>Step 1.</span> Describe the Notice</h4>
<%= render 'notices/submitter_widget/form_components/main_metadata', form: form, request_collection: GovernmentRequest::VALID_REQUEST_TYPES %>
</section>

<section class="works">
<h4><span>Step 2.</span> Original Works in Question</h4>
<p>Enter information about the original work(s) and infringing URL(s).</p>
<div class="body-wrapper left">
<%= form.simple_fields_for(:works) do |works_form| %>
<%= works_form.simple_fields_for(:copyrighted_urls) do |urls_form| %>
<%= urls_form.input :url, label: "URL of original work", placeholder: "https://" %>
<% end %>
<%= works_form.simple_fields_for(:infringing_urls) do |urls_form| %>
<%= urls_form.input :url, label: "URL mentioned in request", placeholder: "https://" %>
<% end %>
<%= works_form.input :kind, label: "Kind of Work", placeholder: "Movie, Music, Book" %>
</div>
<div class="body-wrapper right">
<%= works_form.input :description, label: 'Subject of Government Request' %>
</div>
<% end %>
<%= form.input :regulation_list, label: 'Relevant laws or regulations', placeholder: 'A comma separated list' %>
</section>

<%= render 'notices/form_components/roles', form: form %>
<%= render 'notices/form_components/submit', form: form %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%= render 'notices/submitter_widget/form_components/header' %>
<%= simple_form_for(notice, url: submitter_widget_notices_path(widget_public_key: @widget_public_key)) do |form| %>
<section class="notice-body">
<h4><span>Step 1.</span> Describe the Notice</h4>
<%= render 'notices/submitter_widget/form_components/main_metadata', form: form, request_collection: LawEnforcementRequest::VALID_REQUEST_TYPES %>
</section>

<section class="works">
<h4><span>Step 2.</span> Original Works in Question</h4>
<p>Enter information about the original work(s) and infringing URL(s).</p>
<% form.object.works.each_with_index do |work, index| %>
<%= form.simple_fields_for(:works, work, child_index: index) do |works_form| %>
<div class="body-wrapper left">
<% [:copyrighted_urls, :infringing_urls].each do |assoc| %>
<%= render(
partial: 'url_input_group',
locals: { notice: notice, assoc: assoc, works_form: works_form, index: index }
) %>
<% end %>
<%= works_form.input :kind, label: "Kind of Work", placeholder: "Movie, Music, Book" %>
</div>
<div class="body-wrapper right">
<%= works_form.input :description, label: 'Subject of Enforcement Request' %>
</div>
<% end %>
<% end %>
<%= form.input :regulation_list, label: 'Relevant laws or regulations', placeholder: 'A comma separated list' %>
</section>

<%= render 'notices/form_components/roles',
form: form %>
<%= render 'notices/form_components/submit', form: form %>
<% end %>
33 changes: 33 additions & 0 deletions app/views/notices/submitter_widget/_other_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<%= render 'notices/submitter_widget/form_components/header',
label: 'notice' %>
<%= simple_form_for(notice, url: submitter_widget_notices_path(widget_public_key: @widget_public_key)) do |form| %>
<section class="notice-body">
<h4><span>Step 1.</span> Describe the Notice</h4>
<%= render 'notices/submitter_widget/form_components/main_metadata', form: form %>
</section>

<section class="works">
<h4><span>Step 2.</span> Original Works in Question</h4>
<p>Enter information about the original work(s) and the problematic URL(s).</p>
<% form.object.works.each_with_index do |work, index| %>
<%= form.simple_fields_for(:works, work, child_index: index) do |works_form| %>
<div class="body-wrapper left">
<% [:copyrighted_urls, :infringing_urls].each do |assoc| %>
<%= render(
partial: 'url_input_group',
locals: { notice: notice, assoc: assoc, works_form: works_form, index: index }
) %>
<% end %>
</div>
<div class="body-wrapper right">
<%= works_form.input :description, label: "Complaint" %>
</div>
<% end %>
<% end %>
</section>

<%= render 'notices/form_components/roles',
label: 'Notice',
form: form %>
<%= render 'notices/form_components/submit', form: form %>
<% end %>
Loading

0 comments on commit beb7a07

Please sign in to comment.