This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server/ui): toggle components feature when it's not available (#…
- Loading branch information
Showing
30 changed files
with
255 additions
and
77 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
component/src/main/java/com/chutneytesting/feature/ComponentFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.chutneytesting.feature; | ||
|
||
import com.chutneytesting.server.core.domain.feature.Feature; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ComponentFeature implements Feature { | ||
|
||
@Override | ||
public String name() { | ||
return "COMPONENT"; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
server-core/src/main/java/com/chutneytesting/server/core/domain/feature/Feature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.chutneytesting.server.core.domain.feature; | ||
|
||
public interface Feature { | ||
|
||
String name(); | ||
default boolean active() {return true;} | ||
} |
26 changes: 26 additions & 0 deletions
26
server/src/main/java/com/chutneytesting/feature/api/FeatureController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.chutneytesting.feature.api; | ||
|
||
import com.chutneytesting.feature.api.dto.FeatureDto; | ||
import com.chutneytesting.server.core.domain.feature.Feature; | ||
import java.util.List; | ||
import org.springframework.web.bind.annotation.CrossOrigin; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v2/features") | ||
@CrossOrigin(origins = "*") | ||
public class FeatureController { | ||
|
||
private final List<Feature> features; | ||
|
||
public FeatureController(List<Feature> features) { | ||
this.features = features; | ||
} | ||
|
||
@GetMapping | ||
public List<FeatureDto> getAll() { | ||
return features.stream().map(feature -> new FeatureDto(feature.name(), feature.active())).toList(); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
server/src/main/java/com/chutneytesting/feature/api/dto/FeatureDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.chutneytesting.feature.api.dto; | ||
|
||
public record FeatureDto(String name, boolean active) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface Feature { | ||
name: FeatureName, | ||
active: boolean | ||
} | ||
|
||
export enum FeatureName { | ||
COMPONENT='COMPONENT' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { BehaviorSubject, Observable, of } from 'rxjs'; | ||
import { Feature, FeatureName } from '@core/feature/feature.model'; | ||
import { environment } from '@env/environment'; | ||
import { filter, tap } from 'rxjs/operators'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class FeatureService { | ||
|
||
private readonly featuresApi = '/api/v2/features'; | ||
|
||
private features$:BehaviorSubject<Feature[]> = new BehaviorSubject([]); | ||
|
||
constructor(private http: HttpClient) { | ||
} | ||
|
||
active(featuresName: FeatureName): boolean { | ||
if(!featuresName) { | ||
return true; | ||
} | ||
const activeFeatures = this.features$.value.filter(feature => feature.active).map(feature => feature.name); | ||
return activeFeatures.includes(featuresName); | ||
} | ||
|
||
loadFeatures(): Observable<Feature[]> { | ||
return this.http.get<Feature[]>(environment.backend + this.featuresApi) | ||
.pipe( | ||
tap(features => this.features$.next(features)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
import { Feature } from '@core/feature/feature.model'; | ||
import { FeatureService } from '@core/feature/feature.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class FeaturesResolver implements Resolve<Feature[]> { | ||
|
||
constructor(private featureService: FeatureService) { | ||
} | ||
|
||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Feature[]> { | ||
return this.featureService.loadFeatures(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router'; | ||
import { FeatureService } from '@core/feature/feature.service'; | ||
import { AlertService } from '@shared'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class FeaturesGuard implements CanActivate { | ||
constructor(private featureService: FeatureService, | ||
private alertService: AlertService, | ||
private translateService: TranslateService) { | ||
} | ||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { | ||
const canAccess = this.featureService.active(route.data['feature']); | ||
if (!canAccess) { | ||
this.alertService.error(this.translateService.instant('login.unauthorized'), { timeOut: 0, extendedTimeOut: 0, closeButton: true }); | ||
} | ||
return canAccess; | ||
} | ||
|
||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
ui/src/app/app.theme.factory.ts → ...app/core/initializer/theme.initializer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { ThemeService } from '@core/theme/theme.service'; | ||
|
||
|
||
export function initializeThemeFactory(themeService: ThemeService): () => void { | ||
export function themeInitializer(themeService: ThemeService): () => void { | ||
return () => themeService.applyCurrentTheme(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { AgentNetworkComponent } from './components/agent-network/agent-network.component'; | ||
import { Routes } from '@angular/router'; | ||
import { Authorization } from '@model'; | ||
|
||
export const AgentNetworkRoute: Routes = [ | ||
{ | ||
path: '', | ||
component: AgentNetworkComponent | ||
component: AgentNetworkComponent, | ||
data: { 'authorizations': [ Authorization.ADMIN_ACCESS ] } | ||
} | ||
]; |
Oops, something went wrong.