Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-09 20:02:54 +01:00
Merge branch 'main' into add_tag_creation_to_tag_field
Dieser Commit ist enthalten in:
Commit
e4de96ed03
4 geänderte Dateien mit 45 neuen und 1 gelöschten Zeilen
|
@ -20,6 +20,10 @@ class CustomWizard::AdminApiController < CustomWizard::AdminController
|
||||||
raise Discourse::InvalidParameters, "An API with that name already exists: '#{current.title || current.name}'"
|
raise Discourse::InvalidParameters, "An API with that name already exists: '#{current.title || current.name}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless subscription.includes?(:api, :all)
|
||||||
|
raise Discourse::InvalidParameters, "Your subscription doesn't include API features."
|
||||||
|
end
|
||||||
|
|
||||||
PluginStoreRow.transaction do
|
PluginStoreRow.transaction do
|
||||||
CustomWizard::Api.set(api_params[:name], title: api_params[:title])
|
CustomWizard::Api.set(api_params[:name], title: api_params[:title])
|
||||||
|
|
||||||
|
@ -130,4 +134,8 @@ class CustomWizard::AdminApiController < CustomWizard::AdminController
|
||||||
|
|
||||||
@auth_data ||= auth_data
|
@auth_data ||= auth_data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def subscription
|
||||||
|
@subscription ||= CustomWizard::Subscription.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -87,6 +87,14 @@ class CustomWizard::Subscription
|
||||||
business: ['*'],
|
business: ['*'],
|
||||||
community: ['*']
|
community: ['*']
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
api: {
|
||||||
|
all: {
|
||||||
|
none: [],
|
||||||
|
standard: [],
|
||||||
|
business: ['*'],
|
||||||
|
community: ['*']
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -95,7 +103,7 @@ class CustomWizard::Subscription
|
||||||
@subscription = find_subscription
|
@subscription = find_subscription
|
||||||
end
|
end
|
||||||
|
|
||||||
def includes?(feature, attribute, value)
|
def includes?(feature, attribute, value = nil)
|
||||||
attributes = self.class.attributes[feature]
|
attributes = self.class.attributes[feature]
|
||||||
|
|
||||||
## Attribute is not part of a subscription
|
## Attribute is not part of a subscription
|
||||||
|
|
7
spec/fixtures/api/api.json
gevendort
Normale Datei
7
spec/fixtures/api/api.json
gevendort
Normale Datei
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"name": "my_api",
|
||||||
|
"title": "My API",
|
||||||
|
"auth_type": "none",
|
||||||
|
"endpoints": "[{\"name\":\"my_endpoint\",\"url\":\"https://endpoint.com\",\"method\":\"POST\",\"content_type\":\"application/json\",\"success_codes\":[200]}]",
|
||||||
|
"new": "true"
|
||||||
|
}
|
21
spec/requests/custom_wizard/admin/api_controller_spec.rb
Normale Datei
21
spec/requests/custom_wizard/admin/api_controller_spec.rb
Normale Datei
|
@ -0,0 +1,21 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
describe CustomWizard::AdminApiController do
|
||||||
|
fab!(:admin_user) { Fabricate(:user, admin: true) }
|
||||||
|
let(:api_json) { get_wizard_fixture("api/api") }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in(admin_user)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "does not save if user does not have relevant subscription" do
|
||||||
|
put "/admin/wizards/api/:name.json", params: api_json.to_h
|
||||||
|
expect(response.status).to eq(400)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "saves when user does have relevant subscription" do
|
||||||
|
enable_subscription("business")
|
||||||
|
put "/admin/wizards/api/:name.json", params: api_json.to_h
|
||||||
|
expect(response.status).to eq(200)
|
||||||
|
end
|
||||||
|
end
|
Laden …
In neuem Issue referenzieren