Skip to content

Conversation

Harish-osmosys
Copy link
Contributor

@Harish-osmosys Harish-osmosys commented May 29, 2024

API PR Checklist

Pre-requisites

  • I have gone through the Contributing guidelines for Submitting a Pull Request (PR) and ensured that this is not a duplicate PR.
  • I have performed preliminary unit testing.
  • I have updated the required api docs as applicable.
  • I have added/updated test cases to the test suite as applicable

PR Details

PR details have been updated as per the given format (see below)

  • PR title adheres to the format specified in guidelines (e.g., feat: add admin login endpoint)
  • Description has been added
  • Related changes have been added (optional)
  • Screenshots have been added (optional)
  • Query request and response examples have been added (as applicable, in case added or updated)
  • Documentation changes have been listed (as applicable)
  • Test suite output is added (as applicable)
  • Pending actions have been added (optional)
  • Any other additional notes have been added (optional)

Additional Information

  • Appropriate label(s) have been added (ready for review should be added if the PR is ready to be reviewed)
  • Assignee(s) and reviewer(s) have been added (optional)

Description:

  • Use AcquireTokenSilently to get the token for validation
  • Remove Access Token from Session Storage:

Token Behaviour :

  • The token api is called when we login for the first time
  • Then after for all other operation token api is not called
  • When the token expire the token api is called automatically to get the new token
  • The expiry time for one token is Random . Observed values are : 4142 , 4128, 4866

Related changes:

NA

Screenshots:

NA

Query request and response:

NA

Documentation changes:

NA

Test suite output:

NA

Pending actions:

NA

Additional notes:

NA

Summary by CodeRabbit

  • Bug Fixes

    • Improved token handling in GraphQL requests to ensure proper authentication and authorization.
  • Chores

    • Updated import paths for CurrentUser decorator in the Summary module.

@Harish-osmosys Harish-osmosys requested a review from xixas May 29, 2024 10:50
@Harish-osmosys Harish-osmosys self-assigned this May 29, 2024
Copy link
Contributor

coderabbitai bot commented May 29, 2024

Walkthrough

The updates primarily enhance the GraphqlService in the portal app by making the getToken method return an Observable<string> for better asynchronous handling using RxJS operators and MSAL for token acquisition. Additionally, the query and mutate methods are updated to handle token retrieval more efficiently. Minor import path adjustments were made in the SummaryResolver class in the api app.

Changes

File Path Change Summary
apps/portal/src/app/graphql/graphql.service.ts Updated getToken to return Observable<string>, added necessary imports, and modified query and mutate methods to handle token retrieval.
apps/api/src/modules/summary/summary.resolver.ts Updated import path for CurrentUser decorator.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant GraphqlService
    participant MsalService
    participant GraphQLServer

    Client->>GraphqlService: query/mutate request
    GraphqlService->>MsalService: getToken()
    MsalService-->>GraphqlService: Observable<AuthenticationResult>
    GraphqlService-->>GraphqlService: extract token
    GraphqlService->>GraphQLServer: GraphQL request with Authorization header
    GraphQLServer-->>GraphqlService: Response
    GraphqlService-->>Client: Response
Loading

Poem

In the land of code where tokens flow,
GraphqlService learns to grow.
With Observable streams and async might,
Queries and mutations take flight.
A path corrected, imports aligned,
In our portal and API, harmony we find.
🎉🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Harish-osmosys Harish-osmosys changed the title feat: remove token storage, use acquireTokenSilent feat: remove token storage use acquireTokenSilent May 29, 2024
@Harish-osmosys Harish-osmosys changed the title feat: remove token storage use acquireTokenSilent feat: remove token from storage use acquireTokenSilent May 29, 2024
@coderabbitai coderabbitai bot changed the title feat: remove token from storage use acquireTokenSilent feat: remove token storage, use acquireTokenSilent May 29, 2024
@Harish-osmosys Harish-osmosys added the Ready for review Ready for review label May 29, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range and nitpick comments (3)
apps/portal/src/app/app.component.ts (2)

Line range hint 1-1: Optimize imports to only include what is necessary.

