Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Innovation day - Initial share project workflow #218

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
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 Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RUN gem install bundler \
&& apt-get update \
&& apt-get upgrade --yes \
&& apt-get install --yes --no-install-recommends \
libpq5 libxml2 libxslt1.1 \
libpq5 libxml2 libxslt1.1 libvips42 \
curl gnupg graphviz nodejs \
&& echo "deb http://apt.postgresql.org/pub/repos/apt bullseye-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
Expand Down
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '~> 3.2.0'

gem 'administrate', '~> 0.16.0'
gem 'administrate-field-active_storage'
gem 'aws-sdk-s3', require: false
gem 'bootsnap', require: false
gem 'cancancan', '~> 3.3'
Expand All @@ -14,6 +16,7 @@ gem 'globalid'
gem 'good_job', '~> 3.12'
gem 'graphql'
gem 'graphql-client'
gem 'image_processing'
gem 'importmap-rails'
gem 'jbuilder'
gem 'kaminari'
Expand All @@ -22,6 +25,10 @@ gem 'pg', '~> 1.1'
gem 'puma', '~> 5.6'
gem 'rack-cors'
gem 'rails', '~> 7.0.0'
gem 'omniauth-rails_csrf_protection', '~> 1.0.1'
gem 'omniauth-rpi',
github: 'RaspberryPiFoundation/omniauth-rpi',
tag: 'v1.3.1'
gem 'scout_apm'
gem 'sentry-rails', '~> 5.5.0'

