This commit is contained in:
Harry Bomrah 2014-02-17 12:20:25 +08:00
commit 655a1188f6
22 changed files with 179 additions and 33 deletions

View File

@ -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'

View File

@ -1,6 +1,5 @@
class Admin::ModuleStoreController < OrbitBackendController
@@store = STORE_CONFIG[:store_settings]["url"]
before_filter :check_central_server_connection, :only => [:get_extensions]
def index
@extensions = get_extensions
@ -85,7 +84,7 @@ class Admin::ModuleStoreController < OrbitBackendController
protected
def get_extensions
extensions = JSON.parse(open("#{@@store}/api/extensions").read)
extensions = store_session.extensions
exist_exts = []
ext_file = File.new("#{Rails.root}/downloaded_extensions.rb", "r")
@ -112,7 +111,7 @@ class Admin::ModuleStoreController < OrbitBackendController
end
def get_extension(id)
JSON.parse(open("#{@@store}/api/extensions/#{id}").read)
store_session.get_extension(id)
end
def get_downloaded_extension
@ -142,4 +141,10 @@ class Admin::ModuleStoreController < OrbitBackendController
end
end
private
def get_site
@site ||= Site.first
end
end

View File

@ -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

View File

@ -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)

View File

@ -3,24 +3,22 @@ require 'uri'
require 'fileutils'
require 'zip/zip'
class Admin::TemplateStoreController < OrbitBackendController
before_filter :check_central_server_connection, :only => [:get_templates]
before_filter :set_store
@@store_domain = STORE_CONFIG[:store_settings]["url"]
def index
@store = @@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
@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
@ -92,19 +90,15 @@ 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)
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
store_session.templates
end
def set_store
@store_url = STORE_CONFIG[:store_settings]["url"]
end
end

View File

@ -479,4 +479,18 @@ class ApplicationController < ActionController::Base
end
end
def check_central_server_connection
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
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

View File

@ -1,6 +1,7 @@
class OrbitBackendController < ApplicationController
include OrbitCategory::Categorizing
include OrbitCoreLib::Authorization
include OrbitCoreLib::PermissionUtility
include OrbitTag::Tagging
include AdminHelper
include ApplicationHelper

View File

@ -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'

View File

@ -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)

View File

@ -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,19 @@ class Site
fetch_meta.save
end
end
def generate_site_token
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

View File

@ -184,7 +184,6 @@
<div class="panel">
<div class="panel-heading"><i class="icon-shopping-cart"></i><span class="break"></span><%= t(:module_store) %></div>
<div class="pannel-body">
<table id="mt-list" class="table main-list">
<thead>
<tr class="sort-header">

View File

@ -1,7 +1,7 @@
<tr>
<td>
<a href="<%= admin_template_store_template_path(template["_slugs"][0]) %>">
<img src="<%= @store + template['preview']['preview']['thumb']['url'] %>" class="item-thumb" />
<img src="<%= @store_url + template['preview']['preview']['thumb']['url'] %>" class="item-thumb" />
</a>
</td>
<td>

View File

@ -5,5 +5,6 @@
<th class="span1">Status</th>
</thead>
<tbody>
<%= render :partial => 'template', :collection => @templates %>
</tbody>

View File

@ -6,7 +6,7 @@
<div id="content" class="clearfix">
<div class="side">
<div id="item-info">
<%= image_tag "#{@store}#{@template['preview']['preview']['thumb']['url']}", :class => "item-thumb" %>
<%= image_tag "#{@store_url}/#{@template['preview']['preview']['thumb']['url']}", :class => "item-thumb" %>
<h2 class="item-name"><%= @template['title'] %></h2>
<% 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"] %>

View File

@ -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

View File

@ -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

View File

@ -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: 相關連結

View File

@ -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

View File

@ -1,2 +1,4 @@
store_settings:
url: "http://store.tp.rulingcom.com"
api_url: "http://store.tp.rulingcom.com/api"
api_key: 'Token token="2870f77e59168dbe3fbdffba466c7c8d"'

View File

@ -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

View File

@ -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

52
lib/store.rb Normal file
View File

@ -0,0 +1,52 @@
require 'httparty'
class Store
include HTTParty
format :json
base_uri STORE_CONFIG[:store_settings]["api_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",
'Accept' => 'application/json'
}
}
@options_for_client = {
headers: {
"Authorization" => api_key,
"Content-Type" => "application/json",
'Accept' => 'application/json'
}
}
end
def templates(options={})
options = @options_for_get
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 )
end
end