From 5dfd0d1a355175351a408c87824bce618946eae0 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 12 Feb 2014 19:37:40 +0800 Subject: [PATCH 01/10] new type frontend for faq --- app/controllers/default_widget_controller.rb | 4 + app/views/admin/pages/_default_front.html.erb | 7 ++ app/views/default_widget/_typeD.html.erb | 91 +++++++++++++++++++ built_in_extensions.rb | 1 + 4 files changed, 103 insertions(+) create mode 100644 app/views/default_widget/_typeD.html.erb diff --git a/app/controllers/default_widget_controller.rb b/app/controllers/default_widget_controller.rb index 1f9e1d9..332e19b 100644 --- a/app/controllers/default_widget_controller.rb +++ b/app/controllers/default_widget_controller.rb @@ -58,6 +58,7 @@ class DefaultWidgetController< OrbitWidgetController @frontend_field_names = @page_part.frontend_field_name @frontend_classes = @page_part.frontend_class @frontend_sat_to_links = @page_part.frontend_sat_to_link + @widget_title = @page_part.title_translations[I18n.locale.to_s] @data_limit = @page_part.frontend_data_count.is_a?(Fixnum) ? @page_part.frontend_data_count : (@page_part.frontend_data_count.to_i rescue 3) @paginate = true @@ -95,6 +96,9 @@ class DefaultWidgetController< OrbitWidgetController when "typeC" @tag_class = 'default_widget_typeC' @partial = "typeC" + when "typeD" + @tag_class = 'default_widget_typeC' + @partial = "typeD" end end end diff --git a/app/views/admin/pages/_default_front.html.erb b/app/views/admin/pages/_default_front.html.erb index 4481ec6..7ea505c 100644 --- a/app/views/admin/pages/_default_front.html.erb +++ b/app/views/admin/pages/_default_front.html.erb @@ -35,6 +35,13 @@ <%= t("default_widget.caption.typeC") %> <% end %> + <% if @enabled_styles.include?("typeD") %> +
  • + <%= radio_button_tag "page[frontend_style]", "typeD", @checked_style ? @checked_style.eql?("typeD") : false, class: "d-theme" %> + <%= image_tag 'module/default_widgets/style05.png'%> + <%= t("default_widget.caption.typeD") %> +
  • + <% end %> diff --git a/app/views/default_widget/_typeD.html.erb b/app/views/default_widget/_typeD.html.erb new file mode 100644 index 0000000..4b64235 --- /dev/null +++ b/app/views/default_widget/_typeD.html.erb @@ -0,0 +1,91 @@ +
    + <% @data.each do |row_data| %> +
    +
    + <% @frontend_field_names.each_with_index do |field,index| %> + <% if index == 0 %> + + <%= link_to_field(row_data,field, @frontend_sat_to_links[index],{orig_page: @page_id.to_s}) unless field.blank? %> + + <% else %> + <%= row_data.title %> + <% end %> + <% end %> +
    + +
    +<% end %> +
    + + \ No newline at end of file diff --git a/built_in_extensions.rb b/built_in_extensions.rb index a235a14..a176aac 100644 --- a/built_in_extensions.rb +++ b/built_in_extensions.rb @@ -15,3 +15,4 @@ gem 'personal_patent', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit- gem 'personal_project', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personalproject.git' gem 'personal_research', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personalresearch.git' gem 'web_resource', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-webresource.git' +gem 'faq', '0.0.1', :path => '/Users/H4RRY/github/modules/orbit-faq' \ No newline at end of file From 38124e41b53ff2b050143b3e4d8fd30cd658fb04 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 13 Feb 2014 12:02:36 +0800 Subject: [PATCH 02/10] removed faq from built in extensions --- built_in_extensions.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/built_in_extensions.rb b/built_in_extensions.rb index a176aac..10b154c 100644 --- a/built_in_extensions.rb +++ b/built_in_extensions.rb @@ -14,5 +14,4 @@ gem 'personal_lab', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-per gem 'personal_patent', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personalpatent.git' gem 'personal_project', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personalproject.git' gem 'personal_research', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-personalresearch.git' -gem 'web_resource', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-webresource.git' -gem 'faq', '0.0.1', :path => '/Users/H4RRY/github/modules/orbit-faq' \ No newline at end of file +gem 'web_resource', '0.0.1', :git => 'git@gitlab.tp.rulingcom.com:root/orbit-webresource.git' \ No newline at end of file From f308b8a34c93bb70dedc1bad35704de34f7f293d Mon Sep 17 00:00:00 2001 From: Spen Date: Thu, 13 Feb 2014 16:13:54 +0800 Subject: [PATCH 03/10] Fix approval issue --- app/controllers/orbit_backend_controller.rb | 1 + app/helpers/orbit_backend_helper.rb | 6 +++--- app/models/module_app.rb | 1 + config/locales/en.yml | 6 ++++++ config/locales/zh_tw.yml | 3 +++ lib/orbit_core_lib.rb | 2 +- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index 3a6a759..2759089 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -1,6 +1,7 @@ class OrbitBackendController < ApplicationController include OrbitCategory::Categorizing include OrbitCoreLib::Authorization + include OrbitCoreLib::PermissionUtility include OrbitTag::Tagging include AdminHelper include ApplicationHelper diff --git a/app/helpers/orbit_backend_helper.rb b/app/helpers/orbit_backend_helper.rb index ba2a87e..c946456 100644 --- a/app/helpers/orbit_backend_helper.rb +++ b/app/helpers/orbit_backend_helper.rb @@ -12,13 +12,13 @@ module OrbitBackendHelper def show_form_status_field(object) #by_object = (!object.is_expired? and object.is_pending?) - by_user = ((object.category.authed_users("approval_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin? or is_sub_manager?) + by_user = ((object.category.user_is_authorized_by_title?(current_user,"category_approval_#{@module_app.key}") rescue nil) or is_manager? or is_admin?) by_user end def show_approval_link(object) by_object = (!object.is_expired? and object.is_pending?) - by_user = ((object.category.authed_users("approval_#{@module_app.key}").include?(current_user) rescue nil) or is_manager? or is_admin? or is_sub_manager?) + by_user = ((object.category.user_is_authorized_by_title?(current_user,"category_approval_#{@module_app.key}") rescue nil) or is_manager? or is_admin?) by_object and by_user end @@ -306,7 +306,7 @@ module OrbitBackendHelper content_tag :li, link_to(t(quick[:translation] || :authorization_), eval("#{quick[:link]}"), class: "preview_trigger #{quick[:class]}") end when 'edit' - if authorization && approvable + if authorization && approvable || is_manager? content_tag :li, link_to(t(quick[:translation] || :edit), quick[:link].nil? ? '#' : eval("#{quick[:link]}('#{object.id}'#{link_option})"), class: quick[:class], data: eval("#{quick[:data]}")) end when 'delete' diff --git a/app/models/module_app.rb b/app/models/module_app.rb index 61673ec..9a5cb37 100644 --- a/app/models/module_app.rb +++ b/app/models/module_app.rb @@ -194,6 +194,7 @@ class ModuleApp # authorization def update_auth_approval_users user_ids = self.auth_approvals.inject([]) do |users, auth| + auth = auth.class.find(auth.id) users += auth.authorized_users.map{|user| user.id} end self.update_attribute(:auth_approval_users, user_ids.uniq) diff --git a/config/locales/en.yml b/config/locales/en.yml index c433e63..4ce4512 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -229,11 +229,13 @@ en: groups: Groups help: Help hidden: Hidden + is_hidden: Hidden hide: Hide hits: Hits homepage: Homepage horizontal: Horizontal hot: Hot + is_hot: Hot image: Image images: Images info: Information @@ -352,11 +354,13 @@ en: public_r_tag: System Widget text: Text Area passed: Approved + is_checked: Approved password: Password password_change: Change password password_confirmation: Password confirmation password_current: Current password pending: Pending + is_pending: Pending personal_plugins: author : "Author" edit_brief_intro : "Edit Brief Intro." @@ -400,6 +404,7 @@ en: register: Register registered: Registered rejected: Rejected + is_rejected: Rejected rejected_reason: 'Reason:' rejected_reason_empty: "Approval rejected, no referencable information" related_links: Related Links @@ -527,6 +532,7 @@ en: to_search: Set as Search Key to_show: Display in frontend top: Top + is_top: Top total_visitors: Total Visitors traffic: Traffic type: Field Type diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index b412f5f..69682d2 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -355,11 +355,13 @@ zh_tw: public_r_tag: 系統模塊 text: 文字區域 passed: 通過審核 + is_checked: 通過審核 password: 密碼 password_change: 更改密碼 password_confirmation: 確認密碼 password_current: 目前的密碼 pending: 待審核 + is_pending: 待審核 personal_plugins: author : "著作人" edit_brief_intro : "編輯摘要" @@ -402,6 +404,7 @@ zh_tw: register: 註冊 registered: 已註冊 rejected: 拒絕 + is_rejected: 拒絕 rejected_reason: 拒絕原因:' rejected_reason_empty: "拒絕核准, 沒有參考資訊" related_links: 相關連結 diff --git a/lib/orbit_core_lib.rb b/lib/orbit_core_lib.rb index b44b32e..e0c5f6e 100644 --- a/lib/orbit_core_lib.rb +++ b/lib/orbit_core_lib.rb @@ -234,7 +234,7 @@ module OrbitCoreLib when :sub_manager @open ||= check_sub_manager when :approver - @open ||= check_sub_manager + @open ||= check_approver when :user @open ||= true when :visitor From 66ebd5e62220a16effb1c062d82749f0326d4132 Mon Sep 17 00:00:00 2001 From: Manson Wang Date: Thu, 13 Feb 2014 17:28:12 +0800 Subject: [PATCH 04/10] Fix Resque "Internal Server Error" issue in pushion passenger forked environment --- config/initializers/redis.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 config/initializers/redis.rb diff --git a/config/initializers/redis.rb b/config/initializers/redis.rb new file mode 100644 index 0000000..c77dfe9 --- /dev/null +++ b/config/initializers/redis.rb @@ -0,0 +1,11 @@ +if defined?(PhusionPassenger) + PhusionPassenger.on_event(:starting_worker_process) do |forked| + if forked + Resque.redis.client.disconnect + Resque.redis = Redis.new(:host => 'localhost', :port => 6379) + Resque.redis.namespace = Site.first.resque_namespace rescue APP_CONFIG['orbit'] + else + # We're in conservative spawning mode. We don't need to do anything. + end + end +end \ No newline at end of file From 702b46f416d99bb110601859478265b6cf74752a Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Tue, 11 Feb 2014 18:14:45 +0800 Subject: [PATCH 05/10] Add API Authorization --- .../admin/omniauth_callbacks_controller.rb | 10 +++++++ app/controllers/admin/sites_controller.rb | 7 +++++ app/controllers/application_controller.rb | 9 +++++++ app/models/site.rb | 12 +++++++-- config/store_config.yml | 1 + lib/omniauth/strategies/doorkeeper.rb | 26 +++++++++++++++++++ lib/store.rb | 9 +++++++ 7 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 app/controllers/admin/omniauth_callbacks_controller.rb create mode 100644 lib/omniauth/strategies/doorkeeper.rb create mode 100644 lib/store.rb diff --git a/app/controllers/admin/omniauth_callbacks_controller.rb b/app/controllers/admin/omniauth_callbacks_controller.rb new file mode 100644 index 0000000..f034740 --- /dev/null +++ b/app/controllers/admin/omniauth_callbacks_controller.rb @@ -0,0 +1,10 @@ +class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController + def doorkeeper + oauth_data = request.env["omniauth.auth"] + @user = User.find_or_create_for_doorkeeper_oauth(oauth_data) + @user.update_doorkeeper_credentials(oauth_data) + @user.save + + sign_in_and_redirect @user + end +end \ No newline at end of file diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 2e492dd..31ed337 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -147,6 +147,13 @@ class Admin::SitesController < OrbitBackendController render :text => "success" end + def generate_site_token + begin + self.site_token = SecureRandom.uuid.gsub('-','') + self.save + end + end + protected def update_design(design) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c8fcfe2..f44590e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -479,4 +479,13 @@ class ApplicationController < ActionController::Base end end + def check_central_server_connection + site = Site.first + if site.site_token? + flash[:notice]="Connected to the Store" + else + flash[:notice]="To Access the Store Please Connect It" + end + end + end diff --git a/app/models/site.rb b/app/models/site.rb index a37cbbb..f1de713 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -46,14 +46,15 @@ class Site field :address field :phone_number, :type => Array,:default=>[] field :mobile_bar_color, :type => Array, :default=>[] - - + field :site_token field :mobile_on, :type => Boolean, :default => false belongs_to :design has_many :site_metas, :autosave => true, :dependent => :destroy validate :in_use_locales, :minimum_enabled_locales + index({ access_token: 1}, { unique: true }) + def minimum_enabled_locales size = self.in_use_locales.length if size < 1 @@ -95,5 +96,12 @@ class Site fetch_meta.save end end + + def generate_site_token + begin + self.site_token = SecureRandom.uuid.gsub('-','') + self.save + end + end end diff --git a/config/store_config.yml b/config/store_config.yml index cd0fd3b..def0151 100644 --- a/config/store_config.yml +++ b/config/store_config.yml @@ -1,2 +1,3 @@ store_settings: url: "http://store.tp.rulingcom.com" + api_key: "cc6ae8d0aa0a730792cf519225c40099" diff --git a/lib/omniauth/strategies/doorkeeper.rb b/lib/omniauth/strategies/doorkeeper.rb new file mode 100644 index 0000000..16bdb93 --- /dev/null +++ b/lib/omniauth/strategies/doorkeeper.rb @@ -0,0 +1,26 @@ +module OmniAuth + module Strategies + class Doorkeeper < OmniAuth::Strategies::OAuth2 + option :name, :doorkeeper + + option :client_options, { + :site => "http://localhost:8000", + :authorize_path => "/oauth/authorize" + } + + uid do + raw_info["id"] + end + + info do + { + :email => raw_info["email"] + } + end + + def raw_info + @raw_info ||= access_token.get('/api/v1/me.json').parsed + end + end + end +end \ No newline at end of file diff --git a/lib/store.rb b/lib/store.rb new file mode 100644 index 0000000..773454c --- /dev/null +++ b/lib/store.rb @@ -0,0 +1,9 @@ +class Store + include HTTParty + base_uri 'http://localhost:3000' + + def post(text) + options = { :body => {:status => text}, :token => @auth } + self.class.post('/api/clients', options) + end +end \ No newline at end of file From e76d177ff8accc9c7a04942ab5430a067e9e5489 Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Fri, 14 Feb 2014 14:38:28 +0800 Subject: [PATCH 06/10] Site Registration - some finishing required --- Gemfile | 2 +- .../admin/module_store_controller.rb | 6 +-- .../admin/register_site_controller.rb | 10 +++++ app/controllers/admin/sites_controller.rb | 7 ---- app/controllers/application_controller.rb | 4 +- app/models/site.rb | 9 +++- app/views/admin/register_site/index.html.erb | 1 + config/routes.rb | 7 ++++ config/store_config.yml | 4 +- lib/store.rb | 42 ++++++++++++++++--- 10 files changed, 71 insertions(+), 21 deletions(-) create mode 100644 app/controllers/admin/register_site_controller.rb create mode 100644 app/views/admin/register_site/index.html.erb diff --git a/Gemfile b/Gemfile index d2d88c5..0876fbc 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,7 @@ gem "acts_as_unvlogable" gem 'youtube_it' gem 'gotcha' gem "geocoder" - +gem 'httparty' #database gem 'mini_magick' gem 'mongoid', '> 2.1', '< 3.0.0' diff --git a/app/controllers/admin/module_store_controller.rb b/app/controllers/admin/module_store_controller.rb index 8c5674d..7eda752 100644 --- a/app/controllers/admin/module_store_controller.rb +++ b/app/controllers/admin/module_store_controller.rb @@ -1,5 +1,5 @@ class Admin::ModuleStoreController < OrbitBackendController - + before_filter :check_central_server_connection @@store = STORE_CONFIG[:store_settings]["url"] def index @@ -85,7 +85,7 @@ class Admin::ModuleStoreController < OrbitBackendController protected def get_extensions - extensions = JSON.parse(open("#{@@store}/api/extensions").read) + extensions = JSON.parse(open("#{@@store}/extensions").read) exist_exts = [] ext_file = File.new("#{Rails.root}/downloaded_extensions.rb", "r") @@ -112,7 +112,7 @@ class Admin::ModuleStoreController < OrbitBackendController end def get_extension(id) - JSON.parse(open("#{@@store}/api/extensions/#{id}").read) + JSON.parse(open("#{@@store}/extensions/#{id}").read) end def get_downloaded_extension diff --git a/app/controllers/admin/register_site_controller.rb b/app/controllers/admin/register_site_controller.rb new file mode 100644 index 0000000..7736d56 --- /dev/null +++ b/app/controllers/admin/register_site_controller.rb @@ -0,0 +1,10 @@ +class Admin::RegisterSiteController < OrbitBackendController + def index + end + + def register_site + site = Site.first + site.register_site + redirect_to admin_module_store_path + end +end \ No newline at end of file diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 31ed337..2e492dd 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -147,13 +147,6 @@ class Admin::SitesController < OrbitBackendController render :text => "success" end - def generate_site_token - begin - self.site_token = SecureRandom.uuid.gsub('-','') - self.save - end - end - protected def update_design(design) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f44590e..9f5fa92 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -480,10 +480,10 @@ class ApplicationController < ActionController::Base end def check_central_server_connection - site = Site.first - if site.site_token? + if @site.site_token? flash[:notice]="Connected to the Store" else + redirect_to admin_register_site_index_path flash[:notice]="To Access the Store Please Connect It" end end diff --git a/app/models/site.rb b/app/models/site.rb index f1de713..d1cfe57 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -98,10 +98,17 @@ class Site end def generate_site_token - begin + if self.site_token.nil? self.site_token = SecureRandom.uuid.gsub('-','') self.save end end + + def register_site + api_key = STORE_CONFIG[:store_settings]["api_key"] + self.generate_site_token + store = Store.new(self.id.to_s,self.site_token,api_key) + store.post_client(self.id.to_s,self.site_token,self.name) + end end diff --git a/app/views/admin/register_site/index.html.erb b/app/views/admin/register_site/index.html.erb new file mode 100644 index 0000000..cd8907f --- /dev/null +++ b/app/views/admin/register_site/index.html.erb @@ -0,0 +1 @@ +<%= link_to "Register", register_site_admin_register_site_index_path, :class => "btn btn-primary"%> diff --git a/config/routes.rb b/config/routes.rb index 573e814..bbfc832 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -220,6 +220,7 @@ Orbit::Application.routes.draw do get 'update_orbit' get 'restart_server' end + match 'sites/register_site' => "sites#register_site" resources :tags do collection do @@ -271,6 +272,12 @@ Orbit::Application.routes.draw do match 'template_store' => 'template_store#index' match 'template_store/download_theme' => "template_store#download_theme" match 'template_store/template/:id' => 'template_store#show', :as => :template_store_template + + resources :register_site, only: [:index] do + collection do + post 'register_site' + end + end # match 'template_store/cool_method' => "template_store#cool_method" end diff --git a/config/store_config.yml b/config/store_config.yml index def0151..a56920b 100644 --- a/config/store_config.yml +++ b/config/store_config.yml @@ -1,3 +1,3 @@ store_settings: - url: "http://store.tp.rulingcom.com" - api_key: "cc6ae8d0aa0a730792cf519225c40099" + url: "http://192.168.1.250:3000/api" + api_key: 'Token token="b38ba5f588a7c5072e88ee15737a4d33"' diff --git a/lib/store.rb b/lib/store.rb index 773454c..57a9f9a 100644 --- a/lib/store.rb +++ b/lib/store.rb @@ -1,9 +1,41 @@ +require 'httparty' class Store include HTTParty - base_uri 'http://localhost:3000' - def post(text) - options = { :body => {:status => text}, :token => @auth } - self.class.post('/api/clients', options) - end + format :json + base_uri STORE_CONFIG[:store_settings]["url"] + + def initialize(site_id,site_token,api_key) + @options_for_get = { + headers: { + "Authorization" => api_key, + "X_SiteToken" => site_token, + "X_SiteId" => site_id, + "Content-Type" => "application/json" + } + } + + @options_for_client = { + headers: { + "Authorization" => api_key, + "Content-Type" => "application/json" + } + } + end + + def templates(options={}) + options = @options_for_get + response = self.class.get('/templates', options) + puts response.request.last_uri.to_s + end + + def extensions(options={}) + options = @options_for_get + self.class.get('/extensions', options) + end + + def post_client(site_id,site_token,site_name) + options = @options_for_client.merge({ :body => {:site_name => site_name, :site_id => site_id, :site_token => site_token}.to_json }) + self.class.post('/clients', options ) + end end \ No newline at end of file From 5d6319dfcc78079b06cd6072aa37e84e80581fdb Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Fri, 14 Feb 2014 16:57:05 +0800 Subject: [PATCH 07/10] Updated Store headers to work with nginx --- config/store_config.yml | 4 ++-- lib/store.rb | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/config/store_config.yml b/config/store_config.yml index a56920b..f591dc0 100644 --- a/config/store_config.yml +++ b/config/store_config.yml @@ -1,3 +1,3 @@ store_settings: - url: "http://192.168.1.250:3000/api" - api_key: 'Token token="b38ba5f588a7c5072e88ee15737a4d33"' + url: "http://store.tp.rulingcom.com/api" + api_key: 'Token token="2870f77e59168dbe3fbdffba466c7c8d"' diff --git a/lib/store.rb b/lib/store.rb index 57a9f9a..a7db8b7 100644 --- a/lib/store.rb +++ b/lib/store.rb @@ -9,24 +9,25 @@ class Store @options_for_get = { headers: { "Authorization" => api_key, - "X_SiteToken" => site_token, - "X_SiteId" => site_id, - "Content-Type" => "application/json" + "X-SiteToken" => site_token, + "X-SiteId" => site_id, + "Content-Type" => "application/json", + 'Accept' => 'application/json' } } @options_for_client = { headers: { "Authorization" => api_key, - "Content-Type" => "application/json" + "Content-Type" => "application/json", + 'Accept' => 'application/json' } } end def templates(options={}) options = @options_for_get - response = self.class.get('/templates', options) - puts response.request.last_uri.to_s + self.class.get('/templates', options) end def extensions(options={}) From ce5b35239fbefd71b8b45786f5345b0baadd9bd5 Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Fri, 14 Feb 2014 17:18:47 +0800 Subject: [PATCH 08/10] removed register site controller --- app/controllers/admin/register_site_controller.rb | 10 ---------- app/controllers/admin/sites_controller.rb | 5 +++++ app/views/admin/register_site/index.html.erb | 1 - config/routes.rb | 6 ------ 4 files changed, 5 insertions(+), 17 deletions(-) delete mode 100644 app/controllers/admin/register_site_controller.rb delete mode 100644 app/views/admin/register_site/index.html.erb diff --git a/app/controllers/admin/register_site_controller.rb b/app/controllers/admin/register_site_controller.rb deleted file mode 100644 index 7736d56..0000000 --- a/app/controllers/admin/register_site_controller.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Admin::RegisterSiteController < OrbitBackendController - def index - end - - def register_site - site = Site.first - site.register_site - redirect_to admin_module_store_path - end -end \ No newline at end of file diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 2e492dd..a3b3384 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -147,6 +147,11 @@ class Admin::SitesController < OrbitBackendController render :text => "success" end + def register_site + @site.register_site + redirect_to admin_module_store_path + end + protected def update_design(design) diff --git a/app/views/admin/register_site/index.html.erb b/app/views/admin/register_site/index.html.erb deleted file mode 100644 index cd8907f..0000000 --- a/app/views/admin/register_site/index.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= link_to "Register", register_site_admin_register_site_index_path, :class => "btn btn-primary"%> diff --git a/config/routes.rb b/config/routes.rb index bbfc832..af22d24 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -272,12 +272,6 @@ Orbit::Application.routes.draw do match 'template_store' => 'template_store#index' match 'template_store/download_theme' => "template_store#download_theme" match 'template_store/template/:id' => 'template_store#show', :as => :template_store_template - - resources :register_site, only: [:index] do - collection do - post 'register_site' - end - end # match 'template_store/cool_method' => "template_store#cool_method" end From bf532bfea98865f245cf47715e2be55825e7e5c8 Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Fri, 14 Feb 2014 20:06:32 +0800 Subject: [PATCH 09/10] Fixed Store for templates and modules --- .../admin/module_store_controller.rb | 12 ++++++-- .../admin/template_store_controller.rb | 30 ++++++++++--------- app/controllers/application_controller.rb | 5 ++++ app/views/admin/module_store/index.html.erb | 1 - .../admin/template_store/_template.html.erb | 2 +- app/views/admin/template_store/index.html.erb | 1 + app/views/admin/template_store/show.html.erb | 2 +- config/store_config.yml | 3 +- lib/store.rb | 12 +++++++- 9 files changed, 46 insertions(+), 22 deletions(-) diff --git a/app/controllers/admin/module_store_controller.rb b/app/controllers/admin/module_store_controller.rb index 7eda752..c07f9ec 100644 --- a/app/controllers/admin/module_store_controller.rb +++ b/app/controllers/admin/module_store_controller.rb @@ -1,5 +1,5 @@ class Admin::ModuleStoreController < OrbitBackendController - before_filter :check_central_server_connection + before_filter :check_central_server_connection, :only => [:get_extensions] @@store = STORE_CONFIG[:store_settings]["url"] def index @@ -85,7 +85,7 @@ class Admin::ModuleStoreController < OrbitBackendController protected def get_extensions - extensions = JSON.parse(open("#{@@store}/extensions").read) + extensions = store_session.extensions exist_exts = [] ext_file = File.new("#{Rails.root}/downloaded_extensions.rb", "r") @@ -112,7 +112,7 @@ class Admin::ModuleStoreController < OrbitBackendController end def get_extension(id) - JSON.parse(open("#{@@store}/extensions/#{id}").read) + store_session.get_extension(id) end def get_downloaded_extension @@ -142,4 +142,10 @@ class Admin::ModuleStoreController < OrbitBackendController end end + private + + def get_site + @site ||= Site.first + end + end \ No newline at end of file diff --git a/app/controllers/admin/template_store_controller.rb b/app/controllers/admin/template_store_controller.rb index 5f2344c..e001bce 100644 --- a/app/controllers/admin/template_store_controller.rb +++ b/app/controllers/admin/template_store_controller.rb @@ -3,20 +3,20 @@ require 'uri' require 'fileutils' require 'zip/zip' class Admin::TemplateStoreController < OrbitBackendController - + before_filter :check_central_server_connection, :only => [:get_extensions] @@store_domain = STORE_CONFIG[:store_settings]["url"] def index - @store = @@store_domain + @store_url = @@store_domain @design_ids = Design.all.map{|d| d.template_store_id} - @templates = JSON.parse(get_templates) + @templates = get_templates.parsed_response render :layout => false end def show @store = @@store_domain @design_ids = Design.all.map{|d| d.template_store_id} - @template = JSON.parse(get_template(params[:id])) rescue nil + @template = get_template(params[:id]).parsed_response rescue nil end def download_theme @@ -92,19 +92,21 @@ class Admin::TemplateStoreController < OrbitBackendController end def get_template(id) - uri = URI.parse("#{@@store_domain}/api/templates/#{id}") - http = Net::HTTP.new(uri.host, uri.port) - request = Net::HTTP::Get.new(uri.request_uri) - response = http.request(request) - response.body + store_session.get_template(id) + # uri = URI.parse("#{@@store_domain}/api/templates/#{id}") + # http = Net::HTTP.new(uri.host, uri.port) + # request = Net::HTTP::Get.new(uri.request_uri) + # response = http.request(request) + # response.body end def get_templates - uri = URI.parse("#{@@store_domain}/api/templates") - http = Net::HTTP.new(uri.host, uri.port) - request = Net::HTTP::Get.new(uri.request_uri) - response = http.request(request) - response.body + extensions = store_session.templates + # uri = URI.parse("#{@@store_domain}/api/templates") + # http = Net::HTTP.new(uri.host, uri.port) + # request = Net::HTTP::Get.new(uri.request_uri) + # response = http.request(request) + # response.body end end \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9f5fa92..98618ef 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -488,4 +488,9 @@ class ApplicationController < ActionController::Base end end + def store_session + api_key = STORE_CONFIG[:store_settings]["api_key"] + @store = Store.new(@site.id.to_s,@site.site_token,api_key) if @site.site_token + end + end diff --git a/app/views/admin/module_store/index.html.erb b/app/views/admin/module_store/index.html.erb index 2272c26..d9d10eb 100644 --- a/app/views/admin/module_store/index.html.erb +++ b/app/views/admin/module_store/index.html.erb @@ -184,7 +184,6 @@
    <%= t(:module_store) %>
    -
    diff --git a/app/views/admin/template_store/_template.html.erb b/app/views/admin/template_store/_template.html.erb index 970e138..bbeaa25 100644 --- a/app/views/admin/template_store/_template.html.erb +++ b/app/views/admin/template_store/_template.html.erb @@ -1,7 +1,7 @@ + <%= render :partial => 'template', :collection => @templates %> diff --git a/app/views/admin/template_store/show.html.erb b/app/views/admin/template_store/show.html.erb index c730b85..fd13d80 100644 --- a/app/views/admin/template_store/show.html.erb +++ b/app/views/admin/template_store/show.html.erb @@ -6,7 +6,7 @@
    - <%= image_tag "#{@store}#{@template['preview']['preview']['thumb']['url']}", :class => "item-thumb" %> + <%= image_tag "#{@store_url}/#{@template['preview']['preview']['thumb']['url']}", :class => "item-thumb" %>

    <%= @template['title'] %>

    <% if @design_ids.include?(@template["_id"]["$oid"]) %> <%= link_to "Installed", "javascript:void(0);", "data-url" => @template['template']['template']['url'], :class=> 'btn btn-success download-link', "disabled"=>"disabled", "data-name"=>@template['title'], "data-slug"=>@template["_slugs"][0], "data-id"=>@template["_id"]["$oid"] %> diff --git a/config/store_config.yml b/config/store_config.yml index f591dc0..e086195 100644 --- a/config/store_config.yml +++ b/config/store_config.yml @@ -1,3 +1,4 @@ store_settings: - url: "http://store.tp.rulingcom.com/api" + url: "http://store.tp.rulingcom.com" + api_url: "http://store.tp.rulingcom.com/api" api_key: 'Token token="2870f77e59168dbe3fbdffba466c7c8d"' diff --git a/lib/store.rb b/lib/store.rb index a7db8b7..3d8e400 100644 --- a/lib/store.rb +++ b/lib/store.rb @@ -3,7 +3,7 @@ class Store include HTTParty format :json - base_uri STORE_CONFIG[:store_settings]["url"] + base_uri STORE_CONFIG[:store_settings]["api_url"] def initialize(site_id,site_token,api_key) @options_for_get = { @@ -30,11 +30,21 @@ class Store self.class.get('/templates', options) end + def get_template(id) + options = @options_for_get + self.class.get("/templates/#{id}", options) + end + def extensions(options={}) options = @options_for_get self.class.get('/extensions', options) end + def get_extension(id) + options = @options_for_get + self.class.get("/extensions/#{id}", options) + end + def post_client(site_id,site_token,site_name) options = @options_for_client.merge({ :body => {:site_name => site_name, :site_id => site_id, :site_token => site_token}.to_json }) self.class.post('/clients', options ) From b47bd031f2f2a614770c882246d9177704507553 Mon Sep 17 00:00:00 2001 From: Saurabh Bhatia Date: Mon, 17 Feb 2014 11:33:18 +0800 Subject: [PATCH 10/10] some refactoring of store url object --- .../admin/module_store_controller.rb | 1 - .../admin/template_store_controller.rb | 28 +++++++------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/controllers/admin/module_store_controller.rb b/app/controllers/admin/module_store_controller.rb index c07f9ec..ced1adf 100644 --- a/app/controllers/admin/module_store_controller.rb +++ b/app/controllers/admin/module_store_controller.rb @@ -1,6 +1,5 @@ class Admin::ModuleStoreController < OrbitBackendController before_filter :check_central_server_connection, :only => [:get_extensions] - @@store = STORE_CONFIG[:store_settings]["url"] def index @extensions = get_extensions diff --git a/app/controllers/admin/template_store_controller.rb b/app/controllers/admin/template_store_controller.rb index e001bce..299b96c 100644 --- a/app/controllers/admin/template_store_controller.rb +++ b/app/controllers/admin/template_store_controller.rb @@ -3,24 +3,22 @@ require 'uri' require 'fileutils' require 'zip/zip' class Admin::TemplateStoreController < OrbitBackendController - before_filter :check_central_server_connection, :only => [:get_extensions] + before_filter :check_central_server_connection, :only => [:get_templates] + before_filter :set_store - @@store_domain = STORE_CONFIG[:store_settings]["url"] def index - @store_url = @@store_domain @design_ids = Design.all.map{|d| d.template_store_id} @templates = get_templates.parsed_response render :layout => false end def show - @store = @@store_domain - @design_ids = Design.all.map{|d| d.template_store_id} + @design_ids = Design.all.map{|d| d.template_store_id} @template = get_template(params[:id]).parsed_response rescue nil end def download_theme - url = @@store_domain + params["url"] + url = @store_url + params["url"] url_base = url.split('/')[2] url_path = '/'+url.split('/')[3..-1].join('/') Net::HTTP.start(url_base) do |http| @@ -32,7 +30,7 @@ class Admin::TemplateStoreController < OrbitBackendController end upload_package("#{params['slug']}.zip", params["id"]) File.delete("public/#{params['slug']}.zip") - render :json => {"success"=>true,"url"=>@@store_domain + params["url"]}.to_json + render :json => {"success"=>true,"url"=>@store_url + params["url"]}.to_json end protected @@ -93,20 +91,14 @@ class Admin::TemplateStoreController < OrbitBackendController def get_template(id) store_session.get_template(id) - # uri = URI.parse("#{@@store_domain}/api/templates/#{id}") - # http = Net::HTTP.new(uri.host, uri.port) - # request = Net::HTTP::Get.new(uri.request_uri) - # response = http.request(request) - # response.body end def get_templates - extensions = store_session.templates - # uri = URI.parse("#{@@store_domain}/api/templates") - # http = Net::HTTP.new(uri.host, uri.port) - # request = Net::HTTP::Get.new(uri.request_uri) - # response = http.request(request) - # response.body + store_session.templates + end + + def set_store + @store_url = STORE_CONFIG[:store_settings]["url"] end end \ No newline at end of file
    "> - + diff --git a/app/views/admin/template_store/index.html.erb b/app/views/admin/template_store/index.html.erb index e4c8a61..fd462ec 100644 --- a/app/views/admin/template_store/index.html.erb +++ b/app/views/admin/template_store/index.html.erb @@ -5,5 +5,6 @@ Status