Skip to content

Commit

Permalink
Merge branch 'release/1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
abrain committed Jan 15, 2016
2 parents 78932f7 + 322088e commit 33ee5d5
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 63 deletions.
1 change: 1 addition & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ ratings:
- src/**/*.php
- src/**/*.js
- src/**/*.css
- tests/**/*.php
exclude_paths:
- src/font-awesome/**/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
build
setupLocalTest.sh
59 changes: 39 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,48 @@ language: php

notifications:
email:
on_success: never
on_failure: change
on_success: change
on_failure: always

php:
- '5.3'
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- hhvm

env:
- WP_VERSION=3.7.12 WP_MULTISITE=0
- WP_VERSION=3.8.12 WP_MULTISITE=0
- WP_VERSION=3.9.10 WP_MULTISITE=0
- WP_VERSION=4.0.9 WP_MULTISITE=0
- WP_VERSION=4.1.9 WP_MULTISITE=0
- WP_VERSION=4.2.6 WP_MULTISITE=0
- WP_VERSION=4.3.2 WP_MULTISITE=0
- WP_VERSION=4.4.1 WP_MULTISITE=0

matrix:
include:
- php: 5.3
env: WP_VERSION=latest WP_MULTISITE=0
- php: 5.3
env: WP_VERSION=3.7 WP_MULTISITE=0
- php: 5.4
env: WP_VERSION=latest WP_MULTISITE=0
- php: 5.5
env: WP_VERSION=latest WP_MULTISITE=0
- php: 5.6
env: WP_VERSION=latest WP_MULTISITE=0
exclude:
- php: '5.5'
env: WP_VERSION=3.7.12 WP_MULTISITE=0
- php: '5.6'
env: WP_VERSION=3.7.12 WP_MULTISITE=0
- php: '7.0'
env: WP_VERSION=3.7.12 WP_MULTISITE=0
- php: '7.0'
env: WP_VERSION=3.8.12 WP_MULTISITE=0
- php: '7.0'
env: WP_VERSION=3.9.10 WP_MULTISITE=0
- php: '7.0'
env: WP_VERSION=4.0.9 WP_MULTISITE=0
- php: '7.0'
env: WP_VERSION=4.1.9 WP_MULTISITE=0
- php: '7.0'
env: WP_VERSION=4.2.6 WP_MULTISITE=0
allow_failures:
- php: hhvm
env: WP_VERSION=latest WP_MULTISITE=0
- php: nightly
env: WP_VERSION=latest WP_MULTISITE=0
allow_failures:
- php: hhvm
- php: nightly
fast_finish: true
fast_finish: true

