-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2390 from cloudnativedaysjp/feat/multiple-speakers
複数人登壇
- Loading branch information
Showing
47 changed files
with
973 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,4 @@ package-lock.json | |
localstack | ||
/app/assets/builds/* | ||
!/app/assets/builds/.keep | ||
.aider* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
class SpeakerInvitationAcceptsController < ApplicationController | ||
include SecuredSpeaker | ||
before_action :set_speaker | ||
|
||
skip_before_action :logged_in_using_omniauth?, only: [:invite] | ||
|
||
def invite | ||
return redirect_to(new_speaker_invitation_accept_path(token: params[:token])) if from_auth0?(params) | ||
@conference = Conference.find_by(abbr: params[:event]) | ||
@speaker = Speaker.find_by(conference: @conference, email: current_user[:info][:email]) | ||
@speaker_invitation = SpeakerInvitation.find_by(token: params[:token]) | ||
end | ||
|
||
def new | ||
@speaker_invitation_accept = SpeakerInvitationAccept.new | ||
@conference = Conference.find_by(abbr: params[:event]) | ||
|
||
@speaker_invitation = SpeakerInvitation.find_by(token: params[:token]) | ||
unless @speaker_invitation | ||
raise(ActiveRecord::RecordNotFound) | ||
end | ||
|
||
if Time.zone.now > @speaker_invitation.expires_at | ||
flash.now[:alert] = '招待メールが期限切れです。再度招待メールを送ってもらってください。' | ||
end | ||
@talk = @speaker_invitation.talk | ||
@proposal = @talk.proposal | ||
@speaker = if Speaker.where(email: current_user[:info][:email], conference: @conference).exists? | ||
Speaker.find_by(conference: @conference, email: current_user[:info][:email]) | ||
else | ||
Speaker.new(conference: @conference, email: current_user[:info][:email]) | ||
end | ||
end | ||
|
||
def create | ||
begin | ||
ActiveRecord::Base.transaction do | ||
@conference = Conference.find_by(abbr: params[:event]) | ||
@speaker_invitation = SpeakerInvitation.find(params[:speaker][:speaker_invitation_id]) | ||
|
||
speaker_param = speaker_invitation_accept_params.merge(conference: @conference, email: current_user[:info][:email]) | ||
speaker_param.delete(:speaker_invitation_id) | ||
|
||
@speaker = if Speaker.where(email: current_user[:info][:email], conference: @conference).exists? | ||
Speaker.find_by(conference: @conference, email: current_user[:info][:email]) | ||
else | ||
Speaker.new(conference: @conference, email: current_user[:info][:email]) | ||
end | ||
@speaker.update!(speaker_param) | ||
@speaker.save! | ||
|
||
@talk = @speaker_invitation.talk | ||
@talk.speakers << @speaker | ||
@talk.save! | ||
|
||
@speaker_invitation_accept = SpeakerInvitationAccept.new(conference_id: @conference.id, speaker_invitation_id: @speaker_invitation.id, speaker_id: @speaker.id, talk_id: @talk.id) | ||
@speaker_invitation_accept.save! | ||
|
||
|
||
redirect_to(speaker_dashboard_path(event: @conference.abbr), notice: 'Speaker was successfully added.') | ||
end | ||
rescue ActiveRecord::RecordInvalid => e | ||
render(:new, alert: e.message) | ||
end | ||
end | ||
|
||
def speaker_invitation_accept_params | ||
params.require(:speaker).permit( | ||
:speaker_invitation_id, | ||
:name, | ||
:name_mother_tongue, | ||
:sub, | ||
:email, | ||
:profile, | ||
:company, | ||
:job_title, | ||
:twitter_id, | ||
:github_id, | ||
:avatar, | ||
:conference_id, | ||
:additional_documents | ||
) | ||
end | ||
|
||
def from_auth0?(params) | ||
params[:state].present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class SpeakerInvitationsController < ApplicationController | ||
include SecuredSpeaker | ||
before_action :set_speaker | ||
def new | ||
@speaker_invitation = SpeakerInvitation.new | ||
@talk = Talk.find(params[:talk_id]) | ||
if @speaker.talks.find(@talk.id).nil? | ||
render_404 | ||
end | ||
end | ||
|
||
def create | ||
ActiveRecord::Base.transaction do | ||
@conference = Conference.find_by(abbr: params[:event]) | ||
@invitation = SpeakerInvitation.new(speaker_invitation_params) | ||
@invitation.conference_id = @conference.id | ||
@invitation.token = SecureRandom.hex(50) | ||
@invitation.expires_at = 1.days.from_now # 有効期限を1日後に設定 | ||
if @invitation.save | ||
SpeakerInvitationMailer.invite(@conference, @speaker, @invitation.talk, @invitation).deliver_now | ||
flash[:notice] = 'Invitation sent!' | ||
redirect_to("/#{@conference.abbr}/speaker_dashboard") | ||
else | ||
flash[:alert] = "#{@invitation.email} への招待メール送信に失敗しました: #{@invitation.errors.full_messages.join(', ')}" | ||
redirect_to(new_speaker_invitation_path(event: @conference.abbr, talk_id: @invitation.talk_id)) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def speaker_invitation_params | ||
params.require(:speaker_invitation).permit(:email, :talk_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/javascript/packs/controllers/crop_upload_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import Cropper from "cropperjs" | ||
|
||
export default class extends Controller { | ||
static targets = [ "fileInput" ] | ||
|
||
connect() { | ||
this.fileInputTargets.forEach(fileInput => { | ||
console.log(fileInput) | ||
this.cropUpload(fileInput) | ||
}) | ||
} | ||
|
||
cropUpload(fileInput) { | ||
console.log(fileInput) | ||
let formGroup = fileInput.parentNode | ||
console.log(formGroup) | ||
let hiddenInput = document.querySelector('.upload-data') | ||
console.log(hiddenInput) | ||
let imagePreview = document.querySelector('.image-preview img') | ||
console.log(imagePreview) | ||
|
||
formGroup.removeChild(fileInput) | ||
|
||
let uppy = Uppy.Core({ | ||
autoProceed: true, | ||
}) | ||
.use(Uppy.FileInput, { | ||
target: formGroup, | ||
locale: { strings: { chooseFiles: 'Choose file' } }, | ||
}) | ||
.use(Uppy.Informer, { | ||
target: formGroup, | ||
}) | ||
.use(Uppy.ProgressBar, { | ||
target: imagePreview.parentNode, | ||
}) | ||
.use(Uppy.ThumbnailGenerator, { | ||
thumbnailWidth: 600, | ||
}) | ||
.use(Uppy.XHRUpload, { | ||
endpoint: '/upload/avatar', | ||
}) | ||
|
||
uppy.on('upload-success', function (file, response) { | ||
imagePreview.src = response.uploadURL | ||
|
||
hiddenInput.value = JSON.stringify(response.body['data']) | ||
|
||
let copper = new Cropper(imagePreview, { | ||
aspectRatio: 1, | ||
viewMode: 1, | ||
guides: false, | ||
autoCropArea: 1.0, | ||
background: false, | ||
checkCrossOrigin: false, | ||
crop: function (event) { | ||
let data = JSON.parse(hiddenInput.value) | ||
data['metadata']['crop'] = event.detail | ||
hiddenInput.value = JSON.stringify(data) | ||
} | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class SpeakerInvitationMailer < ApplicationMailer | ||
include Rails.application.routes.url_helpers | ||
|
||
default from: 'CloudNative Days 実行委員会 <[email protected]>' | ||
layout 'mailer' | ||
|
||
def invite(conference, invited_by, talk, invitation) | ||
@conference = conference | ||
@invited_by = invited_by | ||
@talk = talk | ||
@invitation = invitation | ||
@new_accept_url = speaker_invitation_accepts_invite_url(event: @conference.abbr, token: @invitation.token, protocol:) | ||
mail(to: @invitation.email, subject: "#{@conference.name} 共同スピーカー招待") | ||
end | ||
|
||
private | ||
|
||
def protocol | ||
Rails.env.production? ? 'https' : 'http' | ||
end | ||
end |
Oops, something went wrong.