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..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 - - @@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 \ No newline at end of file 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..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/controllers/admin/template_store_controller.rb b/app/controllers/admin/template_store_controller.rb index 5f2344c..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_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 \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c8fcfe2..98618ef 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 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/app/models/site.rb b/app/models/site.rb index a37cbbb..d1cfe57 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,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 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 @@
"> - + | 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 |
---|