Issues (19)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Http/Controllers/DiscussionController.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Faithgen\Discussions\Http\Controllers;
4
5
use Faithgen\Discussions\Http\Requests\CreateRequest;
6
use Faithgen\Discussions\Http\Requests\DeleteImageRequest;
7
use Faithgen\Discussions\Http\Requests\DeleteRequest;
8
use Faithgen\Discussions\Http\Requests\UpdateRequest;
9
use Faithgen\Discussions\Http\Resources\Discussion as DiscussionResource;
10
use Faithgen\Discussions\Http\Resources\DiscussionList;
11
use Faithgen\Discussions\Models\Discussion;
12
use Faithgen\Discussions\Services\DiscussionService;
13
use FaithGen\SDK\Helpers\CommentHelper;
14
use FaithGen\SDK\Http\Requests\CommentRequest;
15
use FaithGen\SDK\Models\Image;
16
use FaithGen\SDK\Models\Ministry;
17
use FaithGen\SDK\Models\User;
18
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
19
use Illuminate\Http\Request;
20
use Illuminate\Routing\Controller;
21
use InnoFlash\LaraStart\Helper;
22
use InnoFlash\LaraStart\Http\Requests\IndexRequest;
23
use InnoFlash\LaraStart\Traits\APIResponses;
24
25
class DiscussionController extends Controller
26
{
27
    use APIResponses;
28
    use AuthorizesRequests;
29
30
    /**
31
     * @var DiscussionService
32
     */
33
    private DiscussionService $discussionService;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
34
35
    /**
36
     * DiscussionController constructor.
37
     *
38
     * @param DiscussionService $discussionService
39
     */
40
    public function __construct(DiscussionService $discussionService)
41
    {
42
        $this->discussionService = $discussionService;
43
    }
44
45
    /**
46
     * Fetches the discussions.
47
     *
48
     * @param IndexRequest $request
49
     *
50
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
51
     */
52
    public function index(IndexRequest $request)
53
    {
54
        $acceptableTypes = [Ministry::class, \App\Models\Ministry::class, User::class];
55
56
        $discussions = auth()->user()
57
            ->ministryDiscussions()
58
            ->latest()
59
            ->approved()
60
            ->with(['discussable.image'])
61
            ->exclude(['discussion'])
62
            ->withCount('comments')
63
            ->where(function ($query) use ($request, $acceptableTypes) {
64
                return $query->search(['url'], $request->filter_text)
65
                    ->orWhereHasMorph('discussable', $acceptableTypes,
66
                        fn ($discussable) => $discussable->where('name', 'LIKE', '%'.$request->filter_text.'%'));
67
            })->paginate(Helper::getLimit($request));
68
69
        DiscussionList::wrap('discussions');
70
71
        return DiscussionList::collection($discussions);
72
    }
73
74
    /**
75
     * Creates a discussion.
76
     *
77
     * @param CreateRequest $request
78
     *
79
     * @return \Illuminate\Http\JsonResponse
80
     */
81
    public function create(CreateRequest $request)
82
    {
83
        if (count($request->validated()) === 1) {
84
            abort(422, 'You can not send a blank discussion!');
85
        }
86
87
        return $this->discussionService->createFromParent($request->validated(),
88
            'Discussion created successfully!'.(auth('web')->user() ? ' Waiting for admin to approve.' : ''));
89
    }
90
91
    /**
92
     * Deletes the discussion.
93
     *
94
     * @param Discussion $discussion
95
     * @param DeleteRequest $request
96
     *
97
     * @return mixed
98
     */
99
    public function destroy(Discussion $discussion, DeleteRequest $request)
100
    {
101
        try {
102
            $discussion->delete();
103
104
            return $this->successResponse('Discussion deleted successfully');
105
        } catch (\Exception $e) {
106
            abort(500, $e->getMessage());
107
        }
108
    }
109
110
    /**
111
     * Updates the discussion.
112
     *
113
     * @param UpdateRequest $request
114
     *
115
     * @return \Illuminate\Http\JsonResponse|mixed
116
     */
117
    public function update(UpdateRequest $request)
118
    {
119
        return $this->discussionService->update($request->validated(), 'Discussion updated successfully!');
120
    }
121
122
    /**
123
     * Shows the discussion in detail.
124
     *
125
     * @param Discussion $discussion
126
     *
127
     * @return DiscussionResource
128
     * @throws \Illuminate\Auth\Access\AuthorizationException
129
     */
130
    public function show(Discussion $discussion)
131
    {
132
        $this->authorize('view', $discussion);
133
134
        $discussion->load([
135
            'images',
136
            'discussable.image',
137
        ]);
138
139
        DiscussionResource::withoutWrapping();
140
141
        return new DiscussionResource($discussion);
142
    }
143
144
    /**
145
     * Fetch discussion comments.
146
     *
147
     * @param Request $request
148
     * @param Discussion $discussion
149
     *
150
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
151
     * @throws \Illuminate\Auth\Access\AuthorizationException
152
     */
153
    public function comments(Request $request, Discussion $discussion)
154
    {
155
        $this->authorize('view', $discussion);
156
157
        return CommentHelper::getComments($discussion, $request);
158
    }
159
160
    /**
161
     * Creates a comment for a discussion.
162
     *
163
     * @param CommentRequest $request
164
     *
165
     * @return \Illuminate\Http\JsonResponse
166
     */
167
    public function comment(CommentRequest $request)
168
    {
169
        return CommentHelper::createComment($this->discussionService->getDiscussion(), $request);
170
    }
171
172
    /**
173
     * Deletes an image from a discussion.
174
     *
175
     * @param DeleteImageRequest $request
176
     * @param Discussion $discussion
177
     * @param Image $image
178
     *
179
     * @return mixed
180
     * @throws \Exception
181
     */
182
    public function deleteImage(DeleteImageRequest $request, Discussion $discussion, Image $image)
183
    {
184
        try {
185
            unlink(storage_path('app/public/discussions/100-100/'.$image->name));
186
            unlink(storage_path('app/public/discussions/original/'.$image->name));
187
        } catch (\Exception $e) {
188
            //abort(500, $e->getMessage());
189
        } finally {
190
            $image->delete();
191
192
            return $this->successResponse('Image deleted!');
193
        }
194
    }
195
196
    /**
197
     * Changes the discussion status.
198
     *
199
     * @param Discussion $discussion
200
     *
201
     * @return mixed
202
     * @throws \Illuminate\Auth\Access\AuthorizationException
203
     */
204
    public function toggleStatus(Discussion $discussion)
205
    {
206
        $this->authorize('update', $discussion);
207
208
        $discussion->approved = ! $discussion->approved;
209
        $discussion->save();
210
211
        return $this->successResponse('Discussion state changed');
212
    }
213
214
    /**
215
     * Get the discussions raised by a user.
216
     *
217
     * @param $user_id
218
     * @param IndexRequest $request
219
     *
220
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
221
     */
222
    public function userDiscussions($user_id, IndexRequest $request)
223
    {
224
        $userModel = config('auth.providers.users.model');
225
        $user = $userModel::findOrFail($user_id);
226
227
        $discussions = $user->discussions()
228
            ->latest()
229
            ->with(['discussable.image'])
230
            ->exclude(['discussion'])
231
            ->withCount('comments')
232
            ->search(['url'], $request->filter_text)
233
            ->where('ministry_id', auth()->user()->id)
234
            ->where(function ($query) use ($user) {
235
                if (auth('web')->user() && $user->id !== auth('web')->user()->id) {
236
                    return $query->approved();
237
                }
238
239
                return $query;
240
            })->paginate(Helper::getLimit($request));
241
242
        DiscussionList::wrap('discussions');
243
244
        return DiscussionList::collection($discussions);
245
    }
246
}
247