diff --git a/Gemfile b/Gemfile index 25aa0e0f..651450f6 100644 --- a/Gemfile +++ b/Gemfile @@ -25,6 +25,7 @@ gem 'addressable' gem 'kgio' gem 'carrierwave_direct' gem 'memcachier' +gem 'solid_use_case' group :development, :test do diff --git a/Gemfile.lock b/Gemfile.lock index 638ab507..0fa09be1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -67,6 +67,7 @@ GEM connection_pool (2.1.1) dalli (2.7.2) debug_inspector (0.0.2) + deterministic (0.6.0) dotenv (1.0.2) dotenv-rails (1.0.2) dotenv (= 1.0.2) @@ -262,6 +263,8 @@ GEM json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) slop (3.6.0) + solid_use_case (2.1.1) + deterministic (~> 0.6.0) spring (1.2.0) sprockets (2.12.3) hike (~> 1.2) @@ -321,6 +324,7 @@ DEPENDENCIES rails (= 4.2.0) sass-rails (~> 5.0) sdoc (~> 0.4.0) + solid_use_case spring sqlite3 turbolinks diff --git a/app/controllers/board_controller.rb b/app/controllers/board_controller.rb new file mode 100644 index 00000000..0d555305 --- /dev/null +++ b/app/controllers/board_controller.rb @@ -0,0 +1,10 @@ +class BoardController < ApplicationController + def index + UseCase::FetchBoard.new(huboard).run(params).match do + success do + @repo = gh.repos(params[:user],params[:repo]) + render :index, layout: "ember" + end + end + end +end diff --git a/app/controllers/marketing_controller.rb b/app/controllers/marketing_controller.rb index 2e6541af..a746d451 100644 --- a/app/controllers/marketing_controller.rb +++ b/app/controllers/marketing_controller.rb @@ -6,15 +6,13 @@ class MarketingController < ActionController::Base include ApplicationHelper def index - if logged_in? - render :index - else - render template: "marketing/marketing", layout: "marketing" - end + render template: "marketing/marketing", layout: "marketing" end + def integrations render template: "marketing/integrations", layout: "marketing" end + def pricing render template: "marketing/pricing", layout: "marketing" end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cbe49d9e..ca6525e0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -24,4 +24,7 @@ def huboard(token = nil) def gh huboard.connection end + def emojis + @emojis ||= gh.connection.get('./emojis').body + end end diff --git a/app/views/board/index.html.erb b/app/views/board/index.html.erb new file mode 100644 index 00000000..4c7c8eff --- /dev/null +++ b/app/views/board/index.html.erb @@ -0,0 +1,62 @@ +<% content_for :title do %> + <%= @repo['full_name'] %> +<% end %> +<% content_for :javascripts do %> + <% unless ENV["SOCKET_BACKEND"].nil? %> + + <% end %> + <%= javascript_include_tag 'board/application' %> + <%= javascript_include_tag 'bootstrap' %> + <%= javascript_include_tag 'vendor/jquery-ui' %> + +<% end %> diff --git a/app/views/layouts/ember.html.erb b/app/views/layouts/ember.html.erb new file mode 100644 index 00000000..b40ee668 --- /dev/null +++ b/app/views/layouts/ember.html.erb @@ -0,0 +1,32 @@ + + + + <%= content_for :title %>HuBoard + + + + + <%= stylesheet_link_tag 'bootstrap' %> + <%= stylesheet_link_tag 'flex_layout' %> + + + + +
+
+ <%= content_for :overlay %> + + <%= render partial: "shared/analytics" %> + + <%= content_for :javascripts %> + <%= render partial: "shared/fontdeck" %> + + + + + + + diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index d6c853ca..c78b91cb 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -8,4 +8,4 @@ # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. -Rails.application.config.assets.precompile += %w( marketing.js marketing/main.css vendor/jquery.js bootstrap.css bootstrap.js ) +Rails.application.config.assets.precompile += %w( flex_layout.css marketing.js marketing/main.css vendor/jquery.js bootstrap.css bootstrap.js board/application.js vendor/jquery-ui.js ) diff --git a/config/initializers/features.rb b/config/initializers/features.rb new file mode 100644 index 00000000..5628dc7a --- /dev/null +++ b/config/initializers/features.rb @@ -0,0 +1 @@ +Rails.application.config.client_environment = JSON.parse(File.read("#{Rails.root}/features.json")) diff --git a/config/initializers/socket_backend.rb b/config/initializers/socket_backend.rb new file mode 100644 index 00000000..f334dc41 --- /dev/null +++ b/config/initializers/socket_backend.rb @@ -0,0 +1,4 @@ +Rails.application.config.sockets = OpenStruct.new( + socket_backend: ENV["SOCKET_BACKEND"], +) + diff --git a/config/routes.rb b/config/routes.rb index ab40b8ee..71866cd4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,7 +13,8 @@ get '/repositories/public/:user' => 'dashboard#public', as: 'repositories_public' - get '/:user' => 'dashboard#user', as: 'user' + get '/:user' => 'dashboard#user', as: 'user' + get '/:user/:repo' => 'board#index', as: 'board' # The priority is based upon order of creation: first created -> highest priority. # See how all your routes lay out with "rake routes". diff --git a/features.json b/features.json new file mode 100644 index 00000000..fc4c98b0 --- /dev/null +++ b/features.json @@ -0,0 +1,5 @@ +{ + "FEATURES" : { + "IMAGE_UPLOADS": true + } +} diff --git a/lib/use_case/fetch_board.rb b/lib/use_case/fetch_board.rb new file mode 100644 index 00000000..48a7c444 --- /dev/null +++ b/lib/use_case/fetch_board.rb @@ -0,0 +1,41 @@ +module UseCase + class FetchBoard + include SolidUseCase + + attr_accessor :client + + def initialize(client) + @client = client + end + + steps :repo_exists?, :board_exists?, :issues_enabled? + + def repo_exists? params + board = client.board params[:user], params[:repo] + if board.repo_exists? + continue board + else + fail :not_found + end + + end + + def board_exists?(board) + if board.has_board? + continue board + else + fail :no_board + end + end + + def issues_enabled?(board) + if board.issues_enabled? + continue board + else + fail :no_issues + end + + end + + end +end diff --git a/lib/use_case/private_repo.rb b/lib/use_case/private_repo.rb new file mode 100644 index 00000000..ba074d68 --- /dev/null +++ b/lib/use_case/private_repo.rb @@ -0,0 +1,57 @@ +require "app/account_helpers" + +module UseCase + class PrivateRepo + include HuBoard::AccountHelpers + include SolidUseCase + + attr_accessor :couch, :gh + def initialize(gh, couch) + @gh = gh + @couch = couch + end + + steps :an_account_exists?, :a_trial_available?, :has_subscription? + + def an_account_exists?(params) + @repo_owner ||= @gh.users(params[:user]) + + plan_doc = QueryHandler.run do |q| + q << Queries::CouchCustomer.get(@repo_owner["id"], @couch) + q << Queries::PassThrough.go + end + return fail(:pass_through) if plan_doc[:pass_through] + + @customer = account_exists?(plan_doc) ? plan_doc[:rows].first.value : false + continue(params) + end + + def a_trial_available?(params) + if trial_available?(@customer) && user_is_owner(params) + params[:trial_available] = true + continue(params) + else + continue(params) + end + end + + def has_subscription?(params) + return continue(params) if params[:trial_available] || trial_active?(@customer) + if @customer && subscription_active?(@customer) + return continue(params) + end + return fail :unauthorized + end + + :private + def user_is_owner(params) + if @repo_owner["type"] == "Organization" + @u ||= @gh.orgs(@repo_owner["login"]).memberships(@gh.user["login"]) do |req| + req.headers["Accept"] = "application/vnd.github.moondragon+json" + end + return @u["role"] == "admin" + end + @repo_owner['login'] == @gh.user['login'] + end + end +end