- import { Component, OnInit, OnDestroy, Inject } from '@angular/core';
- import {
-   MsalService,
-   MsalBroadcastService,
-   MSAL_GUARD_CONFIG,
-   MsalGuardConfiguration,
- } from '@azure/msal-angular';
- import {
-   InteractionStatus,
-   RedirectRequest,
-   AuthenticationResult,
-   EventMessage,
-   EventType,
- } from '@azure/msal-browser';
- import { Subject } from 'rxjs';
- import { filter, takeUntil } from 'rxjs/operators';
- import { environment } from '../environments/environment';
+ import { Component, OnInit, OnDestroy, Inject } from '@angular/core';
+ import { MsalService, MsalBroadcastService, MSAL_GUARD_CONFIG } from '@azure/msal-angular';
+ import { InteractionStatus, RedirectRequest, AuthenticationResult, EventMessage, EventType } from '@azure/msal-browser';
+ import { Subject, filter, takeUntil } from 'rxjs';
+ import { environment } from '../environments/environment';

Also applies to: 1-7, 7-14


Line range hint 1-1: Ensure that named imports are used correctly and remove any that are only used as types.

Also applies to: 1-7, 7-14

apps/portal/src/app/graphql/graphql.service.ts (1)

Line range hint 1-2: Optimize imports to only include what is necessary.

- import { Injectable } from '@angular/core';
- import { DocumentNode } from 'graphql';
- import { QueryRef, Apollo, MutationResult } from 'apollo-angular';
- import { Observable, throwError } from 'rxjs';
- import { ApolloQueryResult } from '@apollo/client';
- import { catchError, switchMap } from 'rxjs/operators';
- import { MsalService } from '@azure/msal-angular';
- import { AuthenticationResult } from '@azure/msal-browser';
- import { environment } from '../../environments/environment';
+ import { Injectable } from '@angular/core';
+ import { DocumentNode, QueryRef, Apollo, MutationResult, ApolloQueryResult } from 'graphql';
+ import { Observable, throwError, catchError, switchMap } from 'rxjs';
+ import { MsalService, AuthenticationResult } from '@azure/msal-angular';
+ import { environment } from '../../environments/environment';

Also applies to: 2-3, 3-4, 4-5, 6-7, 7-8

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1ddf662 and 2d3eb26.
Files selected for processing (2)
  • apps/portal/src/app/app.component.ts (2 hunks)
  • apps/portal/src/app/graphql/graphql.service.ts (4 hunks)
Additional Context Used
Biome (15)
apps/portal/src/app/app.component.ts (4)

34-34: Decorators are not valid here.


1-1: Some named imports are only used as types.


1-7: Some named imports are only used as types.


7-14: Some named imports are only used as types.

apps/portal/src/app/graphql/graphql.service.ts (11)

35-35: Change to an optional chain.


82-82: Unexpected any. Specify a different type.


112-112: Unexpected any. Specify a different type.


114-122: Change to an optional chain.


118-118: Unexpected any. Specify a different type.


1-2: All these imports are only used as types.


2-3: All these imports are only used as types.


3-4: Some named imports are only used as types.


4-5: All these imports are only used as types.


6-7: All these imports are only used as types.


7-8: All these imports are only used as types.

GitHub Check Runs (1)
Lint failure (3)

apps/portal/src/app/graphql/graphql.service.ts: [warning] 42-42:
Unexpected console statement

Additional comments not posted (1)
apps/portal/src/app/app.component.ts (1)

Line range hint 34-34: Ensure that decorators are used correctly in the Angular context.

Verification successful

The decorators @Component and @Inject are used correctly in the Angular context within the app.component.ts file. The search results show that these decorators are used in various files, indicating consistent usage across the codebase.

  • @Component is used to define Angular components.
  • @Inject is used for dependency injection, which is a standard practice in Angular applications.

No issues were found with the usage of these decorators in the provided context.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct use of decorators in Angular components.

# Test: Search for incorrect decorator usage. Expect: No matches.
rg --type typescript $'@Component|@Inject'

Length of output: 78



Script:

#!/bin/bash
# Description: Verify the correct use of decorators in Angular components.

# Test: Search for incorrect decorator usage. Expect: No matches.
rg '@Component|@Inject' --glob '*.ts'

