Skip to content

Commit 6a07ba7

Browse files
authored
Merge branch 'develop' into composer-superuser-20240914
2 parents ea826c8 + 2a40f05 commit 6a07ba7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+456
-802
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"nyholm/psr7": "^1.5",
3737
"ohanzee/database": "dev-namespaces",
3838
"php-http/curl-client": "^2.2",
39-
"predis/predis": "~1.1",
39+
"predis/predis": "^2.2.2",
4040
"robmorgan/phinx": "~0.11.2",
4141
"sentry/sentry-laravel": "^1.9|^2.11",
4242
"symfony/event-dispatcher": "^5.4",

composer.lock

Lines changed: 13 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
ports:
1616
- "33061:3306"
1717
redis:
18-
image: redis:4-alpine
18+
image: redis:7.2-alpine
1919
platform:
2020
build: .
2121
environment:

src/Ushahidi/Modules/V5/Actions/Post/Commands/UpdatePostCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ public static function fromRequest(int $id, PostRequest $request, Post $current_
9191
? $request->input('base_language') : $current_post->base_language;
9292
$input['published_to'] = $request->has('published_to')
9393
? $request->input('published_to') : $current_post->published_to;
94+
$input['source'] = $current_post->source;
9495
$input['created'] = self::ensureTimestamp($current_post->created);
9596
$input['updated'] = time();
9697

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
3+
namespace Ushahidi\Modules\V5\Actions\Post;
4+
5+
use Ushahidi\Modules\V5\Models\Post\Post;
6+
use Ushahidi\Contracts\Sources;
7+
use Ushahidi\Modules\V5\Http\Resources\LockCollection;
8+
use Ushahidi\Modules\V5\Models\Contact;
9+
use Illuminate\Support\Collection;
10+
use Ushahidi\Modules\V5\Http\Resources\PostValueCollection;
11+
12+
trait HandlePostOnlyParameters
13+
{
14+
public function addHydrateRelationships(Post $post, array $hydrates)
15+
{
16+
foreach ($hydrates as $hydrate) {
17+
switch ($hydrate) {
18+
case 'color':
19+
$post->color = $post->survey ? $post->survey->color : null;
20+
break;
21+
case 'categories':
22+
// $result['categories'] = $post->categories;
23+
break;
24+
case 'completed_stages':
25+
$post->completed_stages = $post->postStages;
26+
27+
break;
28+
case 'post_content':
29+
$post->post_content = $this->getResourcePostContent($post);
30+
break;
31+
case 'translations':
32+
break;
33+
case 'contact':
34+
$post->contact = null;
35+
if ($post->source === Sources::WHATSAPP) {
36+
if ($this->userHasManagePostPermissions()) {
37+
if (isset($post->metadata['contact'])) {
38+
$post->contact = (new Contact)->fill($post->metadata['contact']);
39+
}
40+
} else {
41+
if (isset($post->metadata['contact']['id'])) {
42+
$post->contact = (new Contact)->fill(['id'=>$post->metadata['contact']['id']]);
43+
}
44+
}
45+
}
46+
if ($post->message) {
47+
if ($this->userHasManagePostPermissions()) {
48+
$post->contact = $post->message->contact;
49+
} else {
50+
$post->contact = $post->message->contact->setVisible(["id"]);
51+
}
52+
}
53+
break;
54+
case 'locks':
55+
$post->locks = new LockCollection($post->locks);
56+
break;
57+
58+
case 'source':
59+
$message = $post->message;
60+
$post->source = $post->source ?? ($message && isset($message->type)
61+
? $message->type
62+
: Post::DEFAULT_SOURCE_TYPE);
63+
64+
break;
65+
66+
case 'data_source_message_id':
67+
$post->data_source_message_id = null;
68+
$message = $post->message;
69+
if ($message) {
70+
$post->data_source_message_id = $message->data_source_message_id ?? null;
71+
}
72+
break;
73+
case 'message':
74+
if ($post->message && !$this->userHasManagePostPermissions()) {
75+
$post->message->makeHidden("contact");
76+
}
77+
break;
78+
case 'enabled_languages':
79+
$post->enabled_languages = [
80+
'default' => $post->base_language,
81+
'available' => $post->translations->groupBy('language')->keys()
82+
];
83+
$relations['enabled_languages'] = true;
84+
break;
85+
}
86+
}
87+
return $post;
88+
}
89+
public function hideFieldsUsedByRelationships(Post $post, array $fields = [])
90+
{
91+
foreach ($fields as $field) {
92+
$post->offsetUnset($field);
93+
}
94+
$post->offsetUnset('values_int');
95+
96+
return $post;
97+
}
98+
public function hideUnwantedRelationships(Post $post, array $hydrates)
99+
{
100+
// hide post_content relationships
101+
$post->makeHidden('survey');
102+
$post->makeHidden('valuesVarchar');
103+
$post->makeHidden('valuesInt');
104+
$post->makeHidden('valuesText');
105+
$post->makeHidden('valuesDatetime');
106+
$post->makeHidden('valuesDecimal');
107+
$post->makeHidden('valuesDecimal');
108+
$post->makeHidden('valuesGeometry');
109+
$post->makeHidden('valuesMarkdown');
110+
$post->makeHidden('valuesMedia');
111+
$post->makeHidden('valuesPoint');
112+
$post->makeHidden('valuesRelation');
113+
$post->makeHidden('valuesPostsMedia');
114+
$post->makeHidden('valuesPostsSet');
115+
$post->makeHidden('valuesPostTag');
116+
117+
// hide source relationships
118+
if (!in_array('message', $hydrates)) {
119+
$post->makeHidden('message');
120+
}
121+
122+
// hide completed_stages relationships
123+
$post->makeHidden('postStages');
124+
125+
126+
return $post;
127+
}
128+
129+
private function getResourcePostContent($post)
130+
{
131+
$values = $post->getPostValues(); // Calling method on Post Model
132+
$no_values = $values->count() === 0 ? true : false;
133+
$col = new Collection([
134+
'values' => $values,
135+
'tasks' => $post->survey ? $post->survey->tasks : []
136+
]);
137+
if ($post->survey) {
138+
$post_content = new PostValueCollection($col);
139+
} else {
140+
$post_content = Collection::make([]);
141+
}
142+
return $post_content;
143+
}
144+
145+
public function handleSourceField($post)
146+
{
147+
if (!$post->source) {
148+
$message = $post->message;
149+
$post->source = ($message && isset($message->type)
150+
? $message->type
151+
: Post::DEFAULT_SOURCE_TYPE);
152+
}
153+
return $post;
154+
}
155+
}

0 commit comments

Comments
 (0)