From 79be72340c19872487d7a3130bf88e4557f05f71 Mon Sep 17 00:00:00 2001 From: Khanh Nguyen <119989010+ndkhanh-axonivy@users.noreply.github.com> Date: Wed, 24 Jul 2024 15:32:48 +0700 Subject: [PATCH] Feature/marp 721 fix nginx cannot redirect user after authenticated from GitHub (#51) --- .github/workflows/docker-build.yml | 6 ++++ marketplace-build/.env | 5 ++- marketplace-build/config/nginx/nginx.conf | 7 ++-- marketplace-build/docker-compose.yml | 3 ++ marketplace-build/release/.env | 5 ++- marketplace-build/release/docker-compose.yml | 3 ++ marketplace-build/release/sprint-compose.yml | 3 ++ .../market/controller/FeedbackController.java | 6 ++-- .../market/controller/OAuth2Controller.java | 2 ++ .../src/main/resources/application.properties | 6 ++-- .../market/service/SchedulingTasksTest.java | 6 ++-- marketplace-ui/src/app/auth/auth.service.ts | 5 +-- .../product-detail-feedback.component.spec.ts | 7 ---- .../product-detail-feedback.component.ts | 35 +------------------ .../product-feedback.service.spec.ts | 18 ---------- .../product-feedback.service.ts | 9 +++-- .../add-feedback-dialog.component.html | 2 +- .../product-star-rating.service.ts | 5 +-- .../product-detail.component.ts | 35 ++++++++++++++----- .../star-rating/star-rating.component.html | 2 +- .../star-rating/star-rating.component.ts | 1 + .../environments/environment.development.ts | 2 +- .../src/environments/environment.ts | 2 +- marketplace-ui/src/styles.scss | 2 +- 24 files changed, 83 insertions(+), 94 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 8537e9ede..a4a4b25ea 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -36,6 +36,9 @@ jobs: SERVICE_PASSWORD: ${{ secrets.SERVICE_PASSWORD }} MONGODB_DATABASE: ${{ secrets.MONGODB_DATABASE }} GH_TOKEN: ${{ secrets.GH_TOKEN }} + MARKET_GITHUB_OAUTH_APP_CLIENT_ID: ${{ secrets.MARKET_GITHUB_OAUTH_APP_CLIENT_ID }} + MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET: ${{ secrets.MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET }} + MARKET_JWT_SECRET_KEY: ${{ secrets.MARKET_JWT_SECRET_KEY }} run: | sed -i "s/^MONGODB_INITDB_ROOT_USERNAME=.*$/MONGODB_INITDB_ROOT_USERNAME=$ROOT_USERNAME/" $ENV_FILE sed -i "s/^MONGODB_INITDB_ROOT_PASSWORD=.*$/MONGODB_INITDB_ROOT_PASSWORD=$ROOT_PASSWORD/" $ENV_FILE @@ -44,6 +47,9 @@ jobs: sed -i "s/^SERVICE_MONGODB_USER=.*$/SERVICE_MONGODB_USER=$SERVICE_USERNAME/" $ENV_FILE sed -i "s/^SERVICE_MONGODB_PASSWORD=.*$/SERVICE_MONGODB_PASSWORD=$SERVICE_PASSWORD/" $ENV_FILE sed -i "s/^MARKET_GITHUB_TOKEN=.*$/MARKET_GITHUB_TOKEN=$GH_TOKEN/" $ENV_FILE + sed -i "s/^MARKET_GITHUB_OAUTH_APP_CLIENT_ID=.*$/MARKET_GITHUB_OAUTH_APP_CLIENT_ID=$MARKET_GITHUB_OAUTH_APP_CLIENT_ID/" $ENV_FILE + sed -i "s/^MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=.*$/MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=$MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET/" $ENV_FILE + sed -i "s/^MARKET_JWT_SECRET_KEY=.*$/MARKET_JWT_SECRET_KEY=$MARKET_JWT_SECRET_KEY/" $ENV_FILE - name: Build and bring up containers without cache working-directory: ./marketplace-build diff --git a/marketplace-build/.env b/marketplace-build/.env index 8f0271811..c08dfe92a 100644 --- a/marketplace-build/.env +++ b/marketplace-build/.env @@ -5,4 +5,7 @@ SERVICE_MONGODB_USER= SERVICE_MONGODB_PASSWORD= SERVICE_MONGODB_DATABASE= MARKET_GITHUB_TOKEN= -MARKETPLACE_INSTALLATION_URL= \ No newline at end of file +MARKETPLACE_INSTALLATION_URL= +MARKET_GITHUB_OAUTH_APP_CLIENT_ID= +MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET= +MARKET_JWT_SECRET_KEY= \ No newline at end of file diff --git a/marketplace-build/config/nginx/nginx.conf b/marketplace-build/config/nginx/nginx.conf index e8704aa0a..3f23ab6df 100644 --- a/marketplace-build/config/nginx/nginx.conf +++ b/marketplace-build/config/nginx/nginx.conf @@ -1,16 +1,15 @@ -events{} +events {} http { - # include the default mime.types to map file extensions to MIME types include /etc/nginx/mime.types; server { - root /usr/share/nginx/html; + root /usr/share/nginx/html; index index.html; location / { try_files $uri $uri/ /index.html; } } -} +} \ No newline at end of file diff --git a/marketplace-build/docker-compose.yml b/marketplace-build/docker-compose.yml index 71682a2fd..542536546 100644 --- a/marketplace-build/docker-compose.yml +++ b/marketplace-build/docker-compose.yml @@ -42,6 +42,9 @@ services: - MONGODB_USERNAME=${SERVICE_MONGODB_USER} - MONGODB_PASSWORD=${SERVICE_MONGODB_PASSWORD} - MARKET_GITHUB_TOKEN=${MARKET_GITHUB_TOKEN} + - MARKET_GITHUB_OAUTH_APP_CLIENT_ID=${MARKET_GITHUB_OAUTH_APP_CLIENT_ID} + - MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET} + - MARKET_JWT_SECRET_KEY=${MARKET_JWT_SECRET_KEY} build: context: ../marketplace-service dockerfile: Dockerfile diff --git a/marketplace-build/release/.env b/marketplace-build/release/.env index 8f0271811..c08dfe92a 100644 --- a/marketplace-build/release/.env +++ b/marketplace-build/release/.env @@ -5,4 +5,7 @@ SERVICE_MONGODB_USER= SERVICE_MONGODB_PASSWORD= SERVICE_MONGODB_DATABASE= MARKET_GITHUB_TOKEN= -MARKETPLACE_INSTALLATION_URL= \ No newline at end of file +MARKETPLACE_INSTALLATION_URL= +MARKET_GITHUB_OAUTH_APP_CLIENT_ID= +MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET= +MARKET_JWT_SECRET_KEY= \ No newline at end of file diff --git a/marketplace-build/release/docker-compose.yml b/marketplace-build/release/docker-compose.yml index dfc95f0fb..693662a90 100644 --- a/marketplace-build/release/docker-compose.yml +++ b/marketplace-build/release/docker-compose.yml @@ -33,5 +33,8 @@ services: - MONGODB_USERNAME=${SERVICE_MONGODB_USER} - MONGODB_PASSWORD=${SERVICE_MONGODB_PASSWORD} - MARKET_GITHUB_TOKEN=${MARKET_GITHUB_TOKEN} + - MARKET_GITHUB_OAUTH_APP_CLIENT_ID=${MARKET_GITHUB_OAUTH_APP_CLIENT_ID} + - MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET} + - MARKET_JWT_SECRET_KEY=${MARKET_JWT_SECRET_KEY} volumes: mongodata: \ No newline at end of file diff --git a/marketplace-build/release/sprint-compose.yml b/marketplace-build/release/sprint-compose.yml index ff273c945..d4d4a15a5 100644 --- a/marketplace-build/release/sprint-compose.yml +++ b/marketplace-build/release/sprint-compose.yml @@ -33,6 +33,9 @@ services: - MONGODB_USERNAME=${SERVICE_MONGODB_USER} - MONGODB_PASSWORD=${SERVICE_MONGODB_PASSWORD} - MARKET_GITHUB_TOKEN=${MARKET_GITHUB_TOKEN} + - MARKET_GITHUB_OAUTH_APP_CLIENT_ID=${MARKET_GITHUB_OAUTH_APP_CLIENT_ID} + - MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET} + - MARKET_JWT_SECRET_KEY=${MARKET_JWT_SECRET_KEY} volumes: mongodata: \ No newline at end of file diff --git a/marketplace-service/src/main/java/com/axonivy/market/controller/FeedbackController.java b/marketplace-service/src/main/java/com/axonivy/market/controller/FeedbackController.java index 4d04faa3c..ed07514b2 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/controller/FeedbackController.java +++ b/marketplace-service/src/main/java/com/axonivy/market/controller/FeedbackController.java @@ -16,6 +16,7 @@ import org.springframework.hateoas.PagedModel; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -70,12 +71,13 @@ public ResponseEntity findFeedback(@PathVariable("id") String id) @Operation(summary = "Find all feedbacks by user id and product id") @GetMapping() - public ResponseEntity findFeedbackByUserIdAndProductId(@RequestParam String userId, - @RequestParam String productId) { + public ResponseEntity findFeedbackByUserIdAndProductId(@RequestParam("userId") String userId, + @RequestParam("productId") String productId) { Feedback feedback = feedbackService.findFeedbackByUserIdAndProductId(userId, productId); return ResponseEntity.ok(feedbackModelAssembler.toModel(feedback)); } + @CrossOrigin("*") @PostMapping public ResponseEntity createFeedback(@RequestBody @Valid FeedbackModel feedback, @RequestHeader(value = "Authorization", required = false) String authorizationHeader) { diff --git a/marketplace-service/src/main/java/com/axonivy/market/controller/OAuth2Controller.java b/marketplace-service/src/main/java/com/axonivy/market/controller/OAuth2Controller.java index 611b6a860..412d1c61b 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/controller/OAuth2Controller.java +++ b/marketplace-service/src/main/java/com/axonivy/market/controller/OAuth2Controller.java @@ -8,6 +8,7 @@ import com.axonivy.market.service.JwtService; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -34,6 +35,7 @@ public OAuth2Controller(GitHubService gitHubService, JwtService jwtService) { this.jwtService = jwtService; } + @CrossOrigin("*") @PostMapping("/github/login") public ResponseEntity gitHubLogin(@RequestBody Oauth2AuthorizationCode oauth2AuthorizationCode) { GitHubAccessTokenResponse tokenResponse = gitHubService.getAccessToken(oauth2AuthorizationCode.getCode(), clientId, diff --git a/marketplace-service/src/main/resources/application.properties b/marketplace-service/src/main/resources/application.properties index b2fd17582..04676038e 100644 --- a/marketplace-service/src/main/resources/application.properties +++ b/marketplace-service/src/main/resources/application.properties @@ -11,7 +11,7 @@ market.cors.allowed.origin.maxAge=3600 synchronized.installation.counts.path=/home/data/market-installation.json market.github.token=${MARKET_GITHUB_TOKEN} logging.level.org.springframework.security=DEBUG -spring.security.oauth2.client.registration.github.client-id= -spring.security.oauth2.client.registration.github.client-secret= -jwt.secret= +spring.security.oauth2.client.registration.github.client-id=${MARKET_GITHUB_OAUTH_APP_CLIENT_ID} +spring.security.oauth2.client.registration.github.client-secret=${MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET} +jwt.secret=${MARKET_JWT_SECRET_KEY} jwt.expiration=365 diff --git a/marketplace-service/src/test/java/com/axonivy/market/service/SchedulingTasksTest.java b/marketplace-service/src/test/java/com/axonivy/market/service/SchedulingTasksTest.java index 0407a7f75..aa7b8af7c 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/service/SchedulingTasksTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/service/SchedulingTasksTest.java @@ -10,8 +10,10 @@ import static org.mockito.Mockito.atLeast; import static org.mockito.Mockito.verify; -@SpringBootTest(properties = { "MONGODB_USERNAME=user", "MONGODB_PASSWORD=password", "MONGODB_HOST=mongoHost", - "MONGODB_DATABASE=product" }) +@SpringBootTest(properties = { "MONGODB_USERNAME=user", + "MONGODB_PASSWORD=password", "MONGODB_HOST=mongoHost", "MONGODB_DATABASE=product", + "MARKET_GITHUB_OAUTH_APP_CLIENT_ID=clientId", "MARKET_GITHUB_OAUTH_APP_CLIENT_SECRET=clientSecret", + "MARKET_JWT_SECRET_KEY=jwtSecret" }) class SchedulingTasksTest { @SpyBean diff --git a/marketplace-ui/src/app/auth/auth.service.ts b/marketplace-ui/src/app/auth/auth.service.ts index 39e4fccbb..b6b323bf0 100644 --- a/marketplace-ui/src/app/auth/auth.service.ts +++ b/marketplace-ui/src/app/auth/auth.service.ts @@ -28,7 +28,7 @@ export class AuthService { private readonly BASE_URL = environment.apiUrl; private readonly TOKEN_KEY = 'token'; private readonly githubAuthUrl = 'https://github.com/login/oauth/authorize'; - private readonly githubAuthCallbackUrl = environment.githubAuthCallbackUrl; + private readonly githubAuthCallbackPath = environment.githubAuthCallbackPath; constructor( private readonly http: HttpClient, @@ -38,7 +38,8 @@ export class AuthService { redirectToGitHub(originalUrl: string): void { const state = encodeURIComponent(originalUrl); - const authUrl = `${this.githubAuthUrl}?client_id=${environment.githubClientId}&redirect_uri=${this.githubAuthCallbackUrl}&state=${state}`; + const githubAuthCallbackUrl = window.location.origin + this.githubAuthCallbackPath; + const authUrl = `${this.githubAuthUrl}?client_id=${environment.githubClientId}&redirect_uri=${githubAuthCallbackUrl}&state=${state}`; window.location.href = authUrl; } diff --git a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-detail-feedback.component.spec.ts b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-detail-feedback.component.spec.ts index 7c8dd9719..2f372eb57 100644 --- a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-detail-feedback.component.spec.ts +++ b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-detail-feedback.component.spec.ts @@ -95,13 +95,6 @@ describe('ProductDetailFeedbackComponent', () => { expect(component).toBeTruthy(); }); - it('should initialize feedbacks and star ratings on ngOnInit', () => { - expect( - mockProductFeedbackService.findProductFeedbackOfUser - ).toHaveBeenCalled(); - expect(mockProductStarRatingService.fetchData).toHaveBeenCalled(); - }); - it('should render ProductStarRatingPanelComponent and ProductFeedbacksPanelComponent', () => { const starRatingPanel = fixture.debugElement.query( By.directive(ProductStarRatingPanelComponent) diff --git a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-detail-feedback.component.ts b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-detail-feedback.component.ts index ebc5c5872..7b4e4d318 100644 --- a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-detail-feedback.component.ts +++ b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-detail-feedback.component.ts @@ -1,21 +1,16 @@ import { - AfterViewInit, Component, computed, inject, input, - OnInit, Signal } from '@angular/core'; import { ProductStarRatingPanelComponent } from './product-star-rating-panel/product-star-rating-panel.component'; import { ShowFeedbacksDialogComponent } from './show-feedbacks-dialog/show-feedbacks-dialog.component'; import { ProductFeedbacksPanelComponent } from './product-feedbacks-panel/product-feedbacks-panel.component'; import { AppModalService } from '../../../../shared/services/app-modal.service'; -import { ActivatedRoute, Router } from '@angular/router'; import { ProductFeedbackService } from './product-feedbacks-panel/product-feedback.service'; -import { AuthService } from '../../../../auth/auth.service'; import { TranslateModule } from '@ngx-translate/core'; -import { ProductStarRatingService } from './product-star-rating-panel/product-star-rating.service'; const MAX_ELEMENTS = 6; @@ -31,7 +26,7 @@ const MAX_ELEMENTS = 6; templateUrl: './product-detail-feedback.component.html', styleUrls: ['./product-detail-feedback.component.scss'] }) -export class ProductDetailFeedbackComponent implements OnInit, AfterViewInit { +export class ProductDetailFeedbackComponent { isMobileMode = input(); isShowBtnMore: Signal = computed(() => { if ( @@ -46,30 +41,9 @@ export class ProductDetailFeedbackComponent implements OnInit, AfterViewInit { productFeedbackService = inject(ProductFeedbackService); appModalService = inject(AppModalService); - private readonly productStarRatingService = inject(ProductStarRatingService); - private readonly authService = inject(AuthService); - private readonly route = inject(ActivatedRoute); - private readonly router = inject(Router); showPopup!: boolean; - ngOnInit(): void { - this.productFeedbackService.findProductFeedbackOfUser(); - this.productStarRatingService.fetchData(); - } - - ngAfterViewInit(): void { - this.route.queryParams.subscribe(params => { - this.showPopup = params['showPopup'] === 'true'; - if (this.showPopup && this.authService.getToken()) { - this.appModalService.openAddFeedbackDialog().then( - () => this.removeQueryParam(), - () => this.removeQueryParam() - ); - } - }); - } - openShowFeedbacksDialog(): void { if (this.isMobileMode()) { this.productFeedbackService.loadMoreFeedbacks(); @@ -77,11 +51,4 @@ export class ProductDetailFeedbackComponent implements OnInit, AfterViewInit { this.appModalService.openShowFeedbacksDialog(); } } - - private removeQueryParam(): void { - this.router.navigate([], { - queryParams: { showPopup: null }, - queryParamsHandling: 'merge' - }); - } } diff --git a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-feedbacks-panel/product-feedback.service.spec.ts b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-feedbacks-panel/product-feedback.service.spec.ts index 2c0103dd4..45ac6ef43 100644 --- a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-feedbacks-panel/product-feedback.service.spec.ts +++ b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-feedbacks-panel/product-feedback.service.spec.ts @@ -112,22 +112,4 @@ describe('ProductFeedbackService', () => { expect(service.feedbacks()).toEqual([{ content: 'Sorting test', rating: 3, productId: '123' }]); }); - - it('should find product feedback of user', () => { - const mockFeedback: Feedback = { - content: 'User feedback', - rating: 5, - productId: '123' - }; - - authService.getUserId.and.returnValue('user123'); - productDetailService.productId.and.returnValue('123'); - - service.findProductFeedbackOfUser(); - const req = httpMock.expectOne('api/feedback?productId=123&userId=user123'); - expect(req.request.method).toBe('GET'); - req.flush(mockFeedback); - - expect(service.userFeedback()).toEqual(mockFeedback); - }); }); diff --git a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-feedbacks-panel/product-feedback.service.ts b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-feedbacks-panel/product-feedback.service.ts index 22da90117..f21ea75c3 100644 --- a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-feedbacks-panel/product-feedback.service.ts +++ b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-feedbacks-panel/product-feedback.service.ts @@ -58,7 +58,7 @@ export class ProductFeedbackService { .pipe( tap(() => { this.initFeedbacks(); - this.findProductFeedbackOfUser(); + this.findProductFeedbackOfUser().subscribe(); this.productStarRatingService.fetchData(); }) ); @@ -96,13 +96,13 @@ export class ProductFeedbackService { findProductFeedbackOfUser( productId: string = this.productDetailService.productId() - ): void { + ): Observable { const params = new HttpParams() .set('productId', productId) .set('userId', this.authService.getUserId() ?? ''); const requestURL = FEEDBACK_API_URL; - this.http + return this.http .get(requestURL, { params, context: new HttpContext().set(SkipLoading, true) @@ -120,8 +120,7 @@ export class ProductFeedbackService { this.userFeedback.set(feedback); return of(feedback); }) - ) - .subscribe(); + ); } initFeedbacks(): void { diff --git a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-star-rating-panel/add-feedback-dialog/add-feedback-dialog.component.html b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-star-rating-panel/add-feedback-dialog/add-feedback-dialog.component.html index 1a6c585a6..9eca9042f 100644 --- a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-star-rating-panel/add-feedback-dialog/add-feedback-dialog.component.html +++ b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-star-rating-panel/add-feedback-dialog/add-feedback-dialog.component.html @@ -27,7 +27,7 @@

{{ 'common.feedback.starRatingTitle' | translate }}

- +

{{ 'common.feedback.commentLabel' | translate }}

diff --git a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-star-rating-panel/product-star-rating.service.ts b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-star-rating-panel/product-star-rating.service.ts index 9f4345c61..c8af47d13 100644 --- a/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-star-rating-panel/product-star-rating.service.ts +++ b/marketplace-ui/src/app/modules/product/product-detail/product-detail-feedback/product-star-rating-panel/product-star-rating.service.ts @@ -1,4 +1,4 @@ -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpContext } from '@angular/common/http'; import { computed, inject, @@ -10,6 +10,7 @@ import { import { tap } from 'rxjs'; import { StarRatingCounting } from '../../../../../shared/models/star-rating-counting.model'; import { ProductDetailService } from '../../product-detail.service'; +import { SkipLoading } from '../../../../../core/interceptors/api.interceptor'; @Injectable({ providedIn: 'root' @@ -29,7 +30,7 @@ export class ProductStarRatingService { fetchData(productId: string = this.productDetailService.productId()): void { const requestURL = `api/feedback/product/${productId}/rating`; this.http - .get(requestURL) + .get(requestURL, {context: new HttpContext().set(SkipLoading, true)}) .pipe( tap(data => { this.sortByStar(data); diff --git a/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.ts b/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.ts index 482a93e1d..bb6c4b52b 100644 --- a/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.ts +++ b/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.ts @@ -27,10 +27,9 @@ import { ProductFeedbackService } from './product-detail-feedback/product-feedba import { AppModalService } from '../../../shared/services/app-modal.service'; import { AuthService } from '../../../auth/auth.service'; import { ProductStarRatingNumberComponent } from './product-star-rating-number/product-star-rating-number.component'; -import { - ProductInstallationCountActionComponent -} from "./product-installation-count-action/product-installation-count-action.component"; +import { ProductInstallationCountActionComponent } from './product-installation-count-action/product-installation-count-action.component'; import { ProductTypeIconPipe } from '../../../shared/pipes/icon.pipe'; +import { ProductStarRatingService } from './product-detail-feedback/product-star-rating-panel/product-star-rating.service'; export interface DetailTab { activeClass: string; @@ -56,7 +55,7 @@ const DEFAULT_ACTIVE_TAB = 'description'; MultilingualismPipe, ProductDetailFeedbackComponent, ProductInstallationCountActionComponent, - ProductTypeIconPipe, + ProductTypeIconPipe ], providers: [ProductService, MarkdownService], templateUrl: './product-detail.component.html', @@ -70,6 +69,7 @@ export class ProductDetailComponent { languageService = inject(LanguageService); productDetailService = inject(ProductDetailService); productFeedbackService = inject(ProductFeedbackService); + productStarRatingService = inject(ProductStarRatingService); appModalService = inject(AppModalService); authService = inject(AuthService); elementRef = inject(ElementRef); @@ -119,6 +119,7 @@ export class ProductDetailComponent { this.installationCount = productDetail.installationCount; }); this.productFeedbackService.initFeedbacks(); + this.productStarRatingService.fetchData(); } const savedTab = localStorage.getItem(STORAGE_ITEM); @@ -128,6 +129,21 @@ export class ProductDetailComponent { this.updateDropdownSelection(); } + ngAfterViewInit(): void { + this.checkMediaSize(); + this.productFeedbackService.findProductFeedbackOfUser().subscribe(() => { + this.route.queryParams.subscribe(params => { + this.showPopup = params['showPopup'] === 'true'; + if (this.showPopup && this.authService.getToken()) { + this.appModalService + .openAddFeedbackDialog() + .then(() => this.removeQueryParam()) + .catch(() => this.removeQueryParam()); + } + }); + }); + } + getContent(value: string): boolean { const content = this.productModuleContent(); const conditions: { [key: string]: boolean } = { @@ -203,10 +219,6 @@ export class ProductDetailComponent { } } - ngAfterViewInit(): void { - this.checkMediaSize(); - } - @HostListener('window:resize', ['$event']) onResize() { this.checkMediaSize(); @@ -233,4 +245,11 @@ export class ProductDetailComponent { receiveInstallationCountData(data: number) { this.installationCount = data; } + + private removeQueryParam(): void { + this.router.navigate([], { + queryParams: { showPopup: null }, + queryParamsHandling: 'merge' + }); + } } diff --git a/marketplace-ui/src/app/shared/components/star-rating/star-rating.component.html b/marketplace-ui/src/app/shared/components/star-rating/star-rating.component.html index 2175e8a8e..d76db0363 100644 --- a/marketplace-ui/src/app/shared/components/star-rating/star-rating.component.html +++ b/marketplace-ui/src/app/shared/components/star-rating/star-rating.component.html @@ -1,5 +1,5 @@ (); diff --git a/marketplace-ui/src/environments/environment.development.ts b/marketplace-ui/src/environments/environment.development.ts index 4a93e0eca..33f7f2c24 100644 --- a/marketplace-ui/src/environments/environment.development.ts +++ b/marketplace-ui/src/environments/environment.development.ts @@ -2,6 +2,6 @@ export const environment = { production: false, apiUrl: 'http://localhost:9090/marketplace-service', githubClientId: 'Ov23liUzb36JCQIfEBGn', - githubAuthCallbackUrl: 'http://localhost:4200/auth/github/callback', + githubAuthCallbackPath: '/auth/github/callback', dayInMiliseconds: 86400000 }; diff --git a/marketplace-ui/src/environments/environment.ts b/marketplace-ui/src/environments/environment.ts index 9d002c724..ac0668b1f 100644 --- a/marketplace-ui/src/environments/environment.ts +++ b/marketplace-ui/src/environments/environment.ts @@ -2,7 +2,7 @@ export const environment = { production: true, apiUrl: 'http://marketplace.server.ivy-cloud.com:8080/marketplace-service', githubClientId: 'Ov23liVMliBxBqdQ7FnG', - githubAuthCallbackUrl: 'http://marketplace.server.ivy-cloud.com:4200/auth/github/callback', + githubAuthCallbackPath: '/auth/github/callback', dayInMiliseconds: 86400000 }; diff --git a/marketplace-ui/src/styles.scss b/marketplace-ui/src/styles.scss index c547a1ad4..2422760de 100644 --- a/marketplace-ui/src/styles.scss +++ b/marketplace-ui/src/styles.scss @@ -11,5 +11,5 @@ } body { - min-width: 300px; + min-width: 370px; } \ No newline at end of file