Skip to content

Commit

Permalink
WIP - Video production flux
Browse files Browse the repository at this point in the history
  • Loading branch information
jonmaciel committed Apr 22, 2018
1 parent 3454ae3 commit 3b9bd36
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
36 changes: 35 additions & 1 deletion app/graphql/types/query_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
return Video.where(system: current_user.organization.systems) if current_user.end_user?
return Video.all if current_user.admin?
return Video.where(aasm_state: :script_creation) if current_user.script_writer?
return Video.joins('INNER JOIN "users_videos" ON "videos"."id" = "users_videos"."video_id"').where(users_videos: { user_id: current_user.id }, aasm_state: :production) if current_user.video_producer?
[]
end
end
Expand Down Expand Up @@ -125,7 +126,40 @@

require 'aws-sdk-s3'

new_name = "video_attachments/#{input[:videoId]}/#{SecureRandom.hex}.#{input[:fileType].split('/').last}"
new_name = "video/#{input[:videoId]}/attachments/#{SecureRandom.hex}.#{input[:fileType].split('/').last}"

Aws.config.update({
region: 'us-east-2',
credentials: Aws::Credentials.new('AKIAIDV3FJF3WMG5GHHA', 'q2tiO8ZKhbr/FvIkZYj5Ozl+9qhPl9DqLc3rAu6Z')
})

s3 = Aws::S3::Resource.new.bucket('tutorbox-files')

object = s3.object(new_name)

{
file_name: new_name,
signed_url: object.presigned_url(
:put,
expires_in: 5.minutes.to_i,
acl: 'public-read'
)
}
end
end


field :s3SignedUrlVideo, Types::S3Type do
argument :fileType, types.String, 'User ID'
argument :videoId, !types.ID, 'User ID'
resolve ->(_, input, context) do
return unless input[:fileType]

require 'aws-sdk-s3'

video = Video.find(input[:videoId])

new_name = "video/#{video.id}/#{video.version}_#{SecureRandom.hex}.#{input[:fileType].split('/').last}"

Aws.config.update({
region: 'us-east-2',
Expand Down
1 change: 1 addition & 0 deletions app/graphql/types/system_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

field :id, types.ID
field :name, types.String
field :organization, Types::OrganizationType
field :videos, types[Types::VideoType]
end
5 changes: 3 additions & 2 deletions app/policies/access_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ def configure
can :read_tutormakers, User
can :read_collection, Video
can :read_collection, Attachment
can [:cancel_video, :send_request], Video
can [:cancel_video, :send_request, :send_to_production, :cancel_request], Video
can [:read_comments, :video_attachments], Video
can [:post, :edit, :destroy], Comment
end

role :script_writer, user_role: 'script_writer' do
can :manage, Video
can :read_collection, Video
can [:cancel_video, :send_request, :send_to_production, :cancel_request], Video
can :assign, Video
can :read, Organization
can [:post, :edit, :destroy], Comment do |target_comment, current_user|
Expand All @@ -46,7 +47,7 @@ def configure
target_comment.video.source.organization_id == current_user.organization_id
end

can [:read_comments, :video_attachments], Video do |target_video, current_user|
can [:read, :update, :read_comments, :video_attachments], Video do |target_video, current_user|
current_user.video_ids.include?(target_video.id)
end
end
Expand Down
2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
User.create!(name: 'User script writer',email: '[email protected]' , password: '123123123' , password_confirmation: '123123123', user_role: :script_writer)
user = User.create!(name: 'User system admin',email: '[email protected]' , password: '123123123' , password_confirmation: '123123123', user_role: :system_admin, system_role_params: [{ first_system.id => 'admin'}], organization: organization)

video = Video.create(title: 'Default Video 1', system: first_system, created_by: user, url: 'https://media.w3.org/2010/05/sintel/trailer_hd.mp4')
video = Video.create(title: 'Default Video 1', system: first_system, created_by: user, url: 'https://s3.us-east-2.amazonaws.com/tutorbox-files/video/1/7_7c9f5c7863b70f2b27e1522cc681e195.quicktime')
Comment.create(video: video, author: user, comment_destination: 'administrative', body: 'Comment test')
Task.create(video: video, created_by: user, name: 'Improve ths video')
Attachment.create(source: video, source_type: Video, created_by: user, url: '/fake/url')
Expand Down

0 comments on commit 3b9bd36

Please sign in to comment.