mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Clean up permalink checker
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
angular.module("admin.enterprises")
|
||||
.controller "permalinkCtrl", ($scope, Enterprise, PermalinkChecker) ->
|
||||
$scope.pristinePermalink = Enterprise.permalink
|
||||
.controller "permalinkCtrl", ($scope, PermalinkChecker) ->
|
||||
$scope.pristinePermalink = $scope.Enterprise.permalink
|
||||
$scope.availablility = ""
|
||||
$scope.checking = false
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ class EnterprisesController < BaseController
|
||||
before_filter :set_order_cycles, only: :shop
|
||||
before_filter :load_active_distributors, only: :shop
|
||||
|
||||
respond_to :js, only: :permalink_checker
|
||||
|
||||
def index
|
||||
@enterprises = Enterprise.all
|
||||
end
|
||||
@@ -72,15 +74,13 @@ class EnterprisesController < BaseController
|
||||
end
|
||||
|
||||
def check_permalink
|
||||
return render text: params[:permalink], status: 409 if Enterprise.find_by_permalink params[:permalink]
|
||||
|
||||
path = Rails.application.routes.recognize_path( "/#{ params[:permalink].to_s }" )
|
||||
if path && path[:controller] == "cms_content"
|
||||
respond_to do |format|
|
||||
format.js { render text: params[:permalink], status: 200 }
|
||||
end
|
||||
render text: params[:permalink], status: 200
|
||||
else
|
||||
respond_to do |format|
|
||||
format.js { render text: params[:permalink], status: 409 }
|
||||
end
|
||||
render text: params[:permalink], status: 409
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -9,15 +9,15 @@ describe "permalinkCtrl", ->
|
||||
|
||||
beforeEach ->
|
||||
module('admin.enterprises')
|
||||
Enterprise = {
|
||||
Enterprise =
|
||||
permalink: "something"
|
||||
}
|
||||
|
||||
inject ($rootScope, $controller, _$q_, _PermalinkChecker_) ->
|
||||
$scope = $rootScope
|
||||
$scope.Enterprise = Enterprise
|
||||
$q = _$q_
|
||||
PermalinkChecker = _PermalinkChecker_
|
||||
$ctrl = $controller 'permalinkCtrl', {$scope: $scope, Enterprise: Enterprise, PermalinkChecker: PermalinkChecker}
|
||||
$ctrl = $controller 'permalinkCtrl', {$scope: $scope, PermalinkChecker: PermalinkChecker}
|
||||
|
||||
describe "checking permalink", ->
|
||||
deferred = null
|
||||
|
||||
Reference in New Issue
Block a user