Fixed: Fetch member from overview when editing is not possible
This commit is contained in:
parent
6997ff07f1
commit
94fc390fcf
|
@ -22,5 +22,12 @@
|
|||
"require-dev": {
|
||||
"orchestra/testbench": "^5.3",
|
||||
"guzzlehttp/guzzle": "^6.3.1|^7.0"
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Zoomyboy\\LaravelNami\\NamiServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "db3bf1da8c0021b1c212d99c7ebffc7e",
|
||||
"content-hash": "7920005f29b146f7a595ce419682cc13",
|
||||
"packages": [],
|
||||
"packages-dev": [
|
||||
{
|
||||
|
@ -711,16 +711,16 @@
|
|||
},
|
||||
{
|
||||
"name": "laravel/framework",
|
||||
"version": "v7.17.2",
|
||||
"version": "v7.18.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/laravel/framework.git",
|
||||
"reference": "d16ff3a0a66d98e04163456b39c4b7302cf50a40"
|
||||
"reference": "116b508bafd81de97b1c09744445d32a91076b60"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/d16ff3a0a66d98e04163456b39c4b7302cf50a40",
|
||||
"reference": "d16ff3a0a66d98e04163456b39c4b7302cf50a40",
|
||||
"url": "https://api.github.com/repos/laravel/framework/zipball/116b508bafd81de97b1c09744445d32a91076b60",
|
||||
"reference": "116b508bafd81de97b1c09744445d32a91076b60",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -864,7 +864,7 @@
|
|||
"framework",
|
||||
"laravel"
|
||||
],
|
||||
"time": "2020-06-24T13:11:25+00:00"
|
||||
"time": "2020-06-30T13:52:36+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/commonmark",
|
||||
|
@ -1212,20 +1212,20 @@
|
|||
},
|
||||
{
|
||||
"name": "myclabs/deep-copy",
|
||||
"version": "1.9.5",
|
||||
"version": "1.10.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/myclabs/DeepCopy.git",
|
||||
"reference": "b2c28789e80a97badd14145fda39b545d83ca3ef"
|
||||
"reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/b2c28789e80a97badd14145fda39b545d83ca3ef",
|
||||
"reference": "b2c28789e80a97badd14145fda39b545d83ca3ef",
|
||||
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/969b211f9a51aa1f6c01d1d2aef56d3bd91598e5",
|
||||
"reference": "969b211f9a51aa1f6c01d1d2aef56d3bd91598e5",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1"
|
||||
"php": "^7.1 || ^8.0"
|
||||
},
|
||||
"replace": {
|
||||
"myclabs/deep-copy": "self.version"
|
||||
|
@ -1256,20 +1256,26 @@
|
|||
"object",
|
||||
"object graph"
|
||||
],
|
||||
"time": "2020-01-17T21:11:47+00:00"
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-06-29T13:22:24+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
"version": "2.35.0",
|
||||
"version": "2.36.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/briannesbitt/Carbon.git",
|
||||
"reference": "4b9bd835261ef23d36397a46a76b496a458305e5"
|
||||
"reference": "d0b65958d9942fd1b501fdb0800c67e8323aa08d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/4b9bd835261ef23d36397a46a76b496a458305e5",
|
||||
"reference": "4b9bd835261ef23d36397a46a76b496a458305e5",
|
||||
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/d0b65958d9942fd1b501fdb0800c67e8323aa08d",
|
||||
"reference": "d0b65958d9942fd1b501fdb0800c67e8323aa08d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1281,9 +1287,10 @@
|
|||
"require-dev": {
|
||||
"doctrine/orm": "^2.7",
|
||||
"friendsofphp/php-cs-fixer": "^2.14 || ^3.0",
|
||||
"kylekatarnls/multi-tester": "^1.1",
|
||||
"kylekatarnls/multi-tester": "^2.0",
|
||||
"phpmd/phpmd": "^2.8",
|
||||
"phpstan/phpstan": "^0.11",
|
||||
"phpstan/extension-installer": "^1.0",
|
||||
"phpstan/phpstan": "^0.12.30",
|
||||
"phpunit/phpunit": "^7.5 || ^8.0",
|
||||
"squizlabs/php_codesniffer": "^3.4"
|
||||
},
|
||||
|
@ -1300,6 +1307,11 @@
|
|||
"providers": [
|
||||
"Carbon\\Laravel\\ServiceProvider"
|
||||
]
|
||||
},
|
||||
"phpstan": {
|
||||
"includes": [
|
||||
"extension.neon"
|
||||
]
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -1339,7 +1351,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2020-05-24T18:27:52+00:00"
|
||||
"time": "2020-06-25T20:20:01+00:00"
|
||||
},
|
||||
{
|
||||
"name": "opis/closure",
|
||||
|
@ -2460,20 +2472,20 @@
|
|||
},
|
||||
{
|
||||
"name": "psr/http-client",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/php-fig/http-client.git",
|
||||
"reference": "496a823ef742b632934724bf769560c2a5c7c44e"
|
||||
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/php-fig/http-client/zipball/496a823ef742b632934724bf769560c2a5c7c44e",
|
||||
"reference": "496a823ef742b632934724bf769560c2a5c7c44e",
|
||||
"url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
|
||||
"reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.0",
|
||||
"php": "^7.0 || ^8.0",
|
||||
"psr/http-message": "^1.0"
|
||||
},
|
||||
"type": "library",
|
||||
|
@ -2505,7 +2517,7 @@
|
|||
"psr",
|
||||
"psr-18"
|
||||
],
|
||||
"time": "2018-10-30T23:29:13+00:00"
|
||||
"time": "2020-06-29T06:28:15+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-message",
|
||||
|
@ -3015,20 +3027,20 @@
|
|||
},
|
||||
{
|
||||
"name": "sebastian/diff",
|
||||
"version": "4.0.1",
|
||||
"version": "4.0.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/diff.git",
|
||||
"reference": "3e523c576f29dacecff309f35e4cc5a5c168e78a"
|
||||
"reference": "1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/3e523c576f29dacecff309f35e4cc5a5c168e78a",
|
||||
"reference": "3e523c576f29dacecff309f35e4cc5a5c168e78a",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113",
|
||||
"reference": "1e90b4cf905a7d06c420b1d2e9d11a4dc8a13113",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.3"
|
||||
"php": "^7.3 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.0",
|
||||
|
@ -3073,7 +3085,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2020-05-08T05:01:12+00:00"
|
||||
"time": "2020-06-30T04:46:02+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/environment",
|
||||
|
|
37
src/Api.php
37
src/Api.php
|
@ -2,7 +2,9 @@
|
|||
|
||||
namespace Zoomyboy\LaravelNami;
|
||||
|
||||
use Log;
|
||||
use App\Conf;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Nami\Exceptions\TooManyLoginAttemptsException;
|
||||
use App\Nami\Interfaces\UserResolver;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
@ -68,7 +70,25 @@ class Api {
|
|||
}
|
||||
|
||||
public function member($groupId, $memberId) {
|
||||
return $this->http()->get(self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId)->json()['data'];
|
||||
$url = self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/'.$memberId;
|
||||
$response = $this->http()->get($url);
|
||||
|
||||
Log::debug('Member Request '.$memberId, [
|
||||
'url' => $url,
|
||||
'response' => $response->body(),
|
||||
'json' => $response->json()
|
||||
]);
|
||||
|
||||
if ($response->json()['success'] === true) {
|
||||
return $response->json()['data'];
|
||||
}
|
||||
|
||||
|
||||
if(Str::startsWith($response['message'], 'Access denied')) {
|
||||
return $this->singleMemberFallback($groupId, $memberId);
|
||||
}
|
||||
|
||||
return $response->json()['data'];
|
||||
}
|
||||
|
||||
public function hasGroup($groupId): bool {
|
||||
|
@ -112,6 +132,21 @@ class Api {
|
|||
});
|
||||
}
|
||||
|
||||
private function singleMemberFallback($groupId, $memberId) {
|
||||
$url = self::$url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$groupId.'/flist';
|
||||
$response = $this->http()->get($url);
|
||||
|
||||
$member = collect($response['data'])->first(function($member) use ($memberId) {
|
||||
return $member['id'] == $memberId;
|
||||
});
|
||||
|
||||
$member = collect($member)->mapWithKeys(function($value, $key) {
|
||||
return [ str_replace('entries_', '', $key) => $value ];
|
||||
});
|
||||
|
||||
return $member->toArray();
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
public function fees() {
|
||||
|
|
|
@ -7,11 +7,18 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class Member extends Model {
|
||||
|
||||
public $geschlechtMaps = [
|
||||
'männlich' => 19,
|
||||
'weiblich' => 20,
|
||||
'keine Angabe' => 23
|
||||
];
|
||||
|
||||
protected static $overviewAttributes = [
|
||||
'vorname' => 'firstname',
|
||||
'nachname' => 'lastname',
|
||||
'spitzname' => 'nickname',
|
||||
'staatsangehoerigkeitText' => 'other_country',
|
||||
'staatangehoerigkeitText' => 'other_country',
|
||||
'strasse' => 'address',
|
||||
'nameZusatz' => 'further_address',
|
||||
'plz' => 'zip',
|
||||
|
@ -22,6 +29,7 @@ class Member extends Model {
|
|||
'telefon3' => 'work_phone',
|
||||
'telefax' => 'fax',
|
||||
'email' => 'email',
|
||||
'geschlecht' => 'geschlecht_text',
|
||||
'geschlechtId' => 'gender_id',
|
||||
'emailVertretungsberechtigter' => 'email_parents',
|
||||
'staatsangehoerigkeitId' => 'nationality_id',
|
||||
|
@ -58,4 +66,8 @@ class Member extends Model {
|
|||
return $this->attributes['gender_id'] == Gender::getNullValue() ? null : $this->attributes['gender_id'];
|
||||
}
|
||||
|
||||
public function setGeschlechtTextAttribute($v) {
|
||||
$this->attributes['gender_id'] = data_get($this->geschlechtMaps, $v, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use Zoomyboy\LaravelNami\Group;
|
|||
class PullMemberTest extends TestCase
|
||||
{
|
||||
public $groupsResponse = '{"success":true,"data":[{"descriptor":"Group","name":"","representedClass":"de.iconcept.nami.entity.org.Gruppierung","id":103}],"responseType":"OK"}';
|
||||
public $unauthorizedResponse = '{"success":false,"data":null,"responseType":"EXCEPTION","message":"Access denied - no right for requested operation","title":"Exception"}';
|
||||
|
||||
public function dataProvider() {
|
||||
return [
|
||||
|
@ -38,6 +39,24 @@ class PullMemberTest extends TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function overviewDataProvider() {
|
||||
return [
|
||||
'firstname' => ['firstname', ['Max', 'Jane']],
|
||||
'lastname' => ['lastname', ['Nach1', 'Nach2']],
|
||||
'nickname' => ['nickname', ['spitz1', null]],
|
||||
'other_country' => ['other_country', ['deutsch', null]],
|
||||
'main_phone' => ['main_phone', ['+49888', '+49668']],
|
||||
'mobile_phone' => ['mobile_phone', ['+49176', '+49172']],
|
||||
'work_phone' => ['work_phone', ['+11111', '+22222']],
|
||||
'fax' => ['fax', ['+55111', '+55222']],
|
||||
'email' => ['email', ['test@example.com', 'test2@example.com']],
|
||||
'email_parents' => ['email_parents', ['testp@example.com', 'test2p@example.com']],
|
||||
'gender_id' => ['gender_id', [19, null]],
|
||||
'birthday' => ['birthday', ['1991-06-20', '1984-01-17']],
|
||||
'joined_at' => ['joined_at', ['2005-05-01', '2003-11-17']],
|
||||
];
|
||||
}
|
||||
|
||||
public function relationProvider() {
|
||||
return [
|
||||
'firstname' => ['firstname', ['Max', 'Jane']],
|
||||
|
@ -112,4 +131,25 @@ class PullMemberTest extends TestCase
|
|||
Http::assertSentCount(6);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider overviewDataProvider
|
||||
*/
|
||||
public function test_get_a_member_from_overview_with_no_rights($key, $values) {
|
||||
Http::fake(array_merge($this->login(), [
|
||||
'https://nami.dpsg.de/ica/rest/nami/gruppierungen/filtered-for-navigation/gruppierung/node/root' => Http::response($this->groupsResponse, 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/16' => Http::response($this->unauthorizedResponse, 200),
|
||||
'https://nami.dpsg.de/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/103/flist' => Http::response($this->fakeJson('member_overview.json'), 200)
|
||||
]));
|
||||
|
||||
$this->setCredentials();
|
||||
|
||||
Nami::login();
|
||||
|
||||
$group = Nami::group(103);
|
||||
|
||||
$this->assertEquals($values[0], $group->member(16)->{$key});
|
||||
|
||||
Http::assertSentCount(5);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,45 @@
|
|||
"success": true,
|
||||
"data": [
|
||||
{
|
||||
"id": 16
|
||||
"id": 16,
|
||||
"entries_ersteTaetigkeitId":null,
|
||||
"entries_genericField1":"",
|
||||
"entries_version":58,
|
||||
"entries_telefon3":"+11111",
|
||||
"entries_telefon2":"+49176",
|
||||
"entries_telefon1":"+49888",
|
||||
"descriptor":"Nach1, Max",
|
||||
"entries_id":16,
|
||||
"entries_staatsangehoerigkeit":"deutsch",
|
||||
"representedClass":"de.iconcept.nami.entity.mitglied.Mitglied",
|
||||
"entries_rover":"",
|
||||
"entries_pfadfinder":"",
|
||||
"entries_mitgliedsNummer":90166,
|
||||
"entries_wiederverwendenFlag":false,
|
||||
"entries_ersteUntergliederungId":null,
|
||||
"entries_rowCssClass":" ",
|
||||
"entries_vorname":"Max",
|
||||
"entries_woelfling":"",
|
||||
"entries_beitragsarten":"",
|
||||
"entries_stufe":"Wölfling",
|
||||
"entries_email":"test@example.com",
|
||||
"entries_konfession":"",
|
||||
"entries_fixBeitrag":"",
|
||||
"entries_emailVertretungsberechtigter":"testp@example.com",
|
||||
"entries_lastUpdated":"2020-06-28 02:15:24",
|
||||
"entries_status":"Aktiv",
|
||||
"entries_jungpfadfinder":"",
|
||||
"entries_mglType":"Mitglied",
|
||||
"entries_kontoverbindung":"",
|
||||
"entries_geschlecht":"männlich",
|
||||
"entries_spitzname":"spitz1",
|
||||
"entries_geburtsDatum":"1991-06-20 00:00:00",
|
||||
"entries_staatangehoerigkeitText":"deutsch",
|
||||
"entries_nachname":"Nach1",
|
||||
"entries_eintrittsdatum":"2005-05-01 00:00:00",
|
||||
"entries_austrittsDatum":"",
|
||||
"entries_genericField2":"",
|
||||
"entries_telefax":"+55111"
|
||||
},
|
||||
{
|
||||
"id": 17
|
||||
|
|
Loading…
Reference in New Issue