2019-08-12 19:34:23 +03:00
|
|
|
///
|
2024-01-09 10:46:16 +02:00
|
|
|
/// Copyright © 2016-2024 The Thingsboard Authors
|
2019-08-12 19:34:23 +03:00
|
|
|
///
|
|
|
|
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
/// you may not use this file except in compliance with the License.
|
|
|
|
|
/// You may obtain a copy of the License at
|
|
|
|
|
///
|
|
|
|
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
///
|
|
|
|
|
/// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
/// See the License for the specific language governing permissions and
|
|
|
|
|
/// limitations under the License.
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
import { Injectable } from '@angular/core';
|
2022-10-17 16:12:34 +03:00
|
|
|
import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils';
|
|
|
|
|
import { Observable } from 'rxjs';
|
2019-08-12 19:34:23 +03:00
|
|
|
import { HttpClient } from '@angular/common/http';
|
2020-11-20 13:08:20 +02:00
|
|
|
import {
|
|
|
|
|
AdminSettings,
|
2022-11-14 11:05:47 +02:00
|
|
|
AutoCommitSettings,
|
2023-06-08 12:30:35 +03:00
|
|
|
MailConfigTemplate,
|
2023-04-05 16:31:39 +03:00
|
|
|
FeaturesInfo,
|
2022-11-14 11:05:47 +02:00
|
|
|
JwtSettings,
|
2020-11-20 13:08:20 +02:00
|
|
|
MailServerSettings,
|
2022-11-14 11:05:47 +02:00
|
|
|
RepositorySettings,
|
|
|
|
|
RepositorySettingsInfo,
|
2020-11-20 13:08:20 +02:00
|
|
|
SecuritySettings,
|
|
|
|
|
TestSmsRequest,
|
2022-11-14 11:05:47 +02:00
|
|
|
UpdateMessage
|
2020-11-20 13:08:20 +02:00
|
|
|
} from '@shared/models/settings.models';
|
2022-05-25 16:26:39 +03:00
|
|
|
import { EntitiesVersionControlService } from '@core/http/entities-version-control.service';
|
|
|
|
|
import { tap } from 'rxjs/operators';
|
2022-11-14 11:05:47 +02:00
|
|
|
import { LoginResponse } from '@shared/models/login.models';
|
2019-08-12 19:34:23 +03:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class AdminService {
|
|
|
|
|
|
|
|
|
|
constructor(
|
2022-05-25 16:26:39 +03:00
|
|
|
private http: HttpClient,
|
|
|
|
|
private entitiesVersionControlService: EntitiesVersionControlService
|
2019-08-12 19:34:23 +03:00
|
|
|
) { }
|
|
|
|
|
|
2019-11-15 12:22:14 +02:00
|
|
|
public getAdminSettings<T>(key: string, config?: RequestConfig): Observable<AdminSettings<T>> {
|
|
|
|
|
return this.http.get<AdminSettings<T>>(`/api/admin/settings/${key}`, defaultHttpOptionsFromConfig(config));
|
2019-08-12 19:34:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public saveAdminSettings<T>(adminSettings: AdminSettings<T>,
|
2019-11-15 12:22:14 +02:00
|
|
|
config?: RequestConfig): Observable<AdminSettings<T>> {
|
|
|
|
|
return this.http.post<AdminSettings<T>>('/api/admin/settings', adminSettings, defaultHttpOptionsFromConfig(config));
|
2019-08-12 19:34:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public sendTestMail(adminSettings: AdminSettings<MailServerSettings>,
|
2019-11-15 12:22:14 +02:00
|
|
|
config?: RequestConfig): Observable<void> {
|
|
|
|
|
return this.http.post<void>('/api/admin/settings/testMail', adminSettings, defaultHttpOptionsFromConfig(config));
|
2019-08-12 19:34:23 +03:00
|
|
|
}
|
|
|
|
|
|
2020-11-20 13:08:20 +02:00
|
|
|
public sendTestSms(testSmsRequest: TestSmsRequest,
|
|
|
|
|
config?: RequestConfig): Observable<void> {
|
|
|
|
|
return this.http.post<void>('/api/admin/settings/testSms', testSmsRequest, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-15 12:22:14 +02:00
|
|
|
public getSecuritySettings(config?: RequestConfig): Observable<SecuritySettings> {
|
|
|
|
|
return this.http.get<SecuritySettings>(`/api/admin/securitySettings`, defaultHttpOptionsFromConfig(config));
|
2019-08-12 19:34:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public saveSecuritySettings(securitySettings: SecuritySettings,
|
2019-11-15 12:22:14 +02:00
|
|
|
config?: RequestConfig): Observable<SecuritySettings> {
|
2019-08-12 19:34:23 +03:00
|
|
|
return this.http.post<SecuritySettings>('/api/admin/securitySettings', securitySettings,
|
2019-11-15 12:22:14 +02:00
|
|
|
defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 11:05:47 +02:00
|
|
|
public getJwtSettings(config?: RequestConfig): Observable<JwtSettings> {
|
|
|
|
|
return this.http.get<JwtSettings>(`/api/admin/jwtSettings`, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public saveJwtSettings(jwtSettings: JwtSettings, config?: RequestConfig): Observable<LoginResponse> {
|
|
|
|
|
return this.http.post<LoginResponse>('/api/admin/jwtSettings', jwtSettings, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 16:16:24 +03:00
|
|
|
public getRepositorySettings(config?: RequestConfig): Observable<RepositorySettings> {
|
|
|
|
|
return this.http.get<RepositorySettings>(`/api/admin/repositorySettings`, defaultHttpOptionsFromConfig(config));
|
2022-05-20 15:02:30 +03:00
|
|
|
}
|
|
|
|
|
|
2022-05-31 16:16:24 +03:00
|
|
|
public saveRepositorySettings(repositorySettings: RepositorySettings,
|
|
|
|
|
config?: RequestConfig): Observable<RepositorySettings> {
|
|
|
|
|
return this.http.post<RepositorySettings>('/api/admin/repositorySettings', repositorySettings,
|
2022-05-25 16:26:39 +03:00
|
|
|
defaultHttpOptionsFromConfig(config)).pipe(
|
|
|
|
|
tap(() => {
|
|
|
|
|
this.entitiesVersionControlService.clearBranchList();
|
|
|
|
|
})
|
|
|
|
|
);
|
2022-05-20 15:02:30 +03:00
|
|
|
}
|
|
|
|
|
|
2022-05-31 16:16:24 +03:00
|
|
|
public deleteRepositorySettings(config?: RequestConfig) {
|
|
|
|
|
return this.http.delete('/api/admin/repositorySettings', defaultHttpOptionsFromConfig(config)).pipe(
|
2022-05-25 16:26:39 +03:00
|
|
|
tap(() => {
|
|
|
|
|
this.entitiesVersionControlService.clearBranchList();
|
|
|
|
|
})
|
|
|
|
|
);
|
2022-05-20 15:02:30 +03:00
|
|
|
}
|
|
|
|
|
|
2022-05-31 16:16:24 +03:00
|
|
|
public checkRepositoryAccess(repositorySettings: RepositorySettings,
|
|
|
|
|
config?: RequestConfig): Observable<void> {
|
|
|
|
|
return this.http.post<void>('/api/admin/repositorySettings/checkAccess', repositorySettings, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 16:12:34 +03:00
|
|
|
public getRepositorySettingsInfo(config?: RequestConfig): Observable<RepositorySettingsInfo> {
|
|
|
|
|
return this.http.get<RepositorySettingsInfo>('/api/admin/repositorySettings/info', defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 16:16:24 +03:00
|
|
|
public getAutoCommitSettings(config?: RequestConfig): Observable<AutoCommitSettings> {
|
|
|
|
|
return this.http.get<AutoCommitSettings>(`/api/admin/autoCommitSettings`, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 18:42:33 +03:00
|
|
|
public autoCommitSettingsExists(config?: RequestConfig): Observable<boolean> {
|
2022-05-31 16:16:24 +03:00
|
|
|
return this.http.get<boolean>('/api/admin/autoCommitSettings/exists', defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public saveAutoCommitSettings(autoCommitSettings: AutoCommitSettings,
|
|
|
|
|
config?: RequestConfig): Observable<AutoCommitSettings> {
|
|
|
|
|
return this.http.post<AutoCommitSettings>('/api/admin/autoCommitSettings', autoCommitSettings, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public deleteAutoCommitSettings(config?: RequestConfig) {
|
|
|
|
|
return this.http.delete('/api/admin/autoCommitSettings', defaultHttpOptionsFromConfig(config));
|
2022-05-20 15:02:30 +03:00
|
|
|
}
|
|
|
|
|
|
2019-11-15 12:22:14 +02:00
|
|
|
public checkUpdates(config?: RequestConfig): Observable<UpdateMessage> {
|
|
|
|
|
return this.http.get<UpdateMessage>(`/api/admin/updates`, defaultHttpOptionsFromConfig(config));
|
2019-08-12 19:34:23 +03:00
|
|
|
}
|
2023-04-05 16:31:39 +03:00
|
|
|
|
|
|
|
|
public getFeaturesInfo(config?: RequestConfig): Observable<FeaturesInfo> {
|
|
|
|
|
return this.http.get<FeaturesInfo>('/api/admin/featuresInfo', defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
2023-06-08 12:30:35 +03:00
|
|
|
|
|
|
|
|
public getLoginProcessingUrl(config?: RequestConfig): Observable<string> {
|
|
|
|
|
return this.http.get<string>(`/api/admin/mail/oauth2/loginProcessingUrl`, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public generateAccessToken(config?: RequestConfig): Observable<string> {
|
|
|
|
|
return this.http.get<string>(`/api/admin/mail/oauth2/authorize`, defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getMailConfigTemplate(config?: RequestConfig): Observable<Array<MailConfigTemplate>> {
|
|
|
|
|
return this.http.get<Array<MailConfigTemplate>>('/api/mail/config/template', defaultHttpOptionsFromConfig(config));
|
|
|
|
|
}
|
2019-08-12 19:34:23 +03:00
|
|
|
}
|