-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
2,362 additions
and
1,446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "composer" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" | ||
- package-ecosystem: "npm" | ||
directory: "/" | ||
schedule: | ||
interval: "weekly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,7 @@ To set up a Träwelling instance you'll need: | |
* [MariaDB](https://mariadb.org/download) (SQLite is used for running tests) | ||
* A local instance of [db-rest v5](https://github.com/derhuerst/db-rest/tree/5) | ||
* [Composer](https://getcomposer.org/download/) | ||
* PHP 8.0 and the following extensions: | ||
* gd | ||
* sodium | ||
* exif | ||
* pdo_mysql | ||
* pdo_sqlite | ||
* PHP 8.0 and the dependencies mentioned in composer.json | ||
|
||
After setting up these, you can clone the repository and install the project's dependencies: | ||
|
||
|
@@ -76,13 +71,10 @@ feature - great; if you don't want to, that's fine, too. | |
|
||
If you add code: | ||
|
||
* If you edit the language files, please check if your change is applicable at least in german. | ||
* If you edit the language files, please check if your change is applicable at least in english. | ||
|
||
* If you work on the front page (see screenshot above), please consider updating the screenshot. | ||
|
||
* Unless you really want to work on Träwelling for a long time, we cannot support more languages. It would be sad to | ||
have half-baked languages that have missing strings after a while. | ||
|
||
|
||
* Please consider adding unit and integration tests, especially if you're adding new features. | ||
|
||
### Translations | ||
|
@@ -93,6 +85,13 @@ international and for this we need you and your language skills. | |
We use a [Weblate instance](https://weblate.bubu1.eu/projects/trawelling/) to manage the translations. There you can add | ||
new translations and correct mistakes. | ||
|
||
### Security | ||
|
||
If you have identified a security issue, please refrain from directly creating an issue or PullRequest so that the | ||
vulnerability is not exploited. | ||
|
||
Instead, please contact [email protected] or use other [contact methods](https://traewelling.de/security.txt). | ||
|
||
## License | ||
|
||
We are using the [Affero General Public License](/LICENSE) ([why?](http://www.gnu.org/licenses/why-affero-gpl)) - you | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\API\v1; | ||
|
||
use App\Exceptions\AlreadyFollowingException; | ||
use App\Exceptions\IdenticalModelException; | ||
use App\Exceptions\PermissionException; | ||
use App\Http\Controllers\API\ResponseController; | ||
use App\Http\Controllers\Backend\User\FollowController as FollowBackend; | ||
use App\Http\Controllers\Backend\User\FollowController as SettingsBackend; | ||
use App\Http\Controllers\UserController as UserBackend; | ||
use App\Http\Resources\UserResource; | ||
use App\Models\Follow; | ||
use App\Models\User; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Resources\Json\AnonymousResourceCollection; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Validation\Rule; | ||
|
||
class FollowController extends ResponseController | ||
{ | ||
|
||
public static function createFollow(Request $request, FollowController $instance): JsonResponse { | ||
$validated = $request->validate(['userId' => ['required', 'exists:users,id']]); | ||
$userToFollow = User::find($validated['userId']); | ||
|
||
try { | ||
$createFollowResponse = UserBackend::createOrRequestFollow(Auth::user(), $userToFollow); | ||
} catch (AlreadyFollowingException) { | ||
return $instance->sendv1Error(['message' => __('controller.user.follow-error')], 409); | ||
} catch (IdenticalModelException) { | ||
abort(409); | ||
} | ||
|
||
return $instance->sendv1Response(new UserResource($createFollowResponse), 204); | ||
} | ||
|
||
public static function destroyFollow(Request $request, FollowController $instance): JsonResponse { | ||
$validated = $request->validate(['userId' => ['required', 'exists:users,id']]); | ||
$userToUnfollow = User::find($validated['userId']); | ||
|
||
$destroyFollowResponse = UserBackend::destroyFollow(Auth::user(), $userToUnfollow); | ||
if ($destroyFollowResponse === false) { | ||
return $instance->sendv1Error(['message' => __('controller.user.follow-404')], 409); | ||
} | ||
|
||
$userToUnfollow->fresh(); | ||
return $instance->sendv1Response(new UserResource($userToUnfollow)); | ||
|
||
} | ||
|
||
public function getFollowers(): AnonymousResourceCollection { | ||
$followersResponse = FollowBackend::getFollowers(user: auth()->user()); | ||
return UserResource::collection($followersResponse); | ||
} | ||
|
||
public function getFollowRequests(): AnonymousResourceCollection { | ||
$followRequestResponse = FollowBackend::getFollowRequests(user: auth()->user()); | ||
return UserResource::collection($followRequestResponse); | ||
} | ||
|
||
public function getFollowings(): AnonymousResourceCollection { | ||
$followingResponse = FollowBackend::getFollowings(user: auth()->user()); | ||
return UserResource::collection($followingResponse); | ||
} | ||
|
||
public function removeFollower(Request $request): void { | ||
$validated = $request->validate([ | ||
'userId' => [ | ||
'required', | ||
Rule::in(auth()->user()->followers->pluck('user_id')), | ||
] | ||
]); | ||
|
||
$follow = Follow::where('user_id', $validated['userId']) | ||
->where('follow_id', auth()->user()->id) | ||
->firstOrFail(); | ||
|
||
try { | ||
$removeResponse = FollowBackend::removeFollower(follow: $follow, user: auth()->user()); | ||
} catch (PermissionException) { | ||
abort(403); | ||
} | ||
|
||
if ($removeResponse === true) { | ||
abort(204); | ||
} | ||
abort(500); | ||
} | ||
|
||
public function approveFollowRequest(Request $request) { | ||
$validated = $request->validate([ | ||
'userId' => [ | ||
'required', | ||
Rule::in(auth()->user()->followRequests->pluck('user_id')) | ||
] | ||
]); | ||
|
||
try { | ||
FollowBackend::approveFollower(auth()->user()->id, $validated['userId']); | ||
abort(204); | ||
} catch (ModelNotFoundException) { | ||
abort(404); | ||
} catch (AlreadyFollowingException $exception) { | ||
report($exception); | ||
} | ||
abort(500); | ||
} | ||
|
||
public function rejectFollowRequest(Request $request) { | ||
$validated = $request->validate([ | ||
'userId' => [ | ||
'required', | ||
Rule::in(auth()->user()->followRequests->pluck('user_id')) | ||
] | ||
]); | ||
try { | ||
FollowBackend::rejectFollower(auth()->user()->id, $validated['userId']); | ||
abort(204); | ||
} catch (ModelNotFoundException) { | ||
abort(404); | ||
} | ||
abort(500); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.