Fix Trigger Setup Robot Permissions for Private Base (#2543)
This commit is contained in:
parent
2f757faa40
commit
581d7c67a7
5 changed files with 210 additions and 91 deletions
|
@ -1,5 +1,6 @@
|
|||
import { Input, Output, Component, Inject, EventEmitter, OnInit } from 'ng-metadata/core';
|
||||
import * as moment from 'moment';
|
||||
import { Local, Trigger, Repository, Namespace } from '../../../types/common.types';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -12,30 +13,14 @@ import * as moment from 'moment';
|
|||
export class ManageTriggerGithostComponent implements OnInit {
|
||||
|
||||
// FIXME: Use one-way data binding
|
||||
@Input('=') public repository: any;
|
||||
@Input('=') public repository: Repository;
|
||||
@Input('=') public trigger: Trigger;
|
||||
@Output() public activateTrigger: EventEmitter<{config: any, pull_robot?: any}> = new EventEmitter();
|
||||
private config: any;
|
||||
private local: any = {
|
||||
namespaceOptions: {
|
||||
filter: '',
|
||||
predicate: 'score',
|
||||
reverse: false,
|
||||
page: 0
|
||||
},
|
||||
repositoryOptions: {
|
||||
filter: '',
|
||||
predicate: 'score',
|
||||
reverse: false,
|
||||
page: 0,
|
||||
hideStale: true
|
||||
},
|
||||
robotOptions: {
|
||||
filter: '',
|
||||
predicate: 'score',
|
||||
reverse: false,
|
||||
page: 0
|
||||
}
|
||||
public config: any;
|
||||
public local: Local = {
|
||||
namespaceOptions: {filter: '', predicate: 'score', reverse: false, page: 0},
|
||||
repositoryOptions: {filter: '', predicate: 'score', reverse: false, page: 0, hideStale: true},
|
||||
robotOptions: {filter: '', predicate: 'score', reverse: false, page: 0},
|
||||
};
|
||||
private currentState: any | null;
|
||||
private namespacesPerPage: number = 10;
|
||||
|
@ -128,23 +113,21 @@ export class ManageTriggerGithostComponent implements OnInit {
|
|||
context: this.local.dockerContext
|
||||
};
|
||||
|
||||
if (this.local.triggerOptions.hasBranchTagFilter &&
|
||||
this.local.triggerOptions.branchTagFilter) {
|
||||
config['branchtag_regex'] = this.local.triggerOptions.branchTagFilter;
|
||||
if (this.local.triggerOptions['hasBranchTagFilter'] && this.local.triggerOptions['branchTagFilter']) {
|
||||
config['branchtag_regex'] = this.local.triggerOptions['branchTagFilter'];
|
||||
}
|
||||
|
||||
var activate = () => {
|
||||
const activate = () => {
|
||||
this.activateTrigger.emit({config: config, pull_robot: this.local.robotAccount});
|
||||
};
|
||||
|
||||
if (this.local.robotAccount && this.local.triggerAnalysis.status == 'requiresrobot') {
|
||||
if (this.local.triggerAnalysis.status == 'requiresrobot' && this.local.robotAccount) {
|
||||
if (this.local.robotAccount.can_read) {
|
||||
activate();
|
||||
} else {
|
||||
// Add read permission onto the base repository for the robot and then activate the
|
||||
// trigger.
|
||||
var robot_name = this.local.robotAccount.name;
|
||||
this.RolesService.setRepositoryRole(this.repository, 'read', 'robot', robot_name, activate);
|
||||
// Add read permission onto the base repository for the robot and then activate the trigger.
|
||||
const baseRepo: any = {name: this.local.triggerAnalysis.name, namespace: this.local.triggerAnalysis.namespace};
|
||||
this.RolesService.setRepositoryRole(baseRepo, 'read', 'robot', this.local.robotAccount.name, activate);
|
||||
}
|
||||
} else {
|
||||
activate();
|
||||
|
@ -156,7 +139,7 @@ export class ManageTriggerGithostComponent implements OnInit {
|
|||
return;
|
||||
}
|
||||
|
||||
var namespaces = this.local.namespaces || [];
|
||||
var namespaces: Namespace[] = this.local.namespaces || [];
|
||||
this.local.orderedNamespaces = this.TableService.buildOrderedItems(namespaces,
|
||||
this.local.namespaceOptions,
|
||||
['id'],
|
||||
|
@ -305,9 +288,9 @@ export class ManageTriggerGithostComponent implements OnInit {
|
|||
|
||||
var robots = this.local.triggerAnalysis.robots;
|
||||
this.local.orderedRobotAccounts = this.TableService.buildOrderedItems(robots,
|
||||
this.local.robotOptions,
|
||||
['name'],
|
||||
[]);
|
||||
this.local.robotOptions,
|
||||
['name'],
|
||||
[]);
|
||||
}
|
||||
|
||||
private checkDockerfilePath(repository: any, path: string, context: string): void {
|
||||
|
@ -342,38 +325,3 @@ export class ManageTriggerGithostComponent implements OnInit {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A type representing local application data.
|
||||
*/
|
||||
export type Local = {
|
||||
namespaceOptions: {
|
||||
filter: string;
|
||||
predicate: string;
|
||||
reverse: boolean;
|
||||
page: number;
|
||||
};
|
||||
repositoryOptions: {
|
||||
filter: string;
|
||||
predicate: string;
|
||||
reverse: boolean;
|
||||
page: number;
|
||||
hideStale: boolean;
|
||||
};
|
||||
robotOptions: {
|
||||
filter: string;
|
||||
predicate: string;
|
||||
reverse: boolean;
|
||||
page: number;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A type representing a trigger.
|
||||
*/
|
||||
export type Trigger = {
|
||||
id: number;
|
||||
service: any;
|
||||
};
|
Reference in a new issue