-
Notifications
You must be signed in to change notification settings - Fork 18
GDB-12880 introduce repository picker list #2994
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ export const mapRepositoryListResponseToModel: MapperFn<RepositoryListResponse, | |
| externalUrl: repositoryData.externalUrl, | ||
| location: repositoryData.location, | ||
| state: toEnum(RepositoryState, repositoryData.state), | ||
| stateLowercase: repositoryData.state ? repositoryData.state.toLowerCase() : undefined, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why set this here? Isn't it more apropriate to set it in the constructor? It is a helper prop.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this should be in the constructor as it is a derived property. I used to change it, but I guess I've dropped it somewhere down the road |
||
| local: repositoryData.local, | ||
| readable: repositoryData.readable, | ||
| writable: repositoryData.writable, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| import {AuthenticatedUser, Authority, Rights, SecurityConfig} from '../../../models/security'; | ||
| import {service} from '../../../providers'; | ||
| import {SecurityContextService} from './security-context.service'; | ||
| import {Repository} from '../../../models/repositories'; | ||
| import {Repository, RepositoryList} from '../../../models/repositories'; | ||
| import { | ||
| RepositoryAuthorityService, | ||
| RepositoryContextService, | ||
|
|
@@ -77,6 +77,9 @@ | |
| * @returns {boolean} True if the user has the repository manager role, false otherwise. | ||
| */ | ||
| isRepoManager(): boolean { | ||
| // TODO the legacy is doing the following | ||
|
Check warning on line 80 in packages/api/src/services/domain/security/authorization.service.ts
|
||
| // return authorizationService.hasRole(UserRole.ROLE_REPO_MANAGER) && !$repositories.getDegradedReason(); | ||
| // Check why we are not doing the same in the new implementation and if we need to add the degraded reason check back in | ||
| return this.hasRole(Authority.ROLE_REPO_MANAGER); | ||
| } | ||
|
|
||
|
|
@@ -296,6 +299,46 @@ | |
| this.securityContextService.updateRestrictedPages(restrictedPages); | ||
| }; | ||
|
|
||
| /** | ||
| * Retrieves a list of repositories that the user has write access to. | ||
| * | ||
| * @returns {RepositoryList} A list of repositories that the user can write to. | ||
| */ | ||
| getWritableRepositories(): RepositoryList { | ||
| return this.repositoryContextService.getRepositoryList().filterWithCallback(repository => this.canWriteRepo(repository)); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a list of repositories that the user has read access to, including those that are readable through | ||
| * GraphQL permissions. | ||
| * | ||
| * @returns {RepositoryList} A list of repositories that the user can read. | ||
| */ | ||
| getReadableRepositories(): RepositoryList { | ||
| return this.repositoryContextService.getRepositoryList().filterWithCallback(repository => | ||
| this.canReadRepo(repository) || this.canReadGqlRepo(repository) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieves a list of repositories that the user has access to, based on the specified parameters. | ||
| * @param includeRemote - If true, includes remote repositories in the list; otherwise, only local repositories are included. | ||
| * @param isRestricted - If true, returns repositories that the user has write access to; if false, returns repositories that the user has read access to. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is kind of strange. If
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, this was a blind copy/paste from the core-errors. It's stupid indeed. |
||
| * @returns A list of repositories that the user has access to, filtered based on the provided parameters. | ||
| */ | ||
| getAccessibleRepositories(includeRemote = false, isRestricted = true): RepositoryList { | ||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| let remoteLocationsFilter = (_repo: Repository) => true; | ||
| if (!includeRemote) { | ||
| remoteLocationsFilter = (repo) => !!repo.local; | ||
| } | ||
| if (isRestricted) { | ||
| return new RepositoryList(this.getWritableRepositories().filter(remoteLocationsFilter)); | ||
| } else { | ||
| return new RepositoryList(this.getReadableRepositories().filter(remoteLocationsFilter)); | ||
| } | ||
| } | ||
|
|
||
| private resolveAuthorities(authoritiesList?: string[]) { | ||
| // If no authorities list is provided, return empty array. | ||
| if (!authoritiesList) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <div class="page-restrictions"> | ||
| @if (restrictions().length) { | ||
| <p-message [severity]="'info'" icon="ri-alert-line"> | ||
| @for (reason of restrictions(); track reason.translationKey) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not big deal but strange shouldn't the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw it is actually |
||
| <div> | ||
| {{ reason.translationKey | transloco: reason.translationParams }} | ||
| @if (reason.ctaKey) { | ||
| <a [routerLink]="reason.ctaLink">{{ reason.ctaKey | transloco }}</a> | ||
| } | ||
| </div> | ||
| } | ||
| </p-message> | ||
| } | ||
| @if (repositoryList() && !selectedRepository()) { | ||
| <app-repository-picker-list [isRestricted]="isRestricted()"></app-repository-picker-list> | ||
| } | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .page-restrictions { | ||
| margin-top: 1em; | ||
|
|
||
| &:empty { | ||
| margin-top: 0; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { provideRouter } from '@angular/router'; | ||
|
|
||
| import { PageRestrictionsComponent } from './page-restrictions.component'; | ||
| import {provideTranslocoForTesting} from '../../../testing-utils/transloco-utils'; | ||
|
|
||
| describe('PageRestrictionsComponent', () => { | ||
| let component: PageRestrictionsComponent; | ||
| let fixture: ComponentFixture<PageRestrictionsComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [PageRestrictionsComponent, provideTranslocoForTesting()], | ||
| providers: [provideRouter([])], | ||
| }) | ||
| .compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(PageRestrictionsComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this called
filterCallback? Isn't filter informative enough?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a collision with the super's names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so .. what it does different than the already inherited
filtermethod is that it returns a new List with the values. I thinkfilterWithCallbackshould be renamed to something likefilteredList.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. The argument can be renamed to
filterI guess. My idea was somewhat I've seen in lodash for example where they have functions likeunionWith,uniqueWith, etc. where those take a callback/comparator function but made it a bit more verbose.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the lodash functions, but here you already have
filterwhich does the same thing, only difference is that here you return a new reference for a list.If you need both: to get a list and to get an array, perhaps this shoud be a
.toFilteredListor something like this.