Expand Down
81 changes: 81 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
GIT
remote: https://github.com/RaspberryPiFoundation/omniauth-rpi.git
revision: b7cb36cbfbf9a66f2376bb1501a4bdb205f2a7bf
tag: v1.3.1
specs:
omniauth-rpi (1.3.1)
jwt (~> 2.2.3)
omniauth (~> 2.0)
omniauth-oauth2 (~> 1.4)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -68,6 +78,19 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
administrate (0.16.0)
actionpack (>= 5.0)
actionview (>= 5.0)
activerecord (>= 5.0)
datetime_picker_rails (~> 0.0.7)
jquery-rails (>= 4.0)
kaminari (>= 1.0)
momentjs-rails (~> 2.8)
sassc-rails (~> 2.1)
selectize-rails (~> 0.6)
administrate-field-active_storage (1.0.1)
administrate (>= 0.2.2)
rails (>= 7.0)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.718.0)
Expand All @@ -85,6 +108,7 @@ GEM
aws-sigv4 (~> 1.4)
aws-sigv4 (1.5.2)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
bootsnap (1.16.0)
msgpack (~> 1.2)
builder (3.2.4)
Expand All @@ -100,6 +124,8 @@ GEM
rexml
crass (1.0.6)
date (3.3.3)
datetime_picker_rails (0.0.7)
momentjs-rails (>= 2.8.1)
diff-lcs (1.5.0)
docile (1.4.0)
dotenv (2.8.1)
Expand All @@ -120,6 +146,7 @@ GEM
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
ffi (1.16.3)
fugit (1.8.1)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
Expand All @@ -145,16 +172,25 @@ GEM
activesupport (>= 3.0)
graphql
hashdiff (1.0.1)
hashie (5.0.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
importmap-rails (1.1.5)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jmespath (1.6.2)
jquery-rails (4.6.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.6.3)
jwt (2.2.3)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
Expand All @@ -177,9 +213,13 @@ GEM
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mini_magick (4.12.0)
mini_mime (1.1.2)
minitest (5.17.0)
momentjs-rails (2.29.4.1)
railties (>= 3.1)
msgpack (1.6.0)
multi_xml (0.6.0)
net-imap (0.3.4)
date
net-protocol
Expand All @@ -196,6 +236,23 @@ GEM
racc (~> 1.4)
nokogiri (1.14.2-x86_64-linux)
racc (~> 1.4)
oauth2 (2.0.9)
faraday (>= 0.17.3, < 3.0)
jwt (>= 1.0, < 3.0)
multi_xml (~> 0.5)
rack (>= 1.2, < 4)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
omniauth (2.1.2)
hashie (>= 3.4.6)
rack (>= 2.2.3)
rack-protection
omniauth-oauth2 (1.8.0)
oauth2 (>= 1.4, < 3)
omniauth (~> 2.0)
omniauth-rails_csrf_protection (1.0.1)
actionpack (>= 4.2)
omniauth (~> 2.0)
open-uri (0.3.0)
stringio
time
Expand All @@ -218,6 +275,9 @@ GEM
rack (2.2.6.2)
rack-cors (2.0.0)
rack (>= 2.0.0)
rack-protection (3.2.0)
base64 (>= 0.1.0)
rack (~> 2.2, >= 2.2.4)
rack-test (2.0.2)
rack (>= 1.3)
rails (7.0.4.2)
Expand Down Expand Up @@ -297,9 +357,20 @@ GEM
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
ruby-progressbar (1.11.0)
ruby-vips (2.2.0)
ffi (~> 1.12)
ruby2_keywords (0.0.5)
sassc (2.4.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
scout_apm (5.3.5)
parser
selectize-rails (0.12.6)
sentry-rails (5.5.0)
railties (>= 5.0)
sentry-ruby (~> 5.5.0)
Expand All @@ -313,6 +384,9 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
sprockets (4.2.0)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
Expand All @@ -322,6 +396,7 @@ GEM
sprockets (>= 3.0.0)
stringio (3.0.5)
thor (1.2.1)
tilt (2.3.0)
time (0.2.1)
date
timeout (0.3.2)
Expand All @@ -330,6 +405,7 @@ GEM
unicode-display_width (2.4.2)
uniform_notifier (1.16.0)
uri (0.12.0)
version_gem (1.1.3)
webmock (3.18.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
Expand All @@ -346,6 +422,8 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
administrate (~> 0.16.0)
administrate-field-active_storage
aws-sdk-s3
bootsnap
bullet
Expand All @@ -361,9 +439,12 @@ DEPENDENCIES
graphiql-rails
graphql
graphql-client
image_processing
importmap-rails
jbuilder
kaminari
omniauth-rails_csrf_protection (~> 1.0.1)
omniauth-rpi!
open-uri
pg (~> 1.1)
pry-byebug
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project images are uploaded via `POST` requests to `/projects/{project_identfier

A project remix is created via a `POST` request to `projects/{original_project_identifier}/remix`.

A project share duplicates the original project, nulls the user_id and sets `is_live` to false via a `POST` request to `projects/{original_project_identifier}/share`.

### Requests from UI to API

Currently requests to the API from a specific project page are generally performed via `axios`, with `AsyncThunk`s being used to manage the status of such requests and update the UI accordingly.
Expand Down
1 change: 1 addition & 0 deletions app/assets/config/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
//= link_tree ../../../vendor/javascript .js
//= link graphiql/rails/application.css
//= link graphiql/rails/application.js
//= link administrate-field-active_storage/application.css
28 changes: 28 additions & 0 deletions app/controllers/admin/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# All Administrate controllers inherit from this
# `Administrate::ApplicationController`, making it the ideal place to put
# authentication logic or other before_actions.
#
# If you want to add pagination or other controller-level concerns,
# you're free to overwrite the RESTful controller actions.
module Admin
class ApplicationController < Administrate::ApplicationController
# include RpiAuth::Controllers::CurrentUser
include AuthenticationHelper
# include Identifiable

before_action :authenticate_admin

helper_method :current_user

def authenticate_admin
puts current_user.inspect
redirect_to '/', alert: 'Not authorized.' unless current_user&.admin?
end

# Override this value to specify the number of elements to display at a time
# on index pages. Defaults to 20.
# def records_per_page
# params[:per_page] || 20
# end
end
end
4 changes: 4 additions & 0 deletions app/controllers/admin/components_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Admin
class ComponentsController < Admin::ApplicationController
end
end
20 changes: 20 additions & 0 deletions app/controllers/admin/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Admin
class ProjectsController < Admin::ApplicationController
before_action :set_host_for_local_storage

def scoped_resource
resource_class.internal_projects
end

def destroy_image
image = requested_resource.images.find(params[:image_id])
image.purge
redirect_back(fallback_location: requested_resource)
end

private
def set_host_for_local_storage
ActiveStorage::Current.host = request.base_url if Rails.application.config.active_storage.service == :local
end
end
end
36 changes: 36 additions & 0 deletions app/controllers/api/projects/share_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Api
module Projects
class ShareController < ApiController
before_action :authorize_user

def create
result = Project::CreateShare.call(params: remix_params,
user_id: current_user,
original_project: project)

if result.success?
@project = result[:project]
render '/api/projects/show', formats: [:json]
else
render json: { error: result[:error] }, status: :bad_request
end
end

private

def project
@project ||= Project.find_by!(identifier: params[:project_id])
end

def remix_params
params.require(:project)
.permit(:name,
:identifier,
:locale,
components: %i[id name extension content index])
end
end
end
end
4 changes: 4 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
# include RpiAuth::Controllers::CurrentUser
include AuthenticationHelper
# include Identifiable
# helper_method :current_user
end
Loading