Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion decidim-conferences/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ en:
no_taxonomy_filters_found: No taxonomy filters found.
registrations_count:
one: There has been 1 registration.
other: There has been %{count} registrations.
other: There have been %{count} registrations.
slug_help_html: 'URL slugs are used to generate the URLs that point to this conference. Only accepts letters, numbers and dashes, and must start with a letter. Example: %{url}'
taxonomies: Taxonomies
content_blocks:
Expand Down
6 changes: 3 additions & 3 deletions decidim-core/app/cells/decidim/upload_modal/files.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
<% end %>

<% if has_title? %>
<span><%= title_for(attachment) %> (<%= truncated_file_name_for(attachment) %>)</span>
<span><%= title_for(attachment) %></span>
<%= form.hidden_field attribute, multiple: true, value: attachment.id, id: attachment.id %>
<% else %>
<% if blob(attachment).image? %>
<span><%= truncated_file_name_for(attachment, 15) %></span>
<span><%= title_for(attachment) %></span>
<% else %>
<%= link_to truncated_file_name_for(attachment), file_attachment_path(attachment) %>
<%= link_to title_for(attachment), file_attachment_path(attachment), class: "w-full break-all mb-2" %>
<% end %>
<% end %>
</div>
Expand Down
8 changes: 5 additions & 3 deletions decidim-core/app/cells/decidim/upload_modal_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ def id_for(attachment)
end

def title_for(attachment)
return unless has_title?

decidim_html_escape(decidim_sanitize(translated_attribute(attachment.title)))
if has_title?
decidim_html_escape(decidim_sanitize(translated_attribute(attachment.title)))
else
decidim_html_escape(decidim_sanitize(determine_filename(attachment)))
end
end

def truncated_file_name_for(attachment, max_length = 31)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ def call
verify_oauth_signature!

begin
if existing_identity
user = existing_identity.user
verify_user_confirmed(user)
if (@identity = existing_identity)
@user = existing_identity.user
verify_user_confirmed(@user)

return broadcast(:ok, user)
trigger_omniauth_event("decidim.user.omniauth_login")
return broadcast(:ok, @user)
end
return broadcast(:invalid) if form.invalid?

transaction do
create_or_find_user
@identity = create_identity
end
trigger_omniauth_registration
trigger_omniauth_event

broadcast(:ok, @user)
rescue NeedTosAcceptance
Expand Down Expand Up @@ -128,9 +129,9 @@ def signature_valid?
form.oauth_signature == signature
end

