Ability to remove version control settings
This commit is contained in:
parent
2eb94fd95e
commit
587066cfd3
@ -19,13 +19,16 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.thingsboard.rule.engine.api.MailService;
|
import org.thingsboard.rule.engine.api.MailService;
|
||||||
import org.thingsboard.rule.engine.api.SmsService;
|
import org.thingsboard.rule.engine.api.SmsService;
|
||||||
import org.thingsboard.server.common.data.AdminSettings;
|
import org.thingsboard.server.common.data.AdminSettings;
|
||||||
|
import org.thingsboard.server.common.data.Device;
|
||||||
import org.thingsboard.server.common.data.UpdateMessage;
|
import org.thingsboard.server.common.data.UpdateMessage;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
|
import org.thingsboard.server.common.data.id.DeviceId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.security.model.SecuritySettings;
|
import org.thingsboard.server.common.data.security.model.SecuritySettings;
|
||||||
import org.thingsboard.server.common.data.sms.config.TestSmsRequest;
|
import org.thingsboard.server.common.data.sms.config.TestSmsRequest;
|
||||||
@ -38,8 +41,8 @@ import org.thingsboard.server.service.security.system.SystemSecurityService;
|
|||||||
import org.thingsboard.server.service.sync.vc.EntitiesVersionControlService;
|
import org.thingsboard.server.service.sync.vc.EntitiesVersionControlService;
|
||||||
import org.thingsboard.server.service.update.UpdateService;
|
import org.thingsboard.server.service.update.UpdateService;
|
||||||
|
|
||||||
import static org.thingsboard.server.controller.ControllerConstants.SYSTEM_AUTHORITY_PARAGRAPH;
|
import static org.thingsboard.server.controller.ControllerConstants.*;
|
||||||
import static org.thingsboard.server.controller.ControllerConstants.TENANT_AUTHORITY_PARAGRAPH;
|
import static org.thingsboard.server.controller.ControllerConstants.DEVICE_ID;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@TbCoreComponent
|
@TbCoreComponent
|
||||||
@ -203,7 +206,7 @@ public class AdminController extends BaseController {
|
|||||||
@ApiOperation(value = "Creates or Updates the version control settings (saveVersionControlSettings)",
|
@ApiOperation(value = "Creates or Updates the version control settings (saveVersionControlSettings)",
|
||||||
notes = "Creates or Updates the version control settings object. " + TENANT_AUTHORITY_PARAGRAPH)
|
notes = "Creates or Updates the version control settings object. " + TENANT_AUTHORITY_PARAGRAPH)
|
||||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||||
@PostMapping("/vsSettings")
|
@PostMapping("/vcSettings")
|
||||||
public void saveVersionControlSettings(@RequestBody EntitiesVersionControlSettings settings) throws ThingsboardException {
|
public void saveVersionControlSettings(@RequestBody EntitiesVersionControlSettings settings) throws ThingsboardException {
|
||||||
try {
|
try {
|
||||||
accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.WRITE);
|
accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.WRITE);
|
||||||
@ -213,6 +216,21 @@ public class AdminController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "Delete version control settings (deleteVersionControlSettings)",
|
||||||
|
notes = "Deletes the version control settings."
|
||||||
|
+ TENANT_AUTHORITY_PARAGRAPH)
|
||||||
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||||
|
@RequestMapping(value = "/vcSettings", method = RequestMethod.DELETE)
|
||||||
|
@ResponseStatus(value = HttpStatus.OK)
|
||||||
|
public void deleteVersionControlSettings() throws ThingsboardException {
|
||||||
|
try {
|
||||||
|
accessControlService.checkPermission(getCurrentUser(), Resource.ADMIN_SETTINGS, Operation.DELETE);
|
||||||
|
versionControlService.deleteVersionControlSettings(getTenantId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw handleException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Check version control access (checkVersionControlAccess)",
|
@ApiOperation(value = "Check version control access (checkVersionControlAccess)",
|
||||||
notes = "Attempts to check version control access. " + TENANT_AUTHORITY_PARAGRAPH)
|
notes = "Attempts to check version control access. " + TENANT_AUTHORITY_PARAGRAPH)
|
||||||
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
|
||||||
|
|||||||
@ -312,6 +312,13 @@ public class DefaultEntitiesVersionControlService implements EntitiesVersionCont
|
|||||||
return savedVersionControlSettings;
|
return savedVersionControlSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteVersionControlSettings(TenantId tenantId) {
|
||||||
|
if (adminSettingsService.deleteAdminSettings(tenantId, SETTINGS_KEY)) {
|
||||||
|
gitService.clearRepository(tenantId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void checkVersionControlAccess(TenantId tenantId, EntitiesVersionControlSettings settings) throws ThingsboardException {
|
public void checkVersionControlAccess(TenantId tenantId, EntitiesVersionControlSettings settings) throws ThingsboardException {
|
||||||
EntitiesVersionControlSettings storedSettings = getVersionControlSettings(tenantId);
|
EntitiesVersionControlSettings storedSettings = getVersionControlSettings(tenantId);
|
||||||
|
|||||||
@ -58,6 +58,8 @@ public interface EntitiesVersionControlService {
|
|||||||
|
|
||||||
EntitiesVersionControlSettings saveVersionControlSettings(TenantId tenantId, EntitiesVersionControlSettings versionControlSettings);
|
EntitiesVersionControlSettings saveVersionControlSettings(TenantId tenantId, EntitiesVersionControlSettings versionControlSettings);
|
||||||
|
|
||||||
|
void deleteVersionControlSettings(TenantId tenantId);
|
||||||
|
|
||||||
void checkVersionControlAccess(TenantId tenantId, EntitiesVersionControlSettings settings) throws ThingsboardException;
|
void checkVersionControlAccess(TenantId tenantId, EntitiesVersionControlSettings settings) throws ThingsboardException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -111,6 +111,20 @@ public class LocalGitVersionControlService implements GitVersionControlService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearRepository(TenantId tenantId) {
|
||||||
|
var lock = getRepoLock(tenantId);
|
||||||
|
lock.lock();
|
||||||
|
try {
|
||||||
|
gitRepositoryService.clearRepository(tenantId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
//TODO: analyze and return meaningful exceptions that we can show to the client;
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PendingCommit prepareCommit(TenantId tenantId, VersionCreateRequest request) {
|
public PendingCommit prepareCommit(TenantId tenantId, VersionCreateRequest request) {
|
||||||
var lock = getRepoLock(tenantId);
|
var lock = getRepoLock(tenantId);
|
||||||
|
|||||||
@ -27,4 +27,6 @@ public interface AdminSettingsService {
|
|||||||
|
|
||||||
AdminSettings saveAdminSettings(TenantId tenantId, AdminSettings adminSettings);
|
AdminSettings saveAdminSettings(TenantId tenantId, AdminSettings adminSettings);
|
||||||
|
|
||||||
|
boolean deleteAdminSettings(TenantId tenantId, String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -224,7 +224,8 @@ public class DefaultGitRepositoryService implements GitRepositoryService {
|
|||||||
repositories.put(tenantId, repository);
|
repositories.put(tenantId, repository);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearRepository(TenantId tenantId) throws IOException {
|
@Override
|
||||||
|
public void clearRepository(TenantId tenantId) throws IOException {
|
||||||
GitRepository repository = repositories.get(tenantId);
|
GitRepository repository = repositories.get(tenantId);
|
||||||
if (repository != null) {
|
if (repository != null) {
|
||||||
FileUtils.deleteDirectory(new File(repository.getDirectory()));
|
FileUtils.deleteDirectory(new File(repository.getDirectory()));
|
||||||
|
|||||||
@ -36,6 +36,8 @@ public interface GitRepositoryService {
|
|||||||
|
|
||||||
void initRepository(TenantId tenantId, EntitiesVersionControlSettings settings) throws Exception;
|
void initRepository(TenantId tenantId, EntitiesVersionControlSettings settings) throws Exception;
|
||||||
|
|
||||||
|
void clearRepository(TenantId tenantId) throws IOException;
|
||||||
|
|
||||||
void add(PendingCommit commit, String relativePath, String entityDataJson) throws IOException;
|
void add(PendingCommit commit, String relativePath, String entityDataJson) throws IOException;
|
||||||
|
|
||||||
void deleteFolderContent(PendingCommit commit, String relativePath) throws IOException;
|
void deleteFolderContent(PendingCommit commit, String relativePath) throws IOException;
|
||||||
|
|||||||
@ -34,6 +34,8 @@ public interface GitVersionControlService {
|
|||||||
|
|
||||||
void initRepository(TenantId tenantId, EntitiesVersionControlSettings settings);
|
void initRepository(TenantId tenantId, EntitiesVersionControlSettings settings);
|
||||||
|
|
||||||
|
void clearRepository(TenantId tenantId);
|
||||||
|
|
||||||
PendingCommit prepareCommit(TenantId tenantId, VersionCreateRequest request);
|
PendingCommit prepareCommit(TenantId tenantId, VersionCreateRequest request);
|
||||||
|
|
||||||
void addToCommit(PendingCommit commit, EntityExportData<ExportableEntity<EntityId>> entityData);
|
void addToCommit(PendingCommit commit, EntityExportData<ExportableEntity<EntityId>> entityData);
|
||||||
|
|||||||
@ -39,4 +39,6 @@ public interface AdminSettingsDao extends Dao<AdminSettings> {
|
|||||||
*/
|
*/
|
||||||
AdminSettings findByTenantIdAndKey(UUID tenantId, String key);
|
AdminSettings findByTenantIdAndKey(UUID tenantId, String key);
|
||||||
|
|
||||||
|
boolean removeByTenantIdAndKey(UUID tenantId, String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,4 +62,10 @@ public class AdminSettingsServiceImpl implements AdminSettingsService {
|
|||||||
return adminSettingsDao.save(tenantId, adminSettings);
|
return adminSettingsDao.save(tenantId, adminSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean deleteAdminSettings(TenantId tenantId, String key) {
|
||||||
|
log.trace("Executing deleteAdminSettings, tenantId [{}], key [{}]", tenantId, key);
|
||||||
|
Validator.validateString(key, "Incorrect key " + key);
|
||||||
|
return adminSettingsDao.removeByTenantIdAndKey(tenantId.getId(), key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,4 +27,8 @@ public interface AdminSettingsRepository extends JpaRepository<AdminSettingsEnti
|
|||||||
|
|
||||||
AdminSettingsEntity findByTenantIdAndKey(UUID tenantId, String key);
|
AdminSettingsEntity findByTenantIdAndKey(UUID tenantId, String key);
|
||||||
|
|
||||||
|
void deleteByTenantIdAndKey(UUID tenantId, String key);
|
||||||
|
|
||||||
|
boolean existsByTenantIdAndKey(UUID tenantId, String key);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,4 +49,13 @@ public class JpaAdminSettingsDao extends JpaAbstractDao<AdminSettingsEntity, Adm
|
|||||||
public AdminSettings findByTenantIdAndKey(UUID tenantId, String key) {
|
public AdminSettings findByTenantIdAndKey(UUID tenantId, String key) {
|
||||||
return DaoUtil.getData(adminSettingsRepository.findByTenantIdAndKey(tenantId, key));
|
return DaoUtil.getData(adminSettingsRepository.findByTenantIdAndKey(tenantId, key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeByTenantIdAndKey(UUID tenantId, String key) {
|
||||||
|
if (adminSettingsRepository.existsByTenantIdAndKey(tenantId, key)) {
|
||||||
|
adminSettingsRepository.deleteByTenantIdAndKey(tenantId, key);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user