before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ Der PHP-Code wird gemäß dem Coding Style Guide [PSR-2](http://www.php

### Mindestvoraussetzungen
* PHP: 5.3.0
* WordPress: 3.4
* WordPress: 3.7

### Social Media

* Twitter: [@einsatzvw](https://twitter.com/einsatzvw)
* App.net: [@einsatzverwaltung](https://alpha.app.net/einsatzverwaltung)
* Facebook: [Einsatzverwaltung](https://www.facebook.com/einsatzverwaltung/)
* GNU social: [@einsatzverwaltung](https://gnusocial.abrain.de/einsatzverwaltung)
20 changes: 14 additions & 6 deletions bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ download() {

if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then
WP_TESTS_TAG="tags/$WP_VERSION"
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
# http serves a single offer, whereas https serves multiple. we only want one
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
Expand All @@ -46,15 +48,21 @@ install_wp() {

mkdir -p $WP_CORE_DIR

if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p /tmp/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip
unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/
mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR
fi

download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz
tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR

download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}

Expand Down
20 changes: 20 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
{
"name": "abrain/einsatzverwaltung",
"description": "Wordpress-Plugin zur Verwaltung und Darstellung von Einsatzberichten der Feuerwehr und anderer Hilfsorganisationen",
"homepage": "https://www.abrain.de/software/einsatzverwaltung/",
"type": "wordpress-plugin",
"license": "GPL-2.0+",
"authors": [
{
"name": "Andreas Brain",
"email": "[email protected]",
"homepage": "https://www.abrain.de",
"role": "Developer"
}
],
"support": {
"email": "[email protected]",
"issues": "https://github.com/abrain/einsatzverwaltung/issues",
"forum": "https://wordpress.org/support/plugin/einsatzverwaltung",
"source": "https://github.com/abrain/einsatzverwaltung",
"docs": "https://www.abrain.de/software/einsatzverwaltung/anleitung/"
},
"require-dev": {
"codeclimate/php-test-reporter": "dev-master"
}
Expand Down
10 changes: 10 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<file>./tests/bootstrap.php</file>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
Expand Down
46 changes: 38 additions & 8 deletions src/einsatzverwaltung-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
use abrain\Einsatzverwaltung\Widgets\RecentIncidents;
use abrain\Einsatzverwaltung\Widgets\RecentIncidentsFormatted;
use WP_Query;
use WP_User;

/**
* Grundlegende Funktionen
*/
class Core
{
const VERSION = '1.1.2';
const DB_VERSION = 5;
const VERSION = '1.1.3';
const DB_VERSION = 6;

public $pluginFile;
public $pluginBasename;
Expand Down Expand Up @@ -62,7 +63,10 @@ class Core
'feeds' => true
),
'supports' => array('title', 'editor', 'thumbnail', 'publicize', 'author', 'revisions'),
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'capability_type' => array('einsatzbericht', 'einsatzberichte'),
'map_meta_cap' => true,
'capabilities' => array(
Expand Down Expand Up @@ -269,6 +273,7 @@ private function addHooks()
register_deactivation_hook($this->pluginFile, array($this, 'onDeactivation'));
add_filter('posts_where', array($this, 'postsWhere'), 10, 2);
add_action('widgets_init', array($this, 'registerWidgets'));
add_filter('user_has_cap', array($this, 'userHasCap'), 10, 4);
}

/**
Expand All @@ -287,12 +292,6 @@ public function onActivation()

// Permalinks aktualisieren
flush_rewrite_rules();

// Rechte für Administratoren setzen
$role_obj = get_role('administrator');
foreach ($this->getCapabilities() as $cap) {
$role_obj->add_cap($cap, true);
}
}

/**
Expand All @@ -319,6 +318,7 @@ public function onInit()

public function onPluginsLoaded()
{
load_plugin_textdomain('einsatzverwaltung');
$this->maybeUpdate();
}

Expand Down Expand Up @@ -515,6 +515,36 @@ public function getCapabilities()
);
}

/**
* Prüft und vergibt Benutzerrechte zur Laufzeit
*
* @param array $allcaps Effektive Nutzerrechte
* @param array $caps Die angefragten Nutzerrechte
* @param array $args Zusätzliche Parameter wie Objekt-ID
* @param WP_User $user Benutzerobjekt
*
* @return array Die gefilterten oder erweiterten Nutzerrechte
*/
public function userHasCap($allcaps, $caps, $args, $user)
{
$requestedCaps = array_intersect($this->getCapabilities(), $caps);

// Wenn es nicht um Berechtigungen aus der Einsatzverwaltung geht, können wir uns den Rest sparen
if (count($requestedCaps) == 0) {
return $allcaps;
}

// Wenn der Benutzer mindestens einer berechtigten Rolle zugeordnet ist, werden die Berechtigungen erteilt
$allowedUserRoles = array_filter($user->roles, array($this->options, 'isRoleAllowedToEdit'));
if (count($allowedUserRoles) > 0) {
foreach ($requestedCaps as $requestedCap) {
$allcaps[$requestedCap] = 1;
}
}

return $allcaps;
}

private function maybeUpdate()
{
$currentDbVersion = get_option('einsatzvw_db_version', self::DB_VERSION);
Expand Down
1 change: 0 additions & 1 deletion src/einsatzverwaltung-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Options
'einsatzvw_einsatznummer_lfdvorne' => false,
'date_format' => 'd.m.Y',
'time_format' => 'H:i',
'einsatzvw_cap_roles_administrator' => true,
'einsatzvw_list_art_hierarchy' => false,
'einsatzvw_list_ext_link' => false,
'einsatzvw_list_fahrzeuge_link' => false,
Expand Down
22 changes: 10 additions & 12 deletions src/einsatzverwaltung-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public function registerSettings()
$roles = get_editable_roles();
if (!empty($roles)) {
foreach (array_keys($roles) as $role_slug) {
// Administratoren haben immer Zugriff, deshalb ist keine Einstellung nötig
if ('administrator' === $role_slug) {
continue;
}

register_setting(
'einsatzvw_settings',
'einsatzvw_cap_roles_' . $role_slug,
Expand Down Expand Up @@ -532,6 +537,11 @@ public function echoSettingsCapsRoles()
echo "Es konnten keine Rollen gefunden werden.";
} else {
foreach ($roles as $role_slug => $role) {
// Administratoren haben immer Zugriff, deshalb ist keine Einstellung nötig
if ('administrator' === $role_slug) {
continue;
}

$this->echoSettingsCheckbox(
'einsatzvw_cap_roles_' . $role_slug,
translate_user_role($role['name'])
Expand Down Expand Up @@ -564,18 +574,6 @@ public function echoSettingsPage()
echo '<div class="wrap">';
echo '<h1>Einstellungen &rsaquo; Einsatzverwaltung</h1>';

// Berechtigungen aktualisieren
$roles = get_editable_roles();
if (!empty($roles)) {
foreach (array_keys($roles) as $role_slug) {
$role_obj = get_role($role_slug);
$allowed = $this->options->isRoleAllowedToEdit($role_slug);
foreach ($this->core->getCapabilities() as $cap) {
$role_obj->add_cap($cap, $allowed);
}
}
}

// Prüfen, ob Rewrite Slug von einer Seite genutzt wird
$rewriteSlug = $this->options->getRewriteSlug();
$conflictingPage = get_page_by_path($rewriteSlug);
Expand Down
25 changes: 25 additions & 0 deletions src/einsatzverwaltung-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,29 @@ private function updateTo5()
add_option('einsatzvw_rewrite_slug', 'einsaetze');
return true;
}

/**
* Entfernt die Berechtigungen aus den Benutzerrollen und die unnötige Option für Administratoren
*
* @return bool Gibt immer True zurück
*/
private function updateTo6()
{
if (!function_exists('get_editable_roles')) {
require_once(ABSPATH . 'wp-admin/includes/user.php');
}
$roles = get_editable_roles();
if (!empty($roles)) {
foreach (array_keys($roles) as $role_slug) {
$role_obj = get_role($role_slug);
foreach ($this->core->getCapabilities() as $cap) {
error_log("Remove $cap from $role_slug");
$role_obj->remove_cap($cap);
}
}
}

delete_option('einsatzvw_cap_roles_administrator');
return true;
}
}
2 changes: 1 addition & 1 deletion src/einsatzverwaltung.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Einsatzverwaltung
Plugin URI: https://www.abrain.de/software/einsatzverwaltung/
Description: Verwaltung und Darstellung von Einsatzberichten der Feuerwehr und anderer Hilfsorganisationen
Version: 1.1.2
Version: 1.1.3
Author: Andreas Brain
Author URI: https://www.abrain.de
License: GPLv2
Expand Down
15 changes: 12 additions & 3 deletions src/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Contributors: abrain
Donate link: https://www.abrain.de/software/unterstuetzen/
Tags: Feuerwehr, Einsatz, Rettung, Rettungsdienst, THW, HiOrg, Wasserwacht, Bergrettung
Requires at least: 3.4.0
Tested up to: 4.3
Stable tag: 1.1.2
Requires at least: 3.7.0
Tested up to: 4.4
Stable tag: 1.1.3
License: GPLv2
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -66,6 +66,11 @@ Das Du halte ich f&uuml;r die angenehmere Arbeitsgrundlage, aber man darf mich g

== Changelog ==

= 1.1.3 =
* Problem mit Benutzerrechten behoben
* Getestet mit WordPress 4.4
* Mindestanforderung auf WordPress 3.7 angehoben

= 1.1.2 =
* CSV-Import: Ein Leerzeichen in der Spaltenbeschriftung verhinderte den Import dieser Spalte
* Anpassungen f&uuml;r WordPress 4.4: Hierarchie der &Uuml;berschriften korrigiert und neue Labels f&uuml;r Screenreader angelegt
Expand Down Expand Up @@ -227,6 +232,9 @@ Das Du halte ich f&uuml;r die angenehmere Arbeitsgrundlage, aber man darf mich g

== Upgrade Notice ==

= 1.1.3 =
Problem mit Benutzerrechten behoben

= 1.1.2 =
Fehlerbehebung bei der Importfunktion und Anpassungen f&uuml;r WordPress 4.4

Expand Down Expand Up @@ -316,3 +324,4 @@ Kein Upgrade, sondern die erste Version
* Twitter: [@einsatzvw](https://twitter.com/einsatzvw)
* App.net: [@einsatzverwaltung](https://alpha.app.net/einsatzverwaltung)
* Facebook: [Einsatzverwaltung](https://www.facebook.com/einsatzverwaltung/)
* GNU social: [@einsatzverwaltung](https://gnusocial.abrain.de/einsatzverwaltung)
Loading

0 comments on commit 33ee5d5

Please sign in to comment.