Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tta 94 refactor endpoints to make it work on tt stage and tt prod (#903)
* Innecesary env files deleted

* New changes to env files

* Add 1 git-crypt collaborator

New collaborators:

	F295BDD1 Marco Aguirre <[email protected]>

* Add 1 git-crypt collaborator

New collaborators:

	1CC2872D Rodolfo Diaz <[email protected]>

* Add 2 git-crypt collaborators

New collaborators:

	1CC2872D Rodolfo Diaz <[email protected]>
	F295BDD1 Marco Aguirre <[email protected]>

* New keys and env variables added

* env files added & modified

* Make run now uses .dev.env

* Pipeline modified

* is the .env needed?

* using encrypted .stage.env

* load secrets

* adding env variables

* scopes cannot be empty

* use env

* using env var

* using env file

* adding mask

* using docker buildkit

* only on tags

* using buildkit directly

* using dash source

* docker buildkit

* missing folders added

* nginx fix

* fixing secrets

* problem with double qoutes

* fixing quotes in .stage.env

* fixing secrets

* loading to env

* quotes fixed

* replacing \r

* fixing trailing \n

* one line expose

* fixing endpoint url

* removing unnecessary jobs

* update creds

* adding with space at the end of the file

* primer commit

* cambios en users list components

* Se ajusta la variable isDevelopmentOrProd

* revision tests

* reportsUrl como variable global

Co-authored-by: Marco Aguirre <[email protected]>
Co-authored-by: Marco Aguirre <[email protected]>
Co-authored-by: Rodolfo IOET <[email protected]>
Co-authored-by: jisazac <[email protected]>
Co-authored-by: Juan Isaza <[email protected]>
  • Loading branch information
6 people authored Aug 1, 2022
commit 63d8d3d9d68531557e049a2e85693c70be1a8027
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('ProjectService', () => {
it('update project using PUT from url locally', () => {
const project: Project = { id: '1', name: 'new name', description: 'description', project_type_id: '123', status: 'active'};
service.url = 'projects';
service.isDevelopment = true;
service.isDevelopmentOrProd = true;
service.updateProject(project).subscribe((response) => {
expect(response.name).toBe('new name');
});
Expand All @@ -115,7 +115,7 @@ describe('ProjectService', () => {

it('delete project using DELETE from baseUrl', () => {
const url = `${service.url}/1`;
service.isDevelopment = false;
service.isDevelopmentOrProd = false;
service.deleteProject(projectsList[0].id).subscribe((projectsInResponse) => {
expect(projectsInResponse.filter((project) => project.id !== projectsList[0].id).length).toEqual(2);
});
Expand All @@ -126,7 +126,7 @@ describe('ProjectService', () => {

it('update status project using PUT from baseUrl locally', () => {
const url = `${service.url}/1`;
service.isDevelopment = true;
service.isDevelopmentOrProd = true;
service.deleteProject(projectsList[0].id).subscribe((projectsInResponse) => {
expect(projectsInResponse.filter((project) => project.id !== projectsList[0].id).length).toEqual(2);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Project } from '../../../../../shared/models';
export class ProjectService {
projects: Project[] = [];
url = `${environment.timeTrackerApiUrl}/projects`;
isDevelopment = environment.production === EnvironmentType.TT_DEV;
isDevelopmentOrProd = environment.production === EnvironmentType.TT_DEV || environment.production === EnvironmentType.TT_PROD;

constructor(private http: HttpClient) {}

Expand All @@ -34,7 +34,7 @@ export class ProjectService {

updateProject(projectData): Observable<any> {
const { id } = projectData;
if (this.isDevelopment) {
if (this.isDevelopmentOrProd) {
if (projectData.status === 'active') {
projectData.status = 1;
}
Expand All @@ -43,7 +43,7 @@ export class ProjectService {
}

deleteProject(projectId: string): Observable<any> {
return this.isDevelopment
return this.isDevelopmentOrProd
? this.http.put(`${this.url}/${projectId}`, { status: 0 })
: this.http.delete(`${this.url}/${projectId}`);
}
Expand Down
12 changes: 3 additions & 9 deletions src/app/modules/time-clock/services/entry.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as moment from 'moment';
describe('EntryService', () => {
let service: EntryService;
let httpMock: HttpTestingController;
var reportsUrl = service.urlInProductionLegacy ? service.baseUrl : service.baseUrl + '/report';

beforeEach(() => {
TestBed.configureTestingModule({imports: [HttpClientTestingModule], providers: [DatePipe]});
Expand Down Expand Up @@ -84,15 +85,15 @@ describe('EntryService', () => {
});

it('stops an entry using POST', () => {
service.urlInProduction = true;
service.urlInProductionLegacy = true;
service.stopEntryRunning('id').subscribe();

const updateEntryRequest = httpMock.expectOne(`${service.baseUrl}/id/stop`);
expect(updateEntryRequest.request.method).toBe('POST');
});

it('stops an entry using PUT', () => {
service.urlInProduction = false;
service.urlInProductionLegacy = false;
service.stopEntryRunning('id').subscribe();

const updateEntryRequest = httpMock.expectOne(`${service.baseUrl}/stop`);
Expand All @@ -105,7 +106,6 @@ describe('EntryService', () => {
const pipe: DatePipe = new DatePipe('en');
const timeRange: TimeEntriesTimeRange = {start_date: yesterday, end_date: today};
const userId = '123';
const reportsUrl = service.urlInProduction ? service.baseUrl : service.baseUrl + '/report';
service.loadEntriesByTimeRange(timeRange, userId).subscribe();

const loadEntryRequest = httpMock.expectOne(req => req.method === 'GET' && req.url === reportsUrl);
Expand All @@ -120,9 +120,7 @@ describe('EntryService', () => {
const today = moment(new Date());
const timeRange: TimeEntriesTimeRange = { start_date: yesterday, end_date: today };
const userId = '123';
const reportsUrl = service.urlInProduction ? service.baseUrl : service.baseUrl + '/report';
service.loadEntriesByTimeRange(timeRange, userId).subscribe();

const loadEntryRequest = httpMock.expectOne(req => req.method === 'GET' && req.url === reportsUrl);
expect(loadEntryRequest.request.params.get('limit')).toEqual('9999');
});
Expand All @@ -132,12 +130,8 @@ describe('EntryService', () => {
const today = moment(new Date());
const timeRange: TimeEntriesTimeRange = { start_date: yesterday, end_date: today };
const userId = '123';
const reportsUrl = service.urlInProduction ? service.baseUrl : service.baseUrl + '/report';

service.loadEntriesByTimeRange(timeRange, userId).subscribe();

const loadEntryRequest = httpMock.expectOne(req => req.method === 'GET' && req.url === reportsUrl);

const timezoneOffset = new Date().getTimezoneOffset().toString();
expect(loadEntryRequest.request.params.get('timezone_offset')).toEqual(timezoneOffset);
});
Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/time-clock/services/entry.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class EntryService {

static TIME_ENTRIES_DATE_TIME_FORMAT = 'yyyy-MM-ddTHH:mm:ssZZZZZ';
baseUrl = `${environment.timeTrackerApiUrl}/time-entries`;
urlInProduction = environment.production === EnvironmentType.TT_PROD || environment.production === EnvironmentType.TT_PROD_LEGACY;
urlInProductionLegacy = environment.production === EnvironmentType.TT_PROD_LEGACY;

loadActiveEntry(): Observable<any> {
return this.http.get(`${this.baseUrl}/running`);
Expand All @@ -46,7 +46,7 @@ export class EntryService {
}

stopEntryRunning(idEntry: string): Observable<any> {
return (this.urlInProduction ? this.http.post(`${this.baseUrl}/${idEntry}/stop`, null) : this.http.put(`${this.baseUrl}/stop`, null) );
return (this.urlInProductionLegacy ? this.http.post(`${this.baseUrl}/${idEntry}/stop`, null) : this.http.put(`${this.baseUrl}/stop`, null) );
}

restartEntry(idEntry: string): Observable<Entry> {
Expand All @@ -69,7 +69,7 @@ export class EntryService {

loadEntriesByTimeRange(range: TimeEntriesTimeRange, userId: string): Observable<any> {
const MAX_NUMBER_OF_ENTRIES_FOR_REPORTS = 9999;
const loadEntriesByTimeRangeURL = this.urlInProduction ? this.baseUrl : this.baseUrl + '/report';
const loadEntriesByTimeRangeURL = this.urlInProductionLegacy ? this.baseUrl : this.baseUrl + '/report';
return this.http.get(loadEntriesByTimeRangeURL,
{
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
<td class="col-3 text-center">
<ui-switch
size="small"
(change)="!isDevelopment?switchGroup('time-tracker-admin', user):null; updateRole(ROLES.admin, user, $event);"
(change)="!isDevelopmentOrProd?switchGroup('time-tracker-admin', user):null; updateRole(ROLES.admin, user, $event);"
[checked]="user.groups.includes('time-tracker-admin')"></ui-switch>
admin
<span *ngIf="!isDevelopment">
<span *ngIf="!isDevelopmentOrProd">
<ui-switch
size="small"
(change)="switchGroup('time-tracker-tester', user)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
columnDefs: [{ orderable: false, targets: [2]}]
};
switchGroupsSubscription: Subscription;
isDevelopment = true;
isDevelopmentOrProd = true;

public get ROLES() {
return ROLES;
Expand All @@ -38,7 +38,7 @@ export class UsersListComponent implements OnInit, OnDestroy, AfterViewInit {
}

ngOnInit(): void {
this.isDevelopment = environment.production === EnvironmentType.TT_DEV;
this.isDevelopmentOrProd = environment.production === EnvironmentType.TT_DEV || environment.production === EnvironmentType.TT_PROD;
this.store.dispatch(new LoadUsers());
this.loadUsersSubscription = this.actionsSubject$
.pipe(filter((action: any) => action.type === UserActionTypes.LOAD_USERS_SUCCESS))
Expand Down
8 changes: 4 additions & 4 deletions src/app/modules/users/services/users.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('UsersService', () => {
it('grant role to a User', () => {
const userId = 'userId';
const roleId = 'admin';
service.isProduction = true;
service.isProductionLegacy = true;

service.grantRole(userId, roleId).subscribe();

Expand All @@ -46,7 +46,7 @@ describe('UsersService', () => {
it('grant role to a User locally', () => {
const userId = 'userId';
const roleId = 'admin';
service.isProduction = false;
service.isProductionLegacy = false;

service.grantRole(userId, roleId).subscribe();

Expand All @@ -57,7 +57,7 @@ describe('UsersService', () => {
it('revoke role to a User', () => {
const userId = 'userId';
const roleId = 'admin';
service.isProduction = true;
service.isProductionLegacy = true;

service.revokeRole(userId, roleId).subscribe();

Expand All @@ -68,7 +68,7 @@ describe('UsersService', () => {
it('revoke role to a User locally', () => {
const userId = 'userId';
const roleId = 'admin';
service.isProduction = false;
service.isProductionLegacy = false;

service.revokeRole(userId, roleId).subscribe();

Expand Down
6 changes: 3 additions & 3 deletions src/app/modules/users/services/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EnvironmentType } from './../../../../environments/enum';
providedIn: 'root',
})
export class UsersService {
isProduction = environment.production === EnvironmentType.TT_PROD || environment.production === EnvironmentType.TT_PROD_LEGACY;
isProductionLegacy = environment.production === EnvironmentType.TT_PROD_LEGACY;
constructor(private http: HttpClient) {}

baseUrl = `${environment.timeTrackerApiUrl}/users`;
Expand All @@ -19,13 +19,13 @@ export class UsersService {
}

grantRole(userId: string, roleId: string): Observable<any> {
const url = this.isProduction ? `${this.baseUrl}/${userId}/roles/${roleId}/grant`
const url = this.isProductionLegacy ? `${this.baseUrl}/${userId}/roles/${roleId}/grant`
: `${this.baseUrl}/${userId}/${roleId}/grant`;
return this.http.post(url, null);
}

revokeRole(userId: string, roleId: string): Observable<any> {
const url = this.isProduction ? `${this.baseUrl}/${userId}/roles/${roleId}/revoke`
const url = this.isProductionLegacy ? `${this.baseUrl}/${userId}/roles/${roleId}/revoke`
: `${this.baseUrl}/${userId}/${roleId}/revoke`;
return this.http.post(url, null);
}
Expand Down