Skip to content

Commit

Permalink
Cleanup controller escaping (snipe#3084)
Browse files Browse the repository at this point in the history
* Make delete routes work.  We put a little form in the modal that spoofs the delete field.

* Fix route on creating a user.

* Fix redundant id parameter.

* Port acceptance tests to new urls.

* Initial work on migrating to model based policies instead of global gates.  Will allow for much more detailed permissions bits in the future.

* This needs to stay for the dashboard checks.

* Add user states for permissions to build tests.

* Build up unit tests for gates/permissions.  Move accessories/consumables/assets to policies instead of in authserviceprovider

* Migrate various locations to new syntax.  Update test to be more specific

* Fix functional tests.

Add an artisan command for installing a settings setup on travis-ci

* Try a different id... Need to come up with a better way of passing the id for tests that need an existing one.

* Try to fix travis

* Update urls to use routes and not hardcode old paths.  Also fix some migration errors found along the way.:

* Add a environment for travis functional tests.

* Adjust config file to make travis use it.

* Use redirect()->route instead of redirect()-to

* Dump all failures in the output directory if travis fails.

* Cleanups and minor fixes.

* Adjust the supplier modelfactory to comply with new validation restrictions.

* Some test fixes.

* Locales can be longer than 5 characters according to faker... fex gez_ET.  Increase lenght in mysql and add a validation

* Update test database dump to latest migrations.

* Extend Supplier phone/fax length.

This catches issues found in testing with a phone number with a five digit extension.  fex (356) 654-3024 x36632

Also move away from escaping all values put into eloquent.  Eloquent
already uses PDO parameter binding, and this was leading to names like
Mr Ryan O'Malley turning into an html escaped version of that name when
stored.  All values should be escaped when using {{}}, we'll just have
to be more cautious when we use {!!, but I think we already are?

* Remove additional escaping here, like we did in suppliers controller.

* No need to eager load all of these relationships when we can call the count on the querybuilder directly

* Work on controller cleanup

* Always start from scrach, catches more issues this way.

* Update sql dump.  Remove old code from permissions test.

* Generate a deletable item on demand in the test, rather than relying on one existing.  I think we should probably move to mock all the database stuff at some point..

* More travis related fixes

* Break script into multiple functional lines

* Update all controllers to use the new helper, also cleanup syntax and docblocks along the way.
  • Loading branch information
dmeltzer authored and snipe committed Dec 20, 2016
1 parent cd8c585 commit 323c380
Show file tree
Hide file tree
Showing 32 changed files with 1,716 additions and 2,283 deletions.
2 changes: 1 addition & 1 deletion .env.testing
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DB_PASSWORD=null
# --------------------------------------------
# REQUIRED: OUTGOING MAIL SERVER SETTINGS
# --------------------------------------------
MAIL_DRIVER=smtp
MAIL_DRIVER=log
MAIL_HOST=email-smtp.us-west-2.amazonaws.com
MAIL_PORT=587
MAIL_USERNAME=YOURUSERNAME
Expand Down
4 changes: 4 additions & 0 deletions .env.tests
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ APP_KEY=base64:tu9NRh/a6+dCXBDGvg0Gv/0TcABnFsbT4AKxrr8mwQo=
# --------------------------------------------
LOGIN_MAX_ATTEMPTS=1000000
LOGIN_LOCKOUT_DURATION=100000000

MAIL_DRIVER=log
MAIL_FROM_ADDR=you@example.com
MAIL_FROM_NAME=Snipe-IT
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ before_script:
# omitting "script:" will default to phpunit
# use the $DB env variable to determine the phpunit.xml to use
# script: ./vendor/bin/codecept run --env testing-ci
script: ./vendor/bin/codecept run unit --env testing-ci && ./vendor/bin/codecept run functional --env=functional-travis
script:
- ./vendor/bin/codecept run unit --env testing-ci
- ./vendor/bin/codecept run acceptance --env=testing-ci
- ./vendor/bin/codecept run functional --env=functional-travis
#script: ./vendor/bin/codecept run

after_success:
Expand Down
29 changes: 29 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,5 +685,34 @@ public static function stripTagsFromJSON(Array $array) {

}

/**
* Generate html button for datatable actions.
* @author Daniel Meltzer
* @since 3.7
* @param string $type
* @param string $route
* @param boolean $enabled Used for checkin/checkout
* @param string $message Used for Delete Modal
* @param string $itemName Used for Delete Modal
* @return string
*/
public static function generateDatatableButton($type, $route, $enabled = true, $message = null, $itemName = null)
{
$disabledString = $enabled ? '' : 'disabled';
switch($type) {
case 'checkout':
return '<a href="' . $route . '" style="margin-right:5px;" class="btn btn-info btn-sm ' . $disabledString . '">' . trans('general.checkout') . '</a>';
case 'checkin':
return '<a href="' . $route . '" class="btn btn-info btn-sm ' . $disabledString . '">'.trans('general.checkin').'</a>';
case 'edit':
return '<a href="' . $route . '" class="btn btn-warning btn-sm ' . $disabledString . '" title="Edit" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
case 'clone':
return '<a href="'.$route.'" class="btn btn-info btn-sm ' . $disabledString . '" title="Clone" data-toggle="tooltip"><i class="fa fa-clone"></i></a>';
case 'delete':
return '<a data-html="false" class="btn delete-asset btn-danger btn-sm ' . $disabledString . '" data-toggle="modal" href="' . $route . '" data-content="' . $message . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($itemName) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
case 'restore':
return '<a href="'.$route.'" class="btn btn-warning btn-sm ' . $disabledString . '"><i class="fa fa-recycle icon-white"></i></a>';
}
}

}
Loading

0 comments on commit 323c380

Please sign in to comment.