Skip to content

Commit 5a500e2

Browse files
thquadrichard-cox
authored andcommitted
Change createUserEndpoint checkbox & fix validation bug (#4876)
Signed-off-by: Thomas Quandt <[email protected]>
1 parent e871659 commit 5a500e2

File tree

13 files changed

+75
-67
lines changed

13 files changed

+75
-67
lines changed

src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
<h1 class="create-endpoint__section-title">{{endpoint.definition.label}} Information</h1>
33
<mat-form-field>
44
<input matInput id="name" name="name" formControlName="nameField" placeholder="Name"
5-
[appUnique]="registerForm.value.createUserEndpointField ? (existingPersonalEndpoints | async)?.names : (customEndpoints | async)?.names">
5+
[appUnique]="registerForm.value.createSystemEndpointField ? (customEndpoints | async)?.names : (existingPersonalEndpoints | async)?.names">
66
<mat-error *ngIf="registerForm.controls.nameField.errors?.required">Name is required</mat-error>
77
<mat-error *ngIf="registerForm.controls.nameField.errors?.appUnique">Name is not unique</mat-error>
88
</mat-form-field>
99
<mat-form-field novalidate>
1010
<input matInput id="url" name="url" formControlName="urlField" type="url" required placeholder="Endpoint Address"
1111
pattern="{{urlValidation}}"
12-
[appUnique]="registerForm.value.createUserEndpointField ? (existingPersonalEndpoints | async)?.urls : (customEndpoints | async)?.urls">
12+
[appUnique]="registerForm.value.createSystemEndpointField ? (customEndpoints | async)?.urls : (existingPersonalEndpoints | async)?.urls">
1313
<mat-error *ngIf="registerForm.controls.urlField.errors?.required">URL is required</mat-error>
1414
<mat-error *ngIf="registerForm.controls.urlField.errors?.pattern">Invalid API URL</mat-error>
1515
<mat-error *ngIf="registerForm.controls.urlField.errors?.appUnique">URL is not unique</mat-error>
1616
</mat-form-field>
17-
<mat-checkbox matInput *ngIf="userEndpointsAndIsAdmin | async" name="createUserEndpoint"
18-
formControlName="createUserEndpointField" (change)="toggleCreateUserEndpoint()"
19-
[ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Create a user endpoint (only visible to you and other admins)
17+
<mat-checkbox matInput *ngIf="userEndpointsAndIsAdmin | async" name="createSystemEndpoint"
18+
formControlName="createSystemEndpointField" (change)="toggleCreateSystemEndpoint()"
19+
[ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Create a system endpoint (visible to all users)
2020
</mat-checkbox>
2121
<mat-checkbox matInput name="skipSll" formControlName="skipSllField"
2222
[ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Skip SSL validation for the

src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-cf-step-1/create-endpoint-cf-step-1.component.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AfterContentInit, Component, Input } from '@angular/core';
22
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
33
import { ActivatedRoute } from '@angular/router';
44
import { Observable } from 'rxjs';
5-
import { filter, map, pairwise } from 'rxjs/operators';
5+
import { distinctUntilChanged, filter, map, pairwise } from 'rxjs/operators';
66

77
import { entityCatalog } from '../../../../../../store/src/entity-catalog/entity-catalog';
88
import {
@@ -14,12 +14,12 @@ import { getIdFromRoute } from '../../../../core/utils.service';
1414
import { IStepperStep, StepOnNextFunction } from '../../../../shared/components/stepper/step/step.component';
1515
import { SessionService } from '../../../../shared/services/session.service';
1616
import { CurrentUserPermissionsService } from '../../../../core/permissions/current-user-permissions.service';
17+
import { UserProfileService } from '../../../../core/user-profile.service';
1718
import { SnackBarService } from '../../../../shared/services/snackbar.service';
1819
import { ConnectEndpointConfig } from '../../connect.service';
1920
import { getSSOClientRedirectURI } from '../../endpoint-helpers';
2021
import { CreateEndpointHelperComponent } from '../create-endpoint-helper';
2122

22-
2323
@Component({
2424
selector: 'app-create-endpoint-cf-step-1',
2525
templateUrl: './create-endpoint-cf-step-1.component.html',
@@ -63,9 +63,10 @@ export class CreateEndpointCfStep1Component extends CreateEndpointHelperComponen
6363
activatedRoute: ActivatedRoute,
6464
private snackBarService: SnackBarService,
6565
sessionService: SessionService,
66-
currentUserPermissionsService: CurrentUserPermissionsService
66+
currentUserPermissionsService: CurrentUserPermissionsService,
67+
userProfileService: UserProfileService
6768
) {
68-
super(sessionService, currentUserPermissionsService);
69+
super(sessionService, currentUserPermissionsService, userProfileService);
6970

7071
this.registerForm = this.fb.group({
7172
nameField: ['', [Validators.required]],
@@ -75,7 +76,7 @@ export class CreateEndpointCfStep1Component extends CreateEndpointHelperComponen
7576
// Optional Client ID and Client Secret
7677
clientIDField: ['', []],
7778
clientSecretField: ['', []],
78-
createUserEndpointField: [false, []],
79+
createSystemEndpointField: [true, []],
7980
});
8081

8182
const epType = getIdFromRoute(activatedRoute, 'type');
@@ -98,7 +99,7 @@ export class CreateEndpointCfStep1Component extends CreateEndpointHelperComponen
9899
this.registerForm.value.clientIDField,
99100
this.registerForm.value.clientSecretField,
100101
this.registerForm.value.ssoAllowedField,
101-
this.registerForm.value.createUserEndpointField,
102+
this.registerForm.value.createSystemEndpointField,
102103
).pipe(
103104
pairwise(),
104105
filter(([oldVal, newVal]) => (oldVal.busy && !newVal.busy)),
@@ -149,7 +150,7 @@ export class CreateEndpointCfStep1Component extends CreateEndpointHelperComponen
149150
this.showAdvancedOptions = !this.showAdvancedOptions;
150151
}
151152

152-
toggleCreateUserEndpoint() {
153+
toggleCreateSystemEndpoint() {
153154
// wait a tick for validators to adjust to new data in the directive
154155
setTimeout(() => {
155156
this.registerForm.controls.nameField.updateValueAndValidity();

src/frontend/packages/core/src/features/endpoints/create-endpoint/create-endpoint-helper.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getFullEndpointApiUrl } from '../../../../../store/src/endpoint-utils';
55
import { stratosEntityCatalog } from '../../../../../store/src/stratos-entity-catalog';
66
import { CurrentUserPermissionsService } from '../../../core/permissions/current-user-permissions.service';
77
import { StratosCurrentUserPermissions } from '../../../core/permissions/stratos-user-permissions.checker';
8+
import { UserProfileService } from '../../../core/user-profile.service';
89
import { SessionService } from '../../../shared/services/session.service';
910

1011
type EndpointObservable = Observable<{
@@ -22,7 +23,8 @@ export class CreateEndpointHelperComponent {
2223

2324
constructor(
2425
public sessionService: SessionService,
25-
public currentUserPermissionsService: CurrentUserPermissionsService
26+
public currentUserPermissionsService: CurrentUserPermissionsService,
27+
public userProfileService: UserProfileService
2628
) {
2729
const currentPage$ = stratosEntityCatalog.endpoint.store.getAll.getPaginationMonitor().currentPage$;
2830
this.existingSystemEndpoints = currentPage$.pipe(
@@ -31,10 +33,13 @@ export class CreateEndpointHelperComponent {
3133
urls: endpoints.filter(ep => ep.creator.system).map(ep => getFullEndpointApiUrl(ep)),
3234
}))
3335
);
34-
this.existingPersonalEndpoints = currentPage$.pipe(
35-
map(endpoints => ({
36-
names: endpoints.filter(ep => !ep.creator.system).map(ep => ep.name),
37-
urls: endpoints.filter(ep => !ep.creator.system).map(ep => getFullEndpointApiUrl(ep)),
36+
this.existingPersonalEndpoints = combineLatest([
37+
currentPage$,
38+
this.userProfileService.userProfile$
39+
]).pipe(
40+
map(([endpoints, profile]) => ({
41+
names: endpoints.filter(ep => !ep.creator.system && ep.creator.name === profile.userName).map(ep => ep.name),
42+
urls: endpoints.filter(ep => !ep.creator.system && ep.creator.name === profile.userName).map(ep => getFullEndpointApiUrl(ep)),
3843
}))
3944
);
4045
this.existingEndpoints = currentPage$.pipe(

src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ <h3>Select the type of {{gitTypes[epSubType].label}} to register</h3>
1919
<div *ngIf="showEndpointFields" class="select-step__endpoint-form">
2020
<mat-form-field>
2121
<input matInput id="name" name="name" formControlName="nameField" placeholder="Name"
22-
[appUnique]="registerForm.value.createUserEndpointField ? (existingPersonalEndpoints | async)?.names : (customEndpoints | async)?.names">
22+
[appUnique]="registerForm.value.createSystemEndpointField ? (customEndpoints | async)?.names : (existingPersonalEndpoints | async)?.names">
2323
<mat-error *ngIf="registerForm.controls.nameField.errors?.required">Name is required</mat-error>
2424
<mat-error *ngIf="registerForm.controls.nameField.errors?.appUnique">Name is not unique</mat-error>
2525
</mat-form-field>
2626
<mat-form-field novalidate>
2727
<input matInput id="url" name="url" formControlName="urlField" type="url" required
2828
placeholder="Endpoint Address" pattern="{{urlValidation}}"
29-
[appUnique]="registerForm.value.createUserEndpointField ? (existingPersonalEndpoints | async)?.urls : (customEndpoints | async)?.urls">
29+
[appUnique]="registerForm.value.createSystemEndpointField ? (customEndpoints | async)?.urls : (existingPersonalEndpoints | async)?.urls">
3030
<mat-error *ngIf="registerForm.controls.urlField.errors?.required">URL is required</mat-error>
3131
<mat-error *ngIf="registerForm.controls.urlField.errors?.pattern">Invalid API URL</mat-error>
3232
<mat-error *ngIf="registerForm.controls.urlField.errors?.appUnique">URL is not unique</mat-error>
3333
</mat-form-field>
34-
<mat-checkbox matInput *ngIf="userEndpointsAndIsAdmin | async" name="createUserEndpoint"
35-
formControlName="createUserEndpointField" (change)="toggleCreateUserEndpoint()"
36-
[ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Create a user endpoint (only visible to you and other admins)
34+
<mat-checkbox matInput *ngIf="userEndpointsAndIsAdmin | async" name="createSystemEndpoint"
35+
formControlName="createSystemEndpointField" (change)="toggleCreateSystemEndpoint()"
36+
[ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Create a system endpoint (visible to all users)
3737
</mat-checkbox>
3838
<mat-checkbox matInput name="skipSll" formControlName="skipSllField"
3939
[ngClass]="{'hide': fixedUrl, 'show': !fixedUrl}">Skip SSL validation for the

src/frontend/packages/git/src/shared/components/git-registration/git-registration.component.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { ConnectEndpointConfig } from '../../../../../core/src/features/endpoint
1313
import { StepOnNextFunction } from '../../../../../core/src/shared/components/stepper/step/step.component';
1414
import { SessionService } from '../../../../../core/src/shared/services/session.service';
1515
import { CurrentUserPermissionsService } from '../../../../../core/src/core/permissions/current-user-permissions.service';
16+
import { UserProfileService } from '../../../../../core/src/core/user-profile.service';
1617
import { SnackBarService } from '../../../../../core/src/shared/services/snackbar.service';
1718
import { getFullEndpointApiUrl } from '../../../../../store/src/endpoint-utils';
1819
import { entityCatalog } from '../../../../../store/src/public-api';
@@ -77,9 +78,10 @@ export class GitRegistrationComponent extends CreateEndpointHelperComponent impl
7778
private snackBarService: SnackBarService,
7879
private endpointsService: EndpointsService,
7980
public sessionService: SessionService,
80-
public currentUserPermissionsService: CurrentUserPermissionsService
81+
public currentUserPermissionsService: CurrentUserPermissionsService,
82+
public userProfileService: UserProfileService
8183
) {
82-
super(sessionService, currentUserPermissionsService);
84+
super(sessionService, currentUserPermissionsService, userProfileService);
8385
this.epSubType = getIdFromRoute(activatedRoute, 'subtype');
8486
const githubLabel = entityCatalog.getEndpoint(GIT_ENDPOINT_TYPE, GIT_ENDPOINT_SUB_TYPES.GITHUB).definition.label || 'Github';
8587
const gitlabLabel = entityCatalog.getEndpoint(GIT_ENDPOINT_TYPE, GIT_ENDPOINT_SUB_TYPES.GITLAB).definition.label || 'Gitlab';
@@ -159,7 +161,7 @@ export class GitRegistrationComponent extends CreateEndpointHelperComponent impl
159161
nameField: ['', [Validators.required]],
160162
urlField: ['', [Validators.required]],
161163
skipSllField: [false, []],
162-
createUserEndpointField: [false, []],
164+
createSystemEndpointField: [true, []],
163165
});
164166
this.updateType();
165167

@@ -201,10 +203,10 @@ export class GitRegistrationComponent extends CreateEndpointHelperComponent impl
201203
const skipSSL = this.registerForm.controls.nameField.value && this.registerForm.controls.urlField.value ?
202204
this.registerForm.controls.skipSllField.value :
203205
false;
204-
const createUserEndpoint = this.registerForm.controls.createUserEndpointField.value;
206+
const createSystemEndpoint = this.registerForm.controls.createSystemEndpointField.value;
205207

206208
return stratosEntityCatalog.endpoint.api.register<ActionState>(GIT_ENDPOINT_TYPE,
207-
this.epSubType, name, url, skipSSL, '', '', false, createUserEndpoint)
209+
this.epSubType, name, url, skipSSL, '', '', false, createSystemEndpoint)
208210
.pipe(
209211
pairwise(),
210212
filter(([oldVal, newVal]) => (oldVal.busy && !newVal.busy)),
@@ -240,7 +242,7 @@ export class GitRegistrationComponent extends CreateEndpointHelperComponent impl
240242
return ready + '/' + defn.urlSuffix;
241243
}
242244

243-
toggleCreateUserEndpoint() {
245+
toggleCreateSystemEndpoint() {
244246
// wait a tick for validators to adjust to new data in the directive
245247
setTimeout(() => {
246248
this.registerForm.controls.nameField.updateValueAndValidity();

src/frontend/packages/store/src/actions/endpoint.actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export class RegisterEndpoint extends SingleBaseEndpointAction {
215215
public clientID = '',
216216
public clientSecret = '',
217217
public ssoAllowed: boolean,
218-
public createUserEndpoint: boolean,
218+
public createSystemEndpoint: boolean,
219219
) {
220220
super(
221221
REGISTER_ENDPOINTS,

src/frontend/packages/store/src/effects/endpoint.effects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export class EndpointsEffect {
195195
cnsi_client_id: action.clientID,
196196
cnsi_client_secret: action.clientSecret,
197197
sso_allowed: action.ssoAllowed ? 'true' : 'false',
198-
create_user_endpoint: action.createUserEndpoint ? 'true' : 'false'
198+
create_system_endpoint: action.createSystemEndpoint ? 'true' : 'false'
199199
};
200200
// Do not include sub_type in HttpParams if it doesn't exist (falsies get stringified and sent)
201201
if (action.endpointSubType) {

src/frontend/packages/store/src/stratos-action-builders.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface EndpointActionBuilder extends OrchestratedActionBuilders {
6060
clientID?: string,
6161
clientSecret?: string,
6262
ssoAllowed?: boolean,
63-
createUserEndpointField?: boolean,
63+
createSystemEndpointField?: boolean,
6464
) => RegisterEndpoint;
6565
update: (
6666
guid: string,
@@ -105,7 +105,7 @@ export const endpointActionBuilder: EndpointActionBuilder = {
105105
clientID?: string,
106106
clientSecret?: string,
107107
ssoAllowed?: boolean,
108-
createUserEndpoint?: boolean,
108+
createSystemEndpoint?: boolean,
109109
) => new RegisterEndpoint(
110110
endpointType,
111111
endpointSubType,
@@ -115,7 +115,7 @@ export const endpointActionBuilder: EndpointActionBuilder = {
115115
clientID,
116116
clientSecret,
117117
ssoAllowed,
118-
createUserEndpoint,
118+
createSystemEndpoint,
119119
),
120120
update: (
121121
guid: string,

src/jetstream/cnsi.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ func (p *portalProxy) RegisterEndpoint(c echo.Context, fetchInfo interfaces.Info
6363
cnsiClientSecret := params.CNSIClientSecret
6464
subType := params.SubType
6565

66-
createUserEndpoint, err := strconv.ParseBool(params.CreateUserEndpoint)
66+
createSystemEndpoint, err := strconv.ParseBool(params.CreateSystemEndpoint)
6767
if err != nil {
68-
// default to false
69-
createUserEndpoint = false
68+
// default to true
69+
createSystemEndpoint = true
7070
}
7171

7272
if cnsiClientId == "" {
@@ -82,7 +82,7 @@ func (p *portalProxy) RegisterEndpoint(c echo.Context, fetchInfo interfaces.Info
8282
"Failed to get session user: %v", err)
8383
}
8484

85-
newCNSI, err := p.DoRegisterEndpoint(params.CNSIName, params.APIEndpoint, skipSSLValidation, cnsiClientId, cnsiClientSecret, userID, ssoAllowed, subType, createUserEndpoint, fetchInfo)
85+
newCNSI, err := p.DoRegisterEndpoint(params.CNSIName, params.APIEndpoint, skipSSLValidation, cnsiClientId, cnsiClientSecret, userID, ssoAllowed, subType, createSystemEndpoint, fetchInfo)
8686
if err != nil {
8787
return err
8888
}
@@ -91,7 +91,7 @@ func (p *portalProxy) RegisterEndpoint(c echo.Context, fetchInfo interfaces.Info
9191
return nil
9292
}
9393

94-
func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, createUserEndpoint bool, fetchInfo interfaces.InfoFunc) (interfaces.CNSIRecord, error) {
94+
func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, skipSSLValidation bool, clientId string, clientSecret string, userId string, ssoAllowed bool, subType string, createSystemEndpoint bool, fetchInfo interfaces.InfoFunc) (interfaces.CNSIRecord, error) {
9595
log.Debug("DoRegisterEndpoint")
9696

9797
if len(cnsiName) == 0 || len(apiEndpoint) == 0 {
@@ -150,7 +150,7 @@ func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, sk
150150
// check if we've already got this APIEndpoint in this DB
151151
for _, duplicate := range duplicateEndpoints {
152152
// cant create same system endpoint
153-
if len(duplicate.Creator) == 0 && isAdmin && !createUserEndpoint {
153+
if len(duplicate.Creator) == 0 && isAdmin && createSystemEndpoint {
154154
return interfaces.CNSIRecord{}, interfaces.NewHTTPShadowError(
155155
http.StatusBadRequest,
156156
"Can not register same system endpoint multiple times",
@@ -171,7 +171,7 @@ func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, sk
171171

172172
h := sha1.New()
173173
// see why its generated this way in Issue #4753 / #3031
174-
if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.Disabled && (!isAdmin || createUserEndpoint) {
174+
if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.Disabled && (!isAdmin || (isAdmin && !createSystemEndpoint)) {
175175
// Make the new guid unique per api url AND user id
176176
h.Write([]byte(apiEndpointURL.String() + userId))
177177
} else {
@@ -204,7 +204,7 @@ func (p *portalProxy) DoRegisterEndpoint(cnsiName string, apiEndpoint string, sk
204204
newCNSI.SubType = subType
205205

206206
// admins currently can't create user endpoints
207-
if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.Disabled && (!isAdmin || createUserEndpoint) {
207+
if p.GetConfig().UserEndpointsEnabled != config.UserEndpointsConfigEnum.Disabled && (!isAdmin || !createSystemEndpoint) {
208208
newCNSI.Creator = userId
209209
}
210210

0 commit comments

Comments
 (0)