Length of output: 1518

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (2)
apps/portal/src/app/graphql/graphql.service.ts (2)

Line range hint 109-119: Consider using optional chaining in isUnauthorizedError method for better readability and safety.

-      error &&
-      error.graphQLErrors &&
-      error.graphQLErrors.some(
+      error?.graphQLErrors?.some(

Line range hint 1-8: Use import type for imports that are only used as types to prevent side effects and improve clarity.

- import { DocumentNode } from 'graphql';
- import { QueryRef, Apollo, MutationResult } from 'apollo-angular';
- import { ApolloQueryResult } from '@apollo/client';
+ import type { DocumentNode } from 'graphql';
+ import type { QueryRef, Apollo, MutationResult } from 'apollo-angular';
+ import type { ApolloQueryResult } from '@apollo/client';
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2d3eb26 and 4b454c5.
Files selected for processing (1)
  • apps/portal/src/app/graphql/graphql.service.ts (4 hunks)
Additional Context Used
Biome (11)
apps/portal/src/app/graphql/graphql.service.ts (11)

35-35: Change to an optional chain.


79-79: Unexpected any. Specify a different type.


109-109: Unexpected any. Specify a different type.


111-119: Change to an optional chain.


115-115: Unexpected any. Specify a different type.


1-2: All these imports are only used as types.


2-3: All these imports are only used as types.


3-4: Some named imports are only used as types.


4-5: All these imports are only used as types.


6-7: All these imports are only used as types.


7-8: All these imports are only used as types.

Learnings (1)
apps/portal/src/app/graphql/graphql.service.ts (1)
User: Harish-osmosys
PR: OsmosysSoftware/osm-transcript-summarizer#40
File: apps/portal/src/app/graphql/graphql.service.ts:0-0
Timestamp: 2024-05-29T11:00:53.632Z
Learning: Harish-osmosys removed the `console.error` line from the `getToken` method in `GraphqlService` as suggested for better production code practices.
Additional comments not posted (4)
apps/portal/src/app/graphql/graphql.service.ts (4)

35-35: Consider using optional chaining for better readability and safety.

-        if (response && response.accessToken) {
+        if (response?.accessToken) {

Likely invalid or redundant comment.


80-105: Refactor mutate method to use getToken and handle token asynchronously.

Verification successful

The handleUnauthorizedError method is indeed present and invoked within the mutate method, confirming that unauthorized errors are being handled appropriately.

  • handleUnauthorizedError method is defined and called within the mutate method.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that error handling in `mutate` method is robust and correctly redirects on unauthorized errors.

# Test: Search for error handling patterns in the method. Expect: Proper redirection and error throwing.
rg --type typescript $'handleUnauthorizedError' apps/portal/src/app/graphql/graphql.service.ts

Length of output: 128



Script:

#!/bin/bash
# Description: Verify that error handling in `mutate` method is robust and correctly redirects on unauthorized errors.

# Test: Search for error handling patterns in the method. Expect: Proper redirection and error throwing.
rg --type ts 'handleUnauthorizedError' apps/portal/src/app/graphql/graphql.service.ts

Length of output: 213


20-43: Refactor getToken method to use acquireTokenSilent and return Observable<string>.

Verification successful

The getToken method is used within the query and mutate methods of the GraphqlService class, and both usages correctly handle the Observable by using the pipe method with switchMap.

  • query<T>(query: DocumentNode): Observable<ApolloQueryResult<T>>
  • mutate<T>(mutation: DocumentNode, variables: any): Observable<MutationResult<T>>

Both methods properly manage the Observable returned by getToken.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that all usages of `getToken` method handle the Observable correctly.

# Test: Search for the method usage. Expect: Proper handling of Observable.
rg --type typescript $'\\.getToken\\(\\)'

Length of output: 74



Script:

#!/bin/bash
# Description: Verify that all usages of `getToken` method handle the Observable correctly.

# Test: Search for the method usage. Expect: Proper handling of Observable.
rg --glob '*.ts' '\.getToken\(\)'

Length of output: 195



Script:

#!/bin/bash
# Description: Extract lines where `getToken` is used to verify proper Observable handling.

# Extract lines where `getToken` is used in `graphql.service.ts`
rg --glob '*.ts' '\.getToken\(\)' -A 5 -B 5

Length of output: 1791


53-67: Refactor query method to use getToken and handle token asynchronously.

@xixas
Copy link
Contributor

xixas commented May 29, 2024

@Harish-osmosys Add your findings on behaviour of token in description.
Is Acquire Token is fetching same token?
Does it do a new token network call? Check the difference in response time when it does it for first time after login vs later calls.
Any other behaviour you have noticed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
apps/portal/src/app/graphql/graphql.service.ts (1)

Line range hint 113-127: Consider simplifying the condition in isUnauthorizedError for better readability.

-      error &&
-      error.graphQLErrors &&
-      error.graphQLErrors.some(
-        (err: any) =>
-          err.extensions &&
-          err.extensions.code === 'UNAUTHENTICATED' &&
-          err.message === 'Unauthorized',
-      )
+      error?.graphQLErrors?.some(err => err.extensions?.code === 'UNAUTHENTICATED' && err.message === 'Unauthorized')
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 4b454c5 and 7c7e4e6.
Files selected for processing (1)
  • apps/portal/src/app/graphql/graphql.service.ts (4 hunks)
Additional Context Used
Biome (11)
apps/portal/src/app/graphql/graphql.service.ts (11)

35-35: Change to an optional chain.


87-87: Unexpected any. Specify a different type.


117-117: Unexpected any. Specify a different type.


119-127: Change to an optional chain.


123-123: Unexpected any. Specify a different type.


1-2: All these imports are only used as types.


2-3: All these imports are only used as types.


3-4: Some named imports are only used as types.


4-5: All these imports are only used as types.


6-7: All these imports are only used as types.


7-8: Some named imports are only used as types.

Learnings (1)
apps/portal/src/app/graphql/graphql.service.ts (1)
User: Harish-osmosys
PR: OsmosysSoftware/osm-transcript-summarizer#40
File: apps/portal/src/app/graphql/graphql.service.ts:0-0
Timestamp: 2024-05-29T11:00:53.632Z
Learning: Harish-osmosys removed the `console.error` line from the `getToken` method in `GraphqlService` as suggested for better production code practices.
Additional comments not posted (3)
apps/portal/src/app/graphql/graphql.service.ts (3)

61-75: The implementation of the query method looks correct and well-structured.


88-113: The implementation of the mutate method is correct and handles file uploads appropriately.


52-54: The handleUnauthorizedError method correctly handles logout redirection.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7c7e4e6 and 07982e8.

Files selected for processing (2)
  • apps/api/src/modules/summary/summary.resolver.ts (1 hunks)
  • apps/portal/src/app/graphql/graphql.service.ts (4 hunks)
Additional context used
Learnings (1)
apps/portal/src/app/graphql/graphql.service.ts (1)
User: Harish-osmosys
PR: OsmosysSoftware/osm-transcript-summarizer#40
File: apps/portal/src/app/graphql/graphql.service.ts:0-0
Timestamp: 2024-05-29T11:00:53.632Z
Learning: Harish-osmosys removed the `console.error` line from the `getToken` method in `GraphqlService` as suggested for better production code practices.
Biome
apps/api/src/modules/summary/summary.resolver.ts

[error] 18-18: Decorators are not valid here.


[error] 19-19: Decorators are not valid here.


[error] 27-27: Decorators are not valid here.


[error] 1-2: All these imports are only used as types.


[error] 3-4: All these imports are only used as types.

apps/portal/src/app/graphql/graphql.service.ts

[error] 35-35: Change to an optional chain.


[error] 86-86: Unexpected any. Specify a different type.


[error] 116-116: Unexpected any. Specify a different type.


[error] 118-126: Change to an optional chain.


[error] 122-122: Unexpected any. Specify a different type.


[error] 1-2: All these imports are only used as types.


[error] 2-3: All these imports are only used as types.


[error] 3-4: Some named imports are only used as types.


[error] 4-5: All these imports are only used as types.


[error] 6-7: All these imports are only used as types.


[error] 7-8: Some named imports are only used as types.

@xixas xixas merged commit 1c34adb into main May 31, 2024
@xixas xixas deleted the token-getting-fixed branch May 31, 2024 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants