Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from uostream #1

Merged
merged 5 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
/.env.*.local
/config/secrets/prod/prod.decrypt.private.php
/public/bundles/
/var/
/var/*
!/var/.gitkeep
/vendor/
###< symfony/framework-bundle ###

Expand Down Expand Up @@ -32,7 +33,8 @@

###> Docker ###
docker-compose.*.yml
/docker/logs
/docker/logs/nginx/*
!/docker/logs/nginx/.gitkeep
/docker/nginx/ssl/certs/*
!/docker/nginx/ssl/certs/.gitkeep
/docker/nginx/ssl/private/*
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- WIP: organization members (#56)

## [0.1.2] - 2020-04-27
### Added
- Add ability to unlink OAuth integration from user profile page (#106)
- Uptime Robot monitor (#102 & #103)

### Changes
- GitLab API: Show all user's packages and order by last activity (#104)

### Fixed
- Handle oauth errors during registration (#92)
- Handle errors when fetching repos from provider (#94)
- Fix last package version detection mechanism (#99)
- Fix support for packages with slash in version name (#101)
- Fix number of days for /admin/stats (#108)
- Fix recent webhook requests view model (#110)
- Allow *.php named packages to be found (#111)

## [0.1.1] - 2020-04-22
### BC break
- user email is now change to lowercase with migration
Expand Down
4 changes: 0 additions & 4 deletions ansible/roles/nginx/templates/nginx-ssl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ http {
internal;
}

location ~ \.php$ {
return 404;
}

error_log "{{ nginx_app_error_log }}";
access_log "{{ nginx_app_access_log }}" main;
}
Expand Down
4 changes: 0 additions & 4 deletions ansible/roles/nginx/templates/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ http {
internal;
}

location ~ \.php$ {
return 404;
}

error_log "{{ nginx_app_error_log }}";
access_log "{{ nginx_app_access_log }}" main;
}
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:

app:
restart: always
image: buddy/repman:0.1.1
image: buddy/repman:0.1.2
command: >
bash -c 'bin/console cache:clear &&
bin/console cache:warmup &&
Expand All @@ -31,7 +31,7 @@ services:

consumer:
restart: always
image: buddy/repman:0.1.1
image: buddy/repman:0.1.2
command: ['bin/console', 'messenger:consume', 'async', '--limit=500']
env_file: .env.docker
volumes:
Expand All @@ -41,7 +41,7 @@ services:

cron:
restart: always
image: buddy/repman:0.1.1
image: buddy/repman:0.1.2
command: >
bash -c 'echo "*/5 * * * * /app/bin/console repman:proxy:sync-releases" | crontab - && crond -f -L /dev/stdout'
env_file: .env.docker
Expand Down
Empty file added docker/logs/nginx/.gitkeep
Empty file.
4 changes: 0 additions & 4 deletions docker/nginx/scripts/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ http {
internal;
}

location ~ \.php$ {
return 404;
}

error_log /var/log/nginx/repman_error.log;
access_log /var/log/nginx/repman_access.log main;
}
Expand Down
8 changes: 7 additions & 1 deletion src/Controller/Organization/PackageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ public function packageNew(Organization $organization, Request $request, GithubA
return $response;
}
} catch (HttpException $exception) {
$this->addFlash('danger', sprintf('Failed to fetch repositories (reason: %s). Please try again. If the problem persists, try to remove Repman OAuth application from your provider and try again.', $exception->getMessage()));
$this->addFlash('danger', sprintf(
'Failed to fetch repositories (reason: %s).
Please try again. If the problem persists, try to remove Repman OAuth application
from your provider or unlink %s integration in your Profile and try again.',
$exception->getMessage(),
\ucfirst((string) $type)
));
$form->get('type')->setData(null);
}

Expand Down
51 changes: 35 additions & 16 deletions src/Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,39 @@
use Buddy\Repman\Entity\User;
use Buddy\Repman\Form\Type\User\ChangePasswordType;
use Buddy\Repman\Message\User\ChangePassword;
use Buddy\Repman\Message\User\RemoveOAuthToken;
use Buddy\Repman\Message\User\RemoveUser;
use Buddy\Repman\Message\User\SendConfirmToken;
use Buddy\Repman\Query\User\UserQuery;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

final class UserController extends AbstractController
{
private UserQuery $userQuery;

public function __construct(UserQuery $userQuery)
{
$this->userQuery = $userQuery;
}

/**
* @Route(path="/user", name="user_profile", methods={"GET","POST"})
*/
public function profile(Request $request): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');

/** @var User */
$user = $this->getUser();

$oauthTokens = $this->userQuery->findAllOAuthTokens($this->getUser()->id()->toString());
$form = $this->createForm(ChangePasswordType::class);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');

$this->dispatchMessage(new ChangePassword(
$user->id()->toString(),
$this->getUser()->id()->toString(),
$form->get('plainPassword')->getData()
));
$this->addFlash('success', 'Your password has been changed');
Expand All @@ -43,7 +49,7 @@ public function profile(Request $request): Response

return $this->render('user/profile.html.twig', [
'form' => $form->createView(),
'is_user_confirmed' => $user->isEmailConfirmed(),
'oauth_tokens' => $oauthTokens,
]);
}