def trigger_omniauth_registration
def trigger_omniauth_event(event_name = "decidim.user.omniauth_registration")
ActiveSupport::Notifications.publish(
"decidim.user.omniauth_registration",
event_name,
user_id: @user.id,
identity_id: @identity.id,
provider: form.provider,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import UploadModal from "src/decidim/direct_uploads/upload_modal";
import { truncateFilename } from "src/decidim/direct_uploads/upload_utility";
import { escapeHtml, escapeQuotes } from "src/decidim/utilities/text";

const updateModalTitle = (modal) => {
Expand Down Expand Up @@ -30,7 +29,7 @@ const updateActiveUploads = (modal) => {
const [removeFiles, addFiles] = [modal.items.filter(({ removable }) => removable), modal.items.filter(({ removable }) => !removable)]

addFiles.forEach((file, ix) => {
let title = truncateFilename(file.name, 19)
let title = file.name

let hidden = ""
if (file.hiddenField) {
Expand Down Expand Up @@ -80,7 +79,7 @@ const updateActiveUploads = (modal) => {
const template = `
<div ${attachmentIdOrHiddenField} data-filename="${escapeQuotes(file.name)}" data-title="${escapeQuotes(title)}">
${(/image/).test(file.type) && "<div><img src=\"data:,\" role=\"presentation\" /></div>" || ""}
<span>${escapeHtml(title)} (${escapeHtml(truncateFilename(file.name))})</span>
<span>${escapeHtml(title)}</span>
${hidden}
</div>
`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Uploader } from "src/decidim/direct_uploads/uploader";
import icon from "src/decidim/icon";
import { truncateFilename } from "src/decidim/direct_uploads/upload_utility";
import { escapeHtml, escapeQuotes } from "src/decidim/utilities/text";

const STATUS = {
Expand Down Expand Up @@ -172,13 +171,13 @@ export default class UploadModal {
createUploadItem(file, errors, opts = {}) {
const okTemplate = `
<img src="data:,", role="presentation" />
<span>${escapeHtml(truncateFilename(file.name))}</span>
<span class="upload-modal__span">${escapeHtml(file.name)}</span>
`

const errorTemplate = `
<div>${icon("error-warning-line")}</div>
<div>
<span>${escapeHtml(truncateFilename(file.name))}</span>
<span class="upload-modal__span">${escapeHtml(file.name)}</span>
<span>${this.locales.validation_error}</span>
<ul>${errors.map((error) => `<li>${error}</li>`).join("\n")}</ul>
</div>
Expand All @@ -189,11 +188,11 @@ export default class UploadModal {
<div>
<div>
<label>${this.locales.filename}</label>
<span>${escapeHtml(truncateFilename(file.name))}</span>
<span class="upload-modal__span">${escapeHtml(file.name)}</span>
</div>
<div>
<label for="${file.name}">${this.locales.title}</label>
<input class="sm" type="text" value="${escapeQuotes(opts.title || truncateFilename(file.name))}" id="${file.name}" />
<input class="sm" type="text" value="${escapeQuotes(opts.title || file.name)}" id="${file.name}" />
</div>
</div>
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@
}

span {
@apply text-sm text-gray-2 mx-auto;
@apply text-sm text-gray-2 mx-auto w-full break-all mb-2;
}
}
}

&__span {
@apply w-full break-all mb-2;
}
}
4 changes: 2 additions & 2 deletions decidim-core/spec/cells/decidim/upload_modal_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def model_name
expect(subject).to have_css("[data-filename='#{filename}']")

details = subject.find(".attachment-details")
expect(details).to have_content("#{decidim_sanitize_translated(attachments[0].title)} (#{filename})")
expect(details).to have_content(decidim_sanitize_translated(attachments[0].title).to_s)
end
end

Expand Down Expand Up @@ -165,7 +165,7 @@ def model_name
expect(subject).to have_css("[data-filename='#{filename1}']")

details = subject.find(".attachment-details", match: :first)
expect(details).to have_content("#{decidim_sanitize_translated(attachments[0].title)} (#{filename1})")
expect(details).to have_content(decidim_sanitize_translated(attachments[0].title).to_s)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,21 +284,38 @@ module Comments
end

context "when a user exists with that identity" do
before do
user = create(:user, email:, organization:)
create(:identity, user:, provider:, uid:)
end
let!(:user) { create(:user, email:, organization:) }
let!(:identity) { create(:identity, user:, provider:, uid:) }

it "broadcasts ok" do
expect { command.call }.to broadcast(:ok)
end

it "notifies about login with oauth data" do
allow(command).to receive(:create_identity).and_return(identity)
expect(ActiveSupport::Notifications)
.to receive(:publish)
.with("decidim.user.omniauth_login",
user_id: user.id,
identity_id: identity.id,
provider:,
uid:,
email:,
name: "Facebook User",
nickname: "facebook_user",
avatar_url: "http://www.example.com/foo.jpg",
raw_data: {},
tos_agreement: true,
accepted_tos_version: user.accepted_tos_version,
newsletter_notifications_at: user.newsletter_notifications_at)
command.call
end

context "with the same email as reported by the identity" do
it "confirms the user" do
command.call

user = User.find_by(email:)
expect(user).to be_confirmed
expect(user.reload).to be_confirmed
end
end

Expand All @@ -308,8 +325,7 @@ module Comments
it "does not confirm the user" do
command.call

user = User.find_by(email:)
expect(user).not_to be_confirmed
expect(user.reload).not_to be_confirmed
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/spec/lib/form_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ def organization
let(:present?) { true }

it "renders the filename" do
expect(output).to include(%(<a href="#{url}">#{filename}</a>))
expect(output).to include(%(<a class="w-full break-all mb-2" href="#{url}">#{filename}</a>))
end

it "does not render an image tag" do
Expand Down
12 changes: 12 additions & 0 deletions docs/modules/customize/pages/oauth.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,16 @@ ActiveSupport::Notifications.subscribe "decidim.user.omniauth_registration" do |
end
----

Note that, if the user is already registered, the `CreateOmniauthRegistration` command will not trigger the "decidim.user.omniauth_registration" event by instead it will trigger the "decidim.user.omniauth_login" event, which has the same payload as the registration event.

For instance, to retrigger the `IdCatMobilVerificationJob` after a user logs in via omniauth, you can subscribe to the "decidim.user.omniauth_login" event as follows:

[source,ruby]
----
ActiveSupport::Notifications.subscribe "decidim.user.omniauth_login" do |name, started, finished, unique_id, data|
puts "the data: #{data.inspect}"
IdCatMobilVerificationJob.perform_later(data[:raw_data])
end
----

It is a good practice to delegate the required implementation to a Job to bring a fastest response to the user, also it will avoid that crashes in this code to propagate to the registration process.
Loading