Skip to content

Handle case of first CORS whitelist add-delete - #29742

Merged
PVince81 merged 1 commit into
masterfrom
fix-cors-1
Dec 3, 2017
Merged

PVince81 merged 1 commit into
masterfrom
fix-cors-1

Conversation

@phil-davis

Copy link
Copy Markdown
Contributor

Description

Handle a default array the first time when there are no CORS whitelist entries.
When removing the last entry, delete the value completely.

Related Issue

Motivation and Context

Be able to add and delete CORS whitelist entries.

How Has This Been Tested?

Add and delete various entries manually in the webUI, refreshing to confirm the changes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@phil-davis phil-davis added this to the development milestone Dec 1, 2017
@phil-davis phil-davis self-assigned this Dec 1, 2017
Comment thread settings/Controller/CorsController.php Outdated
$userId = $this->userId;
$domains = json_decode($this->config->getUserValue($userId, 'core', 'domains'));

$domains = json_decode($this->config->getUserValue($userId, 'core', 'domains'), true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not also add "[]" here for consistency since you did above ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, in theory removeDomain is only called if there is something to remove. But I guess it should be resilient and silent remove something from nothing if asked.

if ($id >= 0 && $id < count($domains)) {
unset($domains[$id]);
$this->config->setUserValue($userId, 'core', 'domains', json_encode($domains));
if (count($domains)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty($domains) ?

@PVince81 PVince81 mentioned this pull request Dec 1, 2017
83 of 87 tasks
@phil-davis
phil-davis force-pushed the fix-cors-1 branch 2 times, most recently from 0b969d9 to d74f122 Compare December 1, 2017 16:13
@phil-davis

Copy link
Copy Markdown
Contributor Author

@ anybody who cares - I think this swill pass unit tests and also actually works now. CI will tell. Ready for review again.

@codecov

codecov Bot commented Dec 1, 2017 •

Copy link
Copy Markdown

Codecov Report

Merging #29742 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #29742   +/-   ##
=========================================
  Coverage     62.61%   62.61%           
+ Complexity    17582    17581    -1     
=========================================
  Files          1037     1037           
  Lines         57914    57914           
=========================================
  Hits          36263    36263           
  Misses        21651    21651
Impacted Files Coverage Δ Complexity Δ
settings/Controller/CorsController.php 97.5% <100%> (ø) 10 <0> (-1) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a416a25...59cc6a3. Read the comment docs.

@PVince81
PVince81 merged commit 1518adb into master Dec 3, 2017
@PVince81
PVince81 deleted the fix-cors-1 branch December 3, 2017 18:30
@PVince81

PVince81 commented Dec 3, 2017

Copy link
Copy Markdown
Contributor

@phil-davis please backport for 10.0.4

@PVince81

PVince81 commented Dec 3, 2017

Copy link
Copy Markdown
Contributor

stable10: #29749

@lock

lock Bot commented Aug 1, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants