Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit cdeb9e6

Browse files
Merge remote-tracking branch 'origin/dev' into long-embedding-names-break-modal
2 parents 834bb98 + d2bef45 commit cdeb9e6

19 files changed

+215
-16
lines changed

src/app/app.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,23 @@ export class AppComponent implements OnDestroy, OnInit {
3838
) { }
3939

4040
ngOnInit(): void {
41-
this.configService.isManaged().pipe(first()).subscribe((v) => ConfigManager.initConfigManager(this.http, this.configService, v));
41+
this.initalRequests();
4242
NotificationService.subscribeToNotification(this, {
4343
whitelist: ['notification_created', 'project_deleted', 'config_updated'],
4444
func: this.handleWebsocketNotification
4545
});
4646
this.initializeNotificationService();
4747
this.initWithConfigManager();
4848
}
49+
50+
initalRequests() {
51+
this.configService.isManaged().pipe(first()).subscribe((v) => ConfigManager.initConfigManager(this.http, this.configService, v));
52+
this.configService.isDemo().pipe(first()).subscribe((v) => ConfigManager.setIsDemo(v));
53+
this.configService.isAdmin().pipe(first()).subscribe((v) => ConfigManager.setIsAdmin(v));
54+
this.configService.getBlackWhiteDemo().pipe(first()).subscribe((v) => ConfigManager.setBlackWhiteListDemo(v));
55+
}
56+
57+
4958
initWithConfigManager() {
5059

5160
if (!ConfigManager.isInit()) {

src/app/app.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
2-
import { NgModule } from '@angular/core';
2+
import { ErrorHandler, NgModule } from '@angular/core';
33
import { BrowserModule } from '@angular/platform-browser';
44
import { AppRoutingModule } from './app-routing.module';
55
import { AppComponent } from './app.component';
66
import { BaseModule } from './base/base.module';
77
import { ExceptionInterceptor } from './base/interceptors/exception.interceptor';
8+
import { GlobalErrorHandler } from './base/interceptors/global-exception.interceptor';
89
import { NotificationService } from './base/services/notification.service';
910
import { DataModule } from './data/data.module';
1011
import { ProjectsModule } from './projects/projects.module';
@@ -50,6 +51,7 @@ import { RecordIDEModule } from './record-ide/record-ide.module';
5051
],
5152
providers: [
5253
{ provide: HTTP_INTERCEPTORS, useClass: ExceptionInterceptor, multi: true },
54+
{ provide: ErrorHandler, useClass: GlobalErrorHandler },
5355
NotificationService,
5456
],
5557
bootstrap: [AppComponent],

src/app/base/components/header/header.component.html

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
<header class="sticky top-0 z-10 w-full">
22
<div
33
class="relative z-10 flex-shrink-0 h-16 bg-white border-b border-gray-200 shadow-sm flex justify-between items-center">
4+
<div *ngIf="hideLogout"
5+
class="absolute top-0 left-0 right-0 bottom-0 flex items-center justify-center pointer-events-none">
6+
<span class="inline-flex items-center px-2 py-0.5 rounded font-medium bg-red-100 text-red-800">
7+
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-play-card mr-2" width="24"
8+
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
9+
stroke-linecap="round" stroke-linejoin="round">
10+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
11+
<rect transform="rotate(90 12 12)" x="3" y="5" width="18" height="14" rx="2"></rect>
12+
<line x1="8" y1="6" x2="8.01" y2="6"></line>
13+
<line x1="16" y1="18" x2="16.01" y2="18"></line>
14+
<path d="M12 16l-3 -4l3 -4l3 4z"></path>
15+
</svg>
16+
Demo Playground - Everything will be reset on the hour
17+
</span>
18+
<!-- <div class="font-bold text-red-500">Demo - Everything will be reset on the hour</div> -->
19+
</div>
420
<div class="flex items-center">
521
<ng-container [ngSwitch]="page">
622
<ng-template [ngSwitchCase]="'projects'">
@@ -58,8 +74,22 @@
5874
</svg>
5975
</a>
6076
</div>
77+
<div class="flex items-center justify-center">
78+
<a href="https://github.com/code-kern-ai/refinery" target="_blank" data-tip="Star us on GitHub"
79+
rel="noopener noreferrer" class="flex mr-6 tooltip tooltip-left">
80+
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-star" width="24"
81+
height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none"
82+
stroke-linecap="round" stroke-linejoin="round">
83+
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
84+
<path
85+
d="M12 17.75l-6.172 3.245l1.179 -6.873l-5 -4.867l6.9 -1l3.086 -6.253l3.086 6.253l6.9 1l-5 4.867l1.179 6.873z">
86+
</path>
87+
</svg>
88+
</a>
89+
90+
</div>
6191
<div class="flex justify-center overflow-visible">
62-
<div *ngIf="user" class="dropdown dropdown-right dropdown-end mr-4">
92+
<div *ngIf="user && !hideLogout" class="dropdown dropdown-right dropdown-end mr-4">
6393
<a tabindex="0" class="w-full cursor-pointer">
6494
<div data-intercom-target="User Avatar Button" (isMenuOpen)="toggleVisible($event, menuButton)"
6595
appDropdown>

src/app/base/components/header/header.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class HeaderComponent implements OnInit, OnDestroy {
2121
subscriptions$: Subscription[] = [];
2222

2323
showConfigSettings: boolean = false;
24+
hideLogout: boolean;
2425

2526
constructor(private auth: AuthApiService,
2627
private router: Router) { }
@@ -33,7 +34,8 @@ export class HeaderComponent implements OnInit, OnDestroy {
3334
timer(250).subscribe(() => this.setShowConfig());
3435
return;
3536
}
36-
this.showConfigSettings = !ConfigManager.getIsManaged()
37+
this.hideLogout = ConfigManager.getIsDemo() && !ConfigManager.getIsAdmin();
38+
this.showConfigSettings = !ConfigManager.getIsManaged();
3739
}
3840

3941
ngOnDestroy(): void {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export class DemoError extends Error {
2+
errorQueryType: string;
3+
errorQueryText: string;
4+
constructor(type: string, queryText: string, msg?: string) {
5+
super(msg);
6+
Object.setPrototypeOf(this, DemoError.prototype);
7+
this.errorQueryType = type;
8+
this.errorQueryText = queryText;
9+
}
10+
11+
errorMessage(): string {
12+
if (this.message) return this.message
13+
return "This function isn't part of the demo application.\nIf you want to test this function, don't hesitate to check out our open-source or hosted versions!";
14+
}
15+
}

src/app/base/interceptors/exception.interceptor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ import {
99
import { Observable, throwError } from 'rxjs';
1010
import { catchError, retry } from 'rxjs/operators';
1111
import { NotificationService } from '../services/notification.service';
12-
1312
@Injectable()
1413
export class ExceptionInterceptor implements HttpInterceptor {
15-
constructor(private notificationService: NotificationService) {}
14+
constructor(private notificationService: NotificationService) { }
1615

1716
intercept(
1817
request: HttpRequest<any>,
1918
next: HttpHandler
2019
): Observable<HttpEvent<any>> {
2120
return next.handle(request).pipe(
22-
retry(1),
2321
catchError((error: HttpErrorResponse) => {
2422
let message = '';
2523
if (error.error instanceof ErrorEvent) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ErrorHandler, Injectable } from '@angular/core';
2+
import { DemoError } from './DemoError';
3+
@Injectable()
4+
export class GlobalErrorHandler implements ErrorHandler {
5+
constructor() { }
6+
7+
handleError(error: any) {
8+
if (error instanceof DemoError) {
9+
alert(error.errorMessage());
10+
} else {
11+
console.error(error);
12+
}
13+
}
14+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
3+
import { Apollo } from 'apollo-angular';
4+
import { QueryOptions, MutationOptions, ApolloQueryResult, FetchResult } from '@apollo/client/core';
5+
import { EmptyObject, WatchQueryOptions } from 'apollo-angular/types';
6+
import { Observable } from 'rxjs';
7+
import { QueryRef } from 'apollo-angular/query-ref';
8+
import { DemoError } from '../../interceptors/DemoError';
9+
import { ConfigManager } from '../config-service';
10+
11+
export class ApolloChecker {
12+
13+
public apollo: Apollo;
14+
constructor(apollo: Apollo) {
15+
this.apollo = apollo;
16+
}
17+
18+
mutate<T, V = EmptyObject>(options: MutationOptions<T, V>): Observable<FetchResult<T>> {
19+
ApolloChecker.checkBlackWhiteList("mutation", options.mutation.loc?.source.body);
20+
return this.apollo.mutate(options)
21+
}
22+
watchQuery<TData, TVariables = EmptyObject>(options: WatchQueryOptions<TVariables, TData>): QueryRef<TData, TVariables> {
23+
ApolloChecker.checkBlackWhiteList("query", options.query.loc?.source.body);
24+
return this.apollo.watchQuery(options);
25+
}
26+
query<T, V = EmptyObject>(options: QueryOptions<V, T>): Observable<ApolloQueryResult<T>> {
27+
ApolloChecker.checkBlackWhiteList("query", options.query.loc?.source.body);
28+
return this.apollo.query(options);
29+
}
30+
31+
private static checkBlackWhiteList(type: string, queryText: string) {
32+
if (!ConfigManager.getIsDemo()) return;
33+
if (ConfigManager.getIsAdmin()) return;
34+
if (!queryText) throw new Error("Can't find query text");
35+
if (!ConfigManager.checkBlackWhiteList(type, queryText)) throw new DemoError(type, queryText);
36+
}
37+
}

src/app/base/services/config-service.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export class ConfigManager {
99
private static http: HttpClient;
1010
private static configApolloService: ConfigApolloService;
1111
private static isManaged: boolean = true;//differentation between propriatary or not
12+
private static isAdmin: boolean = false;
13+
private static isDemo: boolean = false;
14+
private static blackWhiteListDemo: any;
1215
private static registedUpdateListeners: Map<Object, () => void> = new Map<Object, () => void>();
1316
private static justUpdated = false;
1417

@@ -80,5 +83,37 @@ export class ConfigManager {
8083
ConfigManager.registedUpdateListeners.delete(caller);
8184
}
8285

86+
public static setIsAdmin(value: boolean) {
87+
ConfigManager.isAdmin = value;
88+
}
89+
public static getIsAdmin() {
90+
return ConfigManager.isAdmin;
91+
}
92+
93+
public static setIsDemo(value: boolean) {
94+
ConfigManager.isDemo = value;
95+
}
96+
public static getIsDemo() {
97+
return ConfigManager.isDemo;
98+
}
99+
100+
public static setBlackWhiteListDemo(value: any) {
101+
ConfigManager.blackWhiteListDemo = value;
102+
}
103+
104+
public static checkBlackWhiteList(type: string, queryText: string): boolean {
105+
if (!ConfigManager.blackWhiteListDemo) return false;
106+
if (type == "query") {
107+
for (const blacklisted of ConfigManager.blackWhiteListDemo["queries"]) {
108+
if (queryText.indexOf(blacklisted) != -1) return false;
109+
}
110+
return true;
111+
} else {
112+
for (const whitelisted of ConfigManager.blackWhiteListDemo["mutations"]) {
113+
if (queryText.indexOf(whitelisted) != -1) return true;
114+
}
115+
return false;
116+
}
117+
}
83118
}
84119

src/app/base/services/config/config-apollo.service.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
22
import { Apollo } from 'apollo-angular';
33
import { Observable } from 'rxjs';
44
import { map } from 'rxjs/operators';
5+
import { ApolloChecker } from '../base/apollo-checker';
56
import { mutations } from './config-mutations';
67
import { queries } from './config-queries';
78

@@ -11,7 +12,8 @@ import { queries } from './config-queries';
1112
})
1213
export class ConfigApolloService {
1314

14-
constructor(private apollo: Apollo) { }
15+
private apollo: ApolloChecker;
16+
constructor(private apolloBase: Apollo) { this.apollo = new ApolloChecker(this.apolloBase); }
1517

1618
isManaged() {
1719
return this.apollo
@@ -30,4 +32,32 @@ export class ConfigApolloService {
3032
}
3133
});
3234
}
35+
36+
isDemo() {
37+
return this.apollo
38+
.query({
39+
query: queries.IS_DEMO,
40+
fetchPolicy: 'cache-first',
41+
})
42+
.pipe(map((result) => result['data']['isDemo'] != false));
43+
}
44+
45+
isAdmin() {
46+
return this.apollo
47+
.query({
48+
query: queries.IS_AMDIN,
49+
fetchPolicy: 'no-cache',
50+
})
51+
.pipe(map((result) => result['data']['isAdmin'] != false));
52+
}
53+
54+
getBlackWhiteDemo() {
55+
return this.apollo
56+
.query({
57+
query: queries.GET_BLACK_WHITE_DEMO,
58+
fetchPolicy: 'cache-first',
59+
})
60+
.pipe(map((result) => JSON.parse(result['data']['getBlackWhiteDemo'])));
61+
}
62+
3363
}

src/app/base/services/config/config-queries.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,20 @@ export const queries = {
4747
query{
4848
isManaged
4949
}
50+
`,
51+
IS_DEMO: gql`
52+
query{
53+
isDemo
54+
}
55+
`,
56+
IS_AMDIN: gql`
57+
query{
58+
isAdmin
59+
}
60+
`,
61+
GET_BLACK_WHITE_DEMO: gql`
62+
{
63+
getBlackWhiteDemo
64+
}
5065
`
5166
};

src/app/base/services/knowledge-bases/knowledge-bases-apollo.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { Injectable } from '@angular/core';
33
import { mutations } from './knowledge-bases-mutations';
44
import { queries } from './knowledge-bases-queries';
55
import { map } from 'rxjs/operators';
6+
import { ApolloChecker } from '../base/apollo-checker';
67

78
@Injectable({
89
providedIn: 'root',
910
})
1011
export class KnowledgeBasesApolloService {
11-
constructor(private apollo: Apollo) { }
12+
private apollo: ApolloChecker;
13+
constructor(private apolloBase: Apollo) { this.apollo = new ApolloChecker(this.apolloBase); }
1214

1315
createKnowledgeBase(projectId: string) {
1416
return this.apollo.mutate({

src/app/base/services/notification/notification-apollo.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { Injectable } from '@angular/core';
22
import { Apollo } from 'apollo-angular';
33
import { NotificationType } from 'aws-sdk/clients/budgets';
44
import { map } from 'rxjs/operators';
5+
import { ApolloChecker } from '../base/apollo-checker';
56
import { mutations } from './notification-mutations';
67
import { queries } from './notification-queries';
78

89
@Injectable({
910
providedIn: 'root',
1011
})
1112
export class NotificationApolloService {
12-
constructor(private apollo: Apollo) { }
13+
private apollo: ApolloChecker;
14+
constructor(private apolloBase: Apollo) { this.apollo = new ApolloChecker(this.apolloBase); }
1315

1416
getNotificationsByUser() {
1517
const query = this.apollo

src/app/base/services/organization/organization-apollo.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Apollo } from 'apollo-angular';
33
import { Observable } from 'rxjs';
44
import { map } from 'rxjs/operators';
55
import { Organization } from '../../entities/organization';
6+
import { ApolloChecker } from '../base/apollo-checker';
67
import { mutations } from './organization-mutations';
78
import { queries } from './organization-queries';
89

@@ -12,7 +13,8 @@ import { queries } from './organization-queries';
1213
})
1314
export class OrganizationApolloService {
1415

15-
constructor(private apollo: Apollo) { }
16+
private apollo: ApolloChecker;
17+
constructor(private apolloBase: Apollo) { this.apollo = new ApolloChecker(this.apolloBase); }
1618

1719
createOrganization(name: string) {
1820
return this.apollo

src/app/base/services/project/project-apollo.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ import { Apollo } from 'apollo-angular';
33
import { Observable } from 'rxjs';
44
import { map } from 'rxjs/operators';
55
import { Project } from '../../entities/project';
6+
import { ApolloChecker } from '../base/apollo-checker';
67
import { mutations } from './project-mutations';
78
import { queries } from './project-queries';
89

910
@Injectable({
1011
providedIn: 'root',
1112
})
1213
export class ProjectApolloService {
13-
constructor(private apollo: Apollo) { }
14+
private apollo: ApolloChecker;
15+
constructor(private apolloBase: Apollo) { this.apollo = new ApolloChecker(this.apolloBase) }
1416

1517
createProject(projectName: string, description: string) {
1618
return this.apollo

0 commit comments

Comments
 (0)