Skip to content

Commit

Permalink
Merge pull request #2390 from cloudnativedaysjp/feat/multiple-speakers
Browse files Browse the repository at this point in the history
複数人登壇
  • Loading branch information
takaishi authored Sep 20, 2024
2 parents 4d2c162 + 559a579 commit 132a81b
Show file tree
Hide file tree
Showing 47 changed files with 973 additions and 231 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/build-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ jobs:
--tag ${image_tag_sha} \
${image_tag_sha}-amd64
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: '${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs:${{ github.sha }}'
format: 'table'
exit-code: '0'
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
# - name: Run Trivy vulnerability scanner
# uses: aquasecurity/trivy-action@master
# with:
# image-ref: '${{ steps.login-ecr.outputs.registry }}/dreamkast-ecs:${{ github.sha }}'
# format: 'table'
# exit-code: '0'
# ignore-unfixed: true
# vuln-type: 'os,library'
# severity: 'CRITICAL,HIGH'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ package-lock.json
localstack
/app/assets/builds/*
!/app/assets/builds/.keep
.aider*
8 changes: 7 additions & 1 deletion app/controllers/auth0_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ def callback
# Redirect to the URL you want after successful auth

if request.env['omniauth.origin']
redirect_to("#{request.env['omniauth.origin']}?state=#{params[:state]}")
uri = URI.parse(request.env['omniauth.origin'])
uri.query = if uri.query.nil?
"state=#{params[:state]}"
else
"#{uri.query}&state=#{params[:state]}"
end
redirect_to(uri.to_s)
else
redirect_to('/')
end
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/speaker_dashboard/speakers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def create
r.each do |talk|
SpeakerMailer.cfp_registered(@conference, @speaker, talk).deliver_later
end
format.html { redirect_to("/#{@conference.abbr}/speaker_dashboard", notice: 'Speaker was successfully created.') }
flash.now[:notice] = 'スピーカーもしくはプロポーザルの作成・更新に成功しました。'
format.html { redirect_to("/#{@conference.abbr}/speaker_dashboard") }
format.json { render(:show, status: :created, location: @speaker) }
else
format.html { render(:new) }
Expand Down
88 changes: 88 additions & 0 deletions app/controllers/speaker_invitation_accepts_controller.rb
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
35 changes: 35 additions & 0 deletions app/controllers/speaker_invitations_controller.rb
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
1 change: 0 additions & 1 deletion app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ import './bootstrap_custom.js'
import './timetable.js'
import './talks.js'
import './speaker_form.js'
import './cropbox.js'

//require.context('images/cndo201', true, /\.(png|jpg|jpeg|svg)$/)
1 change: 0 additions & 1 deletion app/javascript/packs/cndf2023.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import '../stylesheets/cndf2023'
import './bootstrap_custom.js'
import './talks.js'
import './speaker_form.js'
import './cropbox.js'
import './timetable.js'


Expand Down
1 change: 0 additions & 1 deletion app/javascript/packs/cndo2021.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Rails.start()
// import '../stylesheets/cndo2021'
import './bootstrap_custom.js'
import './talks.js'
import './cropbox.js'
import './timetable.js'
import "particles.js";
import './speaker_form.js'
1 change: 0 additions & 1 deletion app/javascript/packs/cnds2024.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import "./controllers/index.js"
// import '../stylesheets/cnds2024'
import './bootstrap_custom.js'
import './talks.js'
import './cropbox.js'
import './timetable.js'
import "particles.js";
import './speaker_form.js'
Expand Down
1 change: 0 additions & 1 deletion app/javascript/packs/cndt2023.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Rails.start()
import '../stylesheets/cndt2023'
import './bootstrap_custom.js'
import './talks.js'
import './cropbox.js'
import './timetable.js'


Expand Down
65 changes: 65 additions & 0 deletions app/javascript/packs/controllers/crop_upload_controller.js
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)
}
})
})
}
}
2 changes: 2 additions & 0 deletions app/javascript/packs/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ application.register("remove-link-field", RemoveLinkFieldController)
import CopyController from "./copy_controller.js"
application.register("copy", CopyController)

import CropUploadController from "./crop_upload_controller.js"
application.register("crop-upload", CropUploadController)
55 changes: 0 additions & 55 deletions app/javascript/packs/cropbox.js

This file was deleted.

21 changes: 21 additions & 0 deletions app/mailers/speaker_invitation_mailer.rb
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
Loading

0 comments on commit 132a81b

Please sign in to comment.