You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by garrensmith <gi...@git.apache.org> on 2015/01/27 12:06:15 UTC
[GitHub] couchdb-fauxton pull request: CORS configuration
GitHub user garrensmith opened a pull request:
https://github.com/apache/couchdb-fauxton/pull/250
CORS configuration
CORS configuration in the config section. I've kept it to the simplest settings required for a user to enable and use CORS.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/garrensmith/couchdb-fauxton CORS
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/couchdb-fauxton/pull/250.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #250
----
commit 29f371f85e15d7a9721e68bf8e6aa789b37804d3
Author: Christian Hogan <gi...@infliction.org>
Date: 2014-11-28T18:19:13Z
Initial add CORS to Fauxton
commit aee2e8fd16df433f6258c262543bb740c5929580
Author: Garren Smith <ga...@gmail.com>
Date: 2015-01-20T08:02:34Z
CORS in React
This is the cors section of the config page done in React.js
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-72000595
Thanks @michellephung and @robertkowalski I've made some fixes. Could you take another look.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604596
--- Diff: app/addons/cors/templates/origin_domain_table.html ---
@@ -0,0 +1,17 @@
+<!--
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations under
+the License.
+-->
+
+<table id="origin-domain-table" class="table table-striped">
+ <tbody></tbody>
+</table>
--- End diff --
i think we can remove that file
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604631
--- Diff: app/addons/cors/templates/origin_domain_row.html ---
@@ -0,0 +1,33 @@
+<!--
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations under
+the License.
+-->
+
+<td>
+ <div class="js-url url-display"><%-url%></div>
+
+ <div class="js-edit-domain edit-domain-section hide">
+ <div class="field-wrapper">
+ <input type="text" value="<%-url%>" />
+ </div>
+ <a class="js-save-domain btn update-domain-btn">
+ <i class="fonticon-save"></i>
+ Update
+ </a>
+ </div>
+</td>
+<td width="30">
+ <span class="js-edit fonticon-pencil" title="Click to edit"></span>
+</td>
+<td width="30">
+ <span class="js-delete fonticon-trash" title="Click to delete"></span>
+</td>
--- End diff --
i think we can remove that file
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604358
--- Diff: app/addons/cors/resources.js ---
@@ -0,0 +1,81 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+define([
+ "app",
+ "api"
+],
+
+function (app, FauxtonAPI) {
+ var CORS = FauxtonAPI.addon();
+
+
+ CORS.Config = FauxtonAPI.Model.extend({
+ url: function() {
+ return app.host+"/_config/cors";
--- End diff --
please put a space between the two and use single quotes
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604702
--- Diff: app/addons/cors/views.js ---
@@ -0,0 +1,359 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+define([
+ "app",
+ "api",
+ "addons/cors/resources",
+ "addons/cors/components.react",
+ "addons/cors/actions"
+],
+
+
+function (app, FauxtonAPI, CORS, Components, Actions) {
+ var Views= {};
+
+ Views.CORSWrapper = FauxtonAPI.View.extend({
+ className: 'list',
+ initialize: function (options) {
+ this.options = options;
+ },
+
+ afterRender: function () {
+ Actions.editCors({
+ cors: this.options.cors,
+ httpd: this.options.httpd
+ });
+ Components.renderCORS(this.el);
+ },
+
+ cleanup: function () {
+ Components.removeCORS(this.el);
+ }
+
+ });
+
+ Views.CORSMain = FauxtonAPI.View.extend({
+ className: 'cors-page',
+ template: 'addons/cors/templates/cors',
+ events: {
+ 'submit form#corsForm': 'submit',
+ 'click .js-enable-cors': 'corsClick',
+ 'click .js-restrict-origin-domains': 'restrictOrigins',
+ 'click .js-all-origin-domains': 'allOrigins'
+ },
+
+ initialize: function () {
+ this.originDomainTable = this.setView('.origin-domains', new Views.OriginDomainTable({
+ model: this.model
+ }));
+ },
+
+ serialize: function () {
+ return {
+ enableCors: this.model.get('credentials')
+ };
+ },
+
+ establish: function(){
+ return [this.model.fetch()];
+ },
+
+ afterRender: function () {
+ var corsEnabled = this.$('.js-enable-cors').is(':checked');
+ this.$('#collapsing-container').toggle(corsEnabled);
+ this.setupOrigins();
+ },
+
+ corsClick: function (e) {
+ var isChecked = this.$(e.target).prop('checked');
+ this.$('#collapsing-container').toggle(isChecked);
+ this.setupOrigins();
+ },
+
+
+ setupOrigins: function() {
+ var storedOrigins = this.model.get('origins');
+ if (storedOrigins && storedOrigins != '*') {
+ this.restrictOrigins();
+ } else {
+ this.allOrigins();
+ }
+ },
+
+ allOrigins: function() {
+ this.$('.js-all-origin-domains').prop('checked', true);
+ this.$('.js-restrict-origin-domains').prop('checked', false);
+ this.$('#origin-domains-container').hide();
+ },
+
+ restrictOrigins: function() {
+ this.$('.js-restrict-origin-domains').prop('checked', true);
+ this.$('.js-all-origin-domains').prop('checked', false);
+ this.$('#origin-domains-container').show();
+ },
+
+ formToJSON: function(formSelector){
+ var formObject = $(formSelector).serializeArray(),
+ formJSON={};
+ _.map(formObject, function(field){
+ formJSON[field.name]=field.value;
+ });
+ return formJSON;
+ },
+
+ submit: function(e){
+ e.preventDefault();
+ var data = this.formToJSON(e.currentTarget);
+
+ if (data.enable_cors === 'on') {
+
+ // CORS checked, save data
+ if (data.restrict_origin_domains === 'on') {
+ var storedOrigins = this.model.get('origins').split(',');
+ var newDomain = $.trim(data.new_origin_domain);
+
+ // if a new domain has been entered, check it's valid
+ if (!_.isEmpty(newDomain) && !CORS.validateCORSDomain(newDomain)) {
+ FauxtonAPI.addNotification({
+ msg: 'Please enter a valid domain, starting with http/https and only containing the domain (not a subfolder).',
+ type: 'error',
+ clear: true
+ });
+ return;
+ }
+
+ // check that the user has entered at least one new origin domain
+ if (storedOrigins && storedOrigins.length > 0 && storedOrigins !== '*') {
+ this.originData = storedOrigins.concat(newDomain).toString();
+ } else {
+ if (_.isEmpty(newDomain)) {
+ FauxtonAPI.addNotification({
+ msg: 'Please enter a new origin domain.',
+ type: 'error',
+ clear: true
+ });
+ this.$('.new-origin-domain').focus();
+ return;
+ }
+ this.originData = data.new_origin_domain;
+ }
+
+ } else {
+ this.originData = "*";
+ }
+
+
+ var enableOption = new CORS.ConfigModel({
+ section: 'httpd',
+ attribute: 'enable_cors',
+ value: 'true'
+ });
+
+ var enableCreds = new CORS.ConfigModel({
+ section: 'cors',
+ attribute: 'credentials',
+ value: 'true'
+ });
+
+ var allowOrigins = new CORS.ConfigModel({
+ section: 'cors',
+ attribute: 'origins',
+ value: this.originData
+ });
+
+ enableOption.save().then(function (response) {
+ var notification = FauxtonAPI.addNotification({
+ msg: 'Your settings have been saved.',
+ type: 'success',
+ clear: true
+ });
+ },
+ function (response, errorCode, errorMsg) {
+ var notification = FauxtonAPI.addNotification({
+ msg: 'Sorry! There was an error. Code ' + errorCode + '.',
+ type: 'error',
+ clear: true
+ });
+ });
+
+ enableCreds.save();
+ allowOrigins.save();
+ this.$('.new-origin-domain').val('');
+
+ } else {
+
+ // Disable CORS
+ var disableOption = new CORS.ConfigModel({
+ section: 'httpd',
+ attribute: 'enable_cors',
+ value: 'false'
+ });
+
+ var disableCreds = new CORS.ConfigModel({
+ section: 'cors',
+ attribute: 'credentials',
+ value: 'false'
+ });
+
+ var disableOrigins = new CORS.ConfigModel({
+ section: 'cors',
+ attribute: 'origins',
+ value: ''
+ });
+
+ disableOption.save().then(function (response) {
+ var notification = FauxtonAPI.addNotification({
+ msg: 'Your settings have been saved.',
+ type: 'success',
+ clear: true
+ });
+ },
+ function (response, errorCode, errorMsg) {
+ var notification = FauxtonAPI.addNotification({
+ msg: 'Sorry! There was an error. Code ' + errorCode + '.',
+ type: 'error',
+ clear: true
+ });
+ });
+
+ disableCreds.save();
+ disableOrigins.save();
+ }
+ }
+ });
+
+ Views.OriginDomainTable = FauxtonAPI.View.extend({
--- End diff --
i think we can remove that object
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-72416142
Merged
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-71651710
entering the domain `https://foo.com` does not alter the local.ini and does not add the domain
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604660
--- Diff: app/addons/cors/templates/cors.html ---
@@ -0,0 +1,50 @@
+<!--
+Licensed under the Apache License, Version 2.0 (the "License"); you may not
+use this file except in compliance with the License. You may obtain a copy of
+the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+License for the specific language governing permissions and limitations under
+the License.
+-->
+
+<header id="cors-header">
+ <p>Cross-Origin Resource Sharing (CORS) lets you connect to remote servers directly from the browser, so you can host browser-based apps on static pages and talk directly with CouchDB to load your data.</p>
+</header>
+
+<form id="corsForm">
+
+ <div class="cors-enable">
+ <label class="checkbox">
+ <input type="checkbox" class="js-enable-cors" name="enable_cors" <% if (typeof enableCors !== 'undefined' && enableCors === 'true') { %> checked="checked" <% } %>> Enable CORS
+ </label>
+ </div>
+
+ <div id="collapsing-container">
+ <p><strong>Origin Domains</strong></p>
+
+ <p>Databases will accept requests from these domains:</p>
+
+ <label class="checkbox"><input type="checkbox" class="js-all-origin-domains" name="all_origin_domains"> All origin domains ( * )</label></li>
+
+ <label class="checkbox"><input type="checkbox" class="js-restrict-origin-domains" name="restrict_origin_domains"> Restrict to specific origin domains</label>
+
+ <div id="origin-domains-container">
+ <div class="origin-domains"></div>
+ <input type="text" class="new-origin-domain" name="new_origin_domain" value="" placeholder="e.g., https://site.com" />
+ </div>
+
+ </div>
+
+ </div>
+
+ <div class="form-actions">
+ <input class="btn btn-success" type="submit" value="Save" />
+ </div>
+
+</form>
--- End diff --
i think we can remove that file
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-71651331
after adding an entry & reload the entry is empty: https://cloudup.com/cYlfO2tqejk
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith closed the pull request at:
https://github.com/apache/couchdb-fauxton/pull/250
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604054
--- Diff: app/addons/cors/components.react.jsx ---
@@ -0,0 +1,307 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+define([
+ "api",
+ "react",
+ "addons/cors/stores",
+ "addons/cors/resources",
+ "addons/cors/actions"
+], function (FauxtonAPI, React, Stores, Resources, Actions) {
+ var corsStore = Stores.corsStore;
+
+ var validateOrigin = function (origin) {
+ if (!Resources.validateCORSDomain(origin)) {
+ FauxtonAPI.addNotification({
+ msg: 'Please enter a valid domain, starting with http/https and only containing the domain (not a subfolder).',
+ type: 'error',
+ clear: true
+ });
+
+ return false;
+ }
+
+ return true;
+ };
+
+ var OriginRow = React.createClass({
+
+ getInitialState: function () {
+ return {
+ edit: false,
+ updatedOrigin: this.props.origin
+ };
+ },
+
+ editOrigin: function (event) {
+ event.preventDefault();
+ this.setState({edit: !this.state.edit});
+ },
+
+ updateOrigin: function (event) {
+ event.preventDefault();
+ if (!validateOrigin(this.state.updatedOrigin)) {
+ return;
+ }
+ this.props.updateOrigin(this.state.updatedOrigin, this.props.origin);
+ this.setState({edit: false});
+ },
+
+ deleteOrigin: function (event) {
+ event.preventDefault();
+ if (!window.confirm('Are you sure you want to delete ' + this.props.origin)) {
+ return;
+ }
+
+ this.props.deleteOrigin(this.props.origin);
+ },
+
+ onInputChange: function (event) {
+ this.setState({updatedOrigin: event.target.value});
+ },
+
+ createOriginDisplay: function () {
+ if (this.state.edit) {
+ return (
+ <div className="input-append edit-domain-section">
+ <input type="text" className="span11" name="update_origin_domain" onChange={this.onInputChange} value={this.state.updatedOrigin}/>
+ <button onClick={this.updateOrigin} className="btn btn-primary update-origin"> Update </button>
+ </div>
+ );
+ }
+
+ return <div className="js-url url-display">{this.props.origin}</div>;
+ },
+
+ render: function () {
+ var display = this.createOriginDisplay();
+ return (
+ <tr>
+ <td>
+ { display }
+ </td>
+ <td width="30">
+ <span className="fonticon-pencil" onClick={this.editOrigin} title="Click to edit"></span>
+ </td>
+ <td width="30">
+ <span className="fonticon-trash" onClick={this.deleteOrigin} title="Click to delete"></span>
+ </td>
+ </tr>
+ );
+ }
+
+ });
+
+ var OriginTable = React.createClass({
+
+ createRows: function () {
+ return _.map(this.props.origins, function (origin, i) {
+ return <OriginRow
+ updateOrigin={this.props.updateOrigin}
+ deleteOrigin={this.props.deleteOrigin}
+ key={i} origin={origin}
+ />;
+ }, this);
+ },
+
+ render: function () {
+ if (!this.props.isVisible || this.props.origins.length === 0) {
+ return null;
+ }
+
+ var origins = this.createRows();
+
+ return (
+ <table id="origin-domain-table" className="table table-striped">
+ <tbody>
+ {origins}
+ </tbody>
+ </table>
+ );
+ }
+
+ });
+
+ var OriginInput = React.createClass({
+ getInitialState: function () {
+ return {
+ origin: ''
+ };
+ },
+
+ onInputChange: function (e) {
+ this.setState({origin: e.target.value});
+ },
+
+ addOrigin: function (event) {
+ event.preventDefault();
+ if (!validateOrigin(this.state.origin)) {
+ return;
+ }
+
+ this.props.addOrigin(this.state.origin);
+ this.setState({origin: ''});
+ },
+
+ render: function () {
+ if (!this.props.isVisible) {
+ return null;
+ }
+
+ return (
+ <div id= "origin-domains-container">
+ <div className= "origin-domains">
+ <div className="input-append">
+ <input type="text" className="span12" name="new_origin_domain" onChange={this.onInputChange} value={this.state.origin} placeholder="e.g., https://site.com"/>
+ <button onClick={this.addOrigin} className="btn btn-primary add-domain"> Add </button>
+ </div>
+ </div>
+ </div>
+ );
+ }
+
+ });
+
+ var Origins = React.createClass({
+
+ onOriginChange: function (event) {
+ console.log('boom');
--- End diff --
debug output
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604355
--- Diff: app/addons/cors/resources.js ---
@@ -0,0 +1,81 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+define([
+ "app",
+ "api"
+],
+
+function (app, FauxtonAPI) {
+ var CORS = FauxtonAPI.addon();
+
+
+ CORS.Config = FauxtonAPI.Model.extend({
+ url: function() {
+ return app.host+"/_config/cors";
+ }
+ });
+
+ CORS.Httpd = FauxtonAPI.Model.extend({
+ url: function() {
+ return app.host+"/_config/httpd";
--- End diff --
please put a space between the two and use single quotes
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by michellephung <gi...@git.apache.org>.
Github user michellephung commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-71888154
Hey Garren,
A. I am also still seeing this issue @robertkowalski mentioned:

B. Clicking back and forth between 'Main config' and CORS, will show one of three screens:
- disabled cors (when it actually is enabled, which not right)
- enabled cors, with correct urls (this is right)
- enabled cors, with blank urls (not right)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604691
--- Diff: app/addons/cors/views.js ---
@@ -0,0 +1,359 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+define([
+ "app",
+ "api",
+ "addons/cors/resources",
+ "addons/cors/components.react",
+ "addons/cors/actions"
+],
+
+
+function (app, FauxtonAPI, CORS, Components, Actions) {
+ var Views= {};
+
+ Views.CORSWrapper = FauxtonAPI.View.extend({
+ className: 'list',
+ initialize: function (options) {
+ this.options = options;
+ },
+
+ afterRender: function () {
+ Actions.editCors({
+ cors: this.options.cors,
+ httpd: this.options.httpd
+ });
+ Components.renderCORS(this.el);
+ },
+
+ cleanup: function () {
+ Components.removeCORS(this.el);
+ }
+
+ });
+
+ Views.CORSMain = FauxtonAPI.View.extend({
--- End diff --
i think we can remove that object
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-72012386
+1
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604174
--- Diff: app/addons/cors/tests/componentsSpec.react.jsx ---
@@ -0,0 +1,155 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+define([
+ 'api',
+ 'addons/cors/components.react',
+ 'addons/cors/actions',
+ 'addons/cors/resources',
+ 'testUtils',
+ "react"
+], function (FauxtonAPI, Views, Actions, Resources, utils, React) {
+
+ var assert = utils.assert;
+ var TestUtils = React.addons.TestUtils;
+
+ describe('CORS Components', function () {
+
+ describe('OriginInput', function () {
+ var container, inputEl, addOrigin;
+ var newOrigin = 'http://new-site.com';
+
+ beforeEach(function () {
+ addOrigin = sinon.spy();
+ container = document.createElement('div');
+ inputEl = TestUtils.renderIntoDocument(<Views.OriginInput isVisible={true} addOrigin={addOrigin}/>, container);
+ });
+
+ afterEach(function () {
+ Resources.validateCORSDomain.restore && Resources.validateCORSDomain.restore();
+ React.unmountComponentAtNode(container);
+ });
+
+ it('calls validates each domain', function () {
+ var spy = sinon.spy(Resources, 'validateCORSDomain');
+ TestUtils.Simulate.change($(inputEl.getDOMNode()).find('input')[0],{target: {value: newOrigin}});
+ TestUtils.Simulate.click($(inputEl.getDOMNode()).find('.btn')[0]);
+ assert.ok(spy.calledWith(newOrigin));
+ });
+
+ it('calls addOrogin AddOrigin on add click with valid domain', function () {
+ TestUtils.Simulate.change($(inputEl.getDOMNode()).find('input')[0],{target: {value: newOrigin}});
+ TestUtils.Simulate.click($(inputEl.getDOMNode()).find('.btn')[0]);
+ assert.ok(addOrigin.calledWith(newOrigin));
+ });
+
+ it('shows notification if origin is not valid', function () {
+ var spy = sinon.spy(FauxtonAPI, 'addNotification');
+ TestUtils.Simulate.change($(inputEl.getDOMNode()).find('input')[0],{target: {value: 'badOrigin'}});
+ TestUtils.Simulate.click($(inputEl.getDOMNode()).find('.btn')[0]);
+ assert.ok(spy.calledOnce);
+ });
+
+
+ });
+
+ describe('Origins', function () {
+ var container, originEl, changeOrigin;
+
+ beforeEach(function () {
+ changeOrigin = sinon.spy();
+ container = document.createElement('div');
+ originEl = TestUtils.renderIntoDocument(<Views.Origins corsEnabled={true} isAllOrigins={false} originChange={changeOrigin}/>, container);
+ });
+
+ afterEach(function () {
+ React.unmountComponentAtNode(container);
+ });
+
+ /*it('calls change Origin on add radio button change', function () {
+ TestUtils.Simulate.click($(originEl.getDOMNode()).find('input[type="radio"]')[1]);
+ console.log(changeOrigin.calledOnce, $(originEl.getDOMNode()).html());
+ assert.ok(changeOrigin.calledWith(false));
+ });*/
--- End diff --
can we remove it?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#discussion_r23604715
--- Diff: app/addons/cors/views.js ---
@@ -0,0 +1,359 @@
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not
+// use this file except in compliance with the License. You may obtain a copy of
+// the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+// License for the specific language governing permissions and limitations under
+// the License.
+
+define([
+ "app",
+ "api",
+ "addons/cors/resources",
+ "addons/cors/components.react",
+ "addons/cors/actions"
+],
+
+
+function (app, FauxtonAPI, CORS, Components, Actions) {
+ var Views= {};
+
+ Views.CORSWrapper = FauxtonAPI.View.extend({
+ className: 'list',
+ initialize: function (options) {
+ this.options = options;
+ },
+
+ afterRender: function () {
+ Actions.editCors({
+ cors: this.options.cors,
+ httpd: this.options.httpd
+ });
+ Components.renderCORS(this.el);
+ },
+
+ cleanup: function () {
+ Components.removeCORS(this.el);
+ }
+
+ });
+
+ Views.CORSMain = FauxtonAPI.View.extend({
+ className: 'cors-page',
+ template: 'addons/cors/templates/cors',
+ events: {
+ 'submit form#corsForm': 'submit',
+ 'click .js-enable-cors': 'corsClick',
+ 'click .js-restrict-origin-domains': 'restrictOrigins',
+ 'click .js-all-origin-domains': 'allOrigins'
+ },
+
+ initialize: function () {
+ this.originDomainTable = this.setView('.origin-domains', new Views.OriginDomainTable({
+ model: this.model
+ }));
+ },
+
+ serialize: function () {
+ return {
+ enableCors: this.model.get('credentials')
+ };
+ },
+
+ establish: function(){
+ return [this.model.fetch()];
+ },
+
+ afterRender: function () {
+ var corsEnabled = this.$('.js-enable-cors').is(':checked');
+ this.$('#collapsing-container').toggle(corsEnabled);
+ this.setupOrigins();
+ },
+
+ corsClick: function (e) {
+ var isChecked = this.$(e.target).prop('checked');
+ this.$('#collapsing-container').toggle(isChecked);
+ this.setupOrigins();
+ },
+
+
+ setupOrigins: function() {
+ var storedOrigins = this.model.get('origins');
+ if (storedOrigins && storedOrigins != '*') {
+ this.restrictOrigins();
+ } else {
+ this.allOrigins();
+ }
+ },
+
+ allOrigins: function() {
+ this.$('.js-all-origin-domains').prop('checked', true);
+ this.$('.js-restrict-origin-domains').prop('checked', false);
+ this.$('#origin-domains-container').hide();
+ },
+
+ restrictOrigins: function() {
+ this.$('.js-restrict-origin-domains').prop('checked', true);
+ this.$('.js-all-origin-domains').prop('checked', false);
+ this.$('#origin-domains-container').show();
+ },
+
+ formToJSON: function(formSelector){
+ var formObject = $(formSelector).serializeArray(),
+ formJSON={};
+ _.map(formObject, function(field){
+ formJSON[field.name]=field.value;
+ });
+ return formJSON;
+ },
+
+ submit: function(e){
+ e.preventDefault();
+ var data = this.formToJSON(e.currentTarget);
+
+ if (data.enable_cors === 'on') {
+
+ // CORS checked, save data
+ if (data.restrict_origin_domains === 'on') {
+ var storedOrigins = this.model.get('origins').split(',');
+ var newDomain = $.trim(data.new_origin_domain);
+
+ // if a new domain has been entered, check it's valid
+ if (!_.isEmpty(newDomain) && !CORS.validateCORSDomain(newDomain)) {
+ FauxtonAPI.addNotification({
+ msg: 'Please enter a valid domain, starting with http/https and only containing the domain (not a subfolder).',
+ type: 'error',
+ clear: true
+ });
+ return;
+ }
+
+ // check that the user has entered at least one new origin domain
+ if (storedOrigins && storedOrigins.length > 0 && storedOrigins !== '*') {
+ this.originData = storedOrigins.concat(newDomain).toString();
+ } else {
+ if (_.isEmpty(newDomain)) {
+ FauxtonAPI.addNotification({
+ msg: 'Please enter a new origin domain.',
+ type: 'error',
+ clear: true
+ });
+ this.$('.new-origin-domain').focus();
+ return;
+ }
+ this.originData = data.new_origin_domain;
+ }
+
+ } else {
+ this.originData = "*";
+ }
+
+
+ var enableOption = new CORS.ConfigModel({
+ section: 'httpd',
+ attribute: 'enable_cors',
+ value: 'true'
+ });
+
+ var enableCreds = new CORS.ConfigModel({
+ section: 'cors',
+ attribute: 'credentials',
+ value: 'true'
+ });
+
+ var allowOrigins = new CORS.ConfigModel({
+ section: 'cors',
+ attribute: 'origins',
+ value: this.originData
+ });
+
+ enableOption.save().then(function (response) {
+ var notification = FauxtonAPI.addNotification({
+ msg: 'Your settings have been saved.',
+ type: 'success',
+ clear: true
+ });
+ },
+ function (response, errorCode, errorMsg) {
+ var notification = FauxtonAPI.addNotification({
+ msg: 'Sorry! There was an error. Code ' + errorCode + '.',
+ type: 'error',
+ clear: true
+ });
+ });
+
+ enableCreds.save();
+ allowOrigins.save();
+ this.$('.new-origin-domain').val('');
+
+ } else {
+
+ // Disable CORS
+ var disableOption = new CORS.ConfigModel({
+ section: 'httpd',
+ attribute: 'enable_cors',
+ value: 'false'
+ });
+
+ var disableCreds = new CORS.ConfigModel({
+ section: 'cors',
+ attribute: 'credentials',
+ value: 'false'
+ });
+
+ var disableOrigins = new CORS.ConfigModel({
+ section: 'cors',
+ attribute: 'origins',
+ value: ''
+ });
+
+ disableOption.save().then(function (response) {
+ var notification = FauxtonAPI.addNotification({
+ msg: 'Your settings have been saved.',
+ type: 'success',
+ clear: true
+ });
+ },
+ function (response, errorCode, errorMsg) {
+ var notification = FauxtonAPI.addNotification({
+ msg: 'Sorry! There was an error. Code ' + errorCode + '.',
+ type: 'error',
+ clear: true
+ });
+ });
+
+ disableCreds.save();
+ disableOrigins.save();
+ }
+ }
+ });
+
+ Views.OriginDomainTable = FauxtonAPI.View.extend({
+ template: 'addons/cors/templates/origin_domain_table',
+
+ initialize: function () {
+ // listen for any server-side changes to the object (i.e. saves/deletes). Only then, re-render the table
+ this.listenTo(this.model, 'sync', this.render);
+ },
+
+ beforeRender: function () {
+ var origins = this.model.get('origins');
+
+ // if the stored origins are set to '*' or nothing's defined, show nothing
+ if (_.isEmpty(origins) || origins === '*') {
+ return;
+ }
+ this.showRows();
+ },
+
+ showRows: function () {
+ var originsArray = this.model.get('origins').split(',');
+ _.each(originsArray, function (url, index) {
+ this.insertView('#origin-domain-table tbody', new Views.OriginDomainRow({
+ model: this.model,
+ index: index
+ }));
+ }, this);
+ }
+ });
+
+
+ // this gets passed the entire model so it can manipulate it directly (add/update the row)
+ Views.OriginDomainRow = FauxtonAPI.View.extend({
--- End diff --
i think we can remove that object
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-71652467
@robertkowalski you have to enter a domain and press 'Save'.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by robertkowalski <gi...@git.apache.org>.
Github user robertkowalski commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-71651528
the input field is overlapping the right side of the screen:

---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by michellephung <gi...@git.apache.org>.
Github user michellephung commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-72052884
+1
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] couchdb-fauxton pull request: CORS configuration
Posted by garrensmith <gi...@git.apache.org>.
Github user garrensmith commented on the pull request:
https://github.com/apache/couchdb-fauxton/pull/250#issuecomment-71643477
Thanks @robertkowalski for the review. I've fixed all the issues you have spotted.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---