Expand All @@ -53,10 +59,7 @@ public function profile(Request $request): Response
public function remove(): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');

/** @var User */
$user = $this->getUser();
$this->dispatchMessage(new RemoveUser($user->id()->toString()));
$this->dispatchMessage(new RemoveUser($this->getUser()->id()->toString()));
$this->addFlash('success', 'User has been successfully removed');

return $this->redirectToRoute('index');
Expand All @@ -68,16 +71,32 @@ public function remove(): Response
public function resendVerificationEmail(): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');

/** @var User */
$user = $this->getUser();

$this->dispatchMessage(new SendConfirmToken(
$user->getEmail(),
$user->emailConfirmToken()
$this->getUser()->getEmail(),
$this->getUser()->emailConfirmToken()
));
$this->addFlash('success', 'Email sent successfully');

return $this->redirectToRoute('user_profile');
}

/**
* @Route(path="/user/remove-oauth-token/{type}", name="user_remove_oauth_token", methods={"DELETE"}, requirements={"type"="github|gitlab|bitbucket|buddy"})
*/
public function removeOAuthToken(string $type): Response
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$this->dispatchMessage(new RemoveOAuthToken($this->getUser()->id()->toString(), $type));
$this->addFlash('success', sprintf('%s has been successfully unlinked.', \ucfirst($type)));

return $this->redirectToRoute('user_profile');
}

protected function getUser(): User
{
/** @var User $user */
$user = parent::getUser();

return $user;
}
}
9 changes: 9 additions & 0 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ public function oauthToken(string $type): ?OAuthToken
return null;
}

public function removeOAuthToken(string $type): void
{
foreach ($this->oauthTokens as $oauthToken) {
if ($oauthToken->isType($type)) {
$this->oauthTokens->removeElement($oauthToken);
}
}
}

/**
* @return Option<string>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Kernel extends BaseKernel
{
use MicroKernelTrait;

public const REPMAN_VERSION = '0.1.1';
public const REPMAN_VERSION = '0.1.2';
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';

public function registerBundles(): iterable
Expand Down
27 changes: 27 additions & 0 deletions src/Message/User/RemoveOAuthToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Buddy\Repman\Message\User;

final class RemoveOAuthToken
{
private string $userId;
private string $type;

public function __construct(string $userId, string $type)
{
$this->userId = $userId;
$this->type = $type;
}

public function userId(): string
{
return $this->userId;
}

public function type(): string
{
return $this->type;
}
}
26 changes: 26 additions & 0 deletions src/MessageHandler/User/RemoveOAuthTokenHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Buddy\Repman\MessageHandler\User;

use Buddy\Repman\Message\User\RemoveOAuthToken;
use Buddy\Repman\Repository\UserRepository;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;

final class RemoveOAuthTokenHandler implements MessageHandlerInterface
{
private UserRepository $users;

public function __construct(UserRepository $users)
{
$this->users = $users;
}

public function __invoke(RemoveOAuthToken $message): void
{
$user = $this->users->getById(Uuid::fromString($message->userId()));
$user->removeOAuthToken($message->type());
}
}
27 changes: 27 additions & 0 deletions src/Query/User/Model/OAuthToken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Buddy\Repman\Query\User\Model;

final class OAuthToken
{
private string $type;
private \DateTimeImmutable $createdAt;

public function __construct(string $type, \DateTimeImmutable $createdAt)
{
$this->type = $type;
$this->createdAt = $createdAt;
}

public function type(): string
{
return $this->type;
}

public function createdAt(): \DateTimeImmutable
{
return $this->createdAt;
}
}
10 changes: 5 additions & 5 deletions src/Query/User/Model/WebhookRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
final class WebhookRequest
{
private string $date;
private string $ip;
private string $userAgent;
private ?string $ip;
private ?string $userAgent;

public function __construct(string $date, string $ip, string $userAgent)
public function __construct(string $date, ?string $ip, ?string $userAgent)
{
$this->date = $date;
$this->ip = $ip;
Expand All @@ -22,12 +22,12 @@ public function date(): string
return $this->date;
}

public function ip(): string
public function ip(): ?string
{
return $this->ip;
}

public function userAgent(): string
public function userAgent(): ?string
{
return $this->userAgent;
}
Expand Down
15 changes: 15 additions & 0 deletions src/Query/User/UserQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Buddy\Repman\Query\User;

use Buddy\Repman\Query\User\Model\OAuthToken;

interface UserQuery
{
/**
* @return OAuthToken[]
*/
public function findAllOAuthTokens(string $userId): array;
}
Loading