ci: Added pre-commit hook to check for Spotless formatting (#25228)
This commit is contained in:
parent
0cc716c2a5
commit
fca545a115
|
|
@ -2,3 +2,7 @@
|
|||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npx lint-staged --cwd app/client && git-secrets --scan --untracked && git-secrets --scan -r
|
||||
|
||||
echo "Running Spotless check ..."
|
||||
pushd app/server > /dev/null
|
||||
(mvn spotless:check 1> /dev/null && popd > /dev/null) || (echo "Spotless check failed, please run mvn spotless:apply" && exit 1)
|
||||
|
|
|
|||
|
|
@ -12,5 +12,4 @@ public class S3PluginConstants {
|
|||
public static final String AWS_S3_SERVICE_PROVIDER = "amazon-s3";
|
||||
public static String DEFAULT_FILE_NAME = "MyFile.txt";
|
||||
public static final String ACCESS_DENIED_ERROR_CODE = "AccessDenied";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,9 +99,8 @@ public class AuthenticationSuccessHandlerCE implements ServerAuthenticationSucce
|
|||
// verification this can be eliminated safely
|
||||
if (user.getPassword() != null) {
|
||||
user.setPassword(null);
|
||||
user.setSource(
|
||||
LoginSource.fromString(((OAuth2AuthenticationToken) authentication).getAuthorizedClientRegistrationId())
|
||||
);
|
||||
user.setSource(LoginSource.fromString(
|
||||
((OAuth2AuthenticationToken) authentication).getAuthorizedClientRegistrationId()));
|
||||
// Update the user in separate thread
|
||||
userRepository
|
||||
.save(user)
|
||||
|
|
|
|||
|
|
@ -8,10 +8,14 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CacheableFeatureFlagHelperImpl extends CacheableFeatureFlagHelperCEImpl implements CacheableFeatureFlagHelper {
|
||||
public CacheableFeatureFlagHelperImpl(TenantService tenantService, ConfigService configService,
|
||||
CloudServicesConfig cloudServicesConfig, CommonConfig commonConfig,
|
||||
UserIdentifierService userIdentifierService) {
|
||||
public class CacheableFeatureFlagHelperImpl extends CacheableFeatureFlagHelperCEImpl
|
||||
implements CacheableFeatureFlagHelper {
|
||||
public CacheableFeatureFlagHelperImpl(
|
||||
TenantService tenantService,
|
||||
ConfigService configService,
|
||||
CloudServicesConfig cloudServicesConfig,
|
||||
CommonConfig commonConfig,
|
||||
UserIdentifierService userIdentifierService) {
|
||||
super(tenantService, configService, cloudServicesConfig, commonConfig, userIdentifierService);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,9 +36,12 @@ public class CacheableFeatureFlagHelperCEImpl implements CacheableFeatureFlagHel
|
|||
|
||||
private final UserIdentifierService userIdentifierService;
|
||||
|
||||
public CacheableFeatureFlagHelperCEImpl(TenantService tenantService, ConfigService configService,
|
||||
CloudServicesConfig cloudServicesConfig, CommonConfig commonConfig,
|
||||
UserIdentifierService userIdentifierService) {
|
||||
public CacheableFeatureFlagHelperCEImpl(
|
||||
TenantService tenantService,
|
||||
ConfigService configService,
|
||||
CloudServicesConfig cloudServicesConfig,
|
||||
CommonConfig commonConfig,
|
||||
UserIdentifierService userIdentifierService) {
|
||||
this.tenantService = tenantService;
|
||||
this.configService = configService;
|
||||
this.cloudServicesConfig = cloudServicesConfig;
|
||||
|
|
@ -58,24 +61,23 @@ public class CacheableFeatureFlagHelperCEImpl implements CacheableFeatureFlagHel
|
|||
}
|
||||
|
||||
private Mono<Map<String, Object>> getUserDefaultTraits(User user) {
|
||||
return configService.getInstanceId()
|
||||
.map(instanceId -> {
|
||||
Map<String, Object> userTraits = new HashMap<>();
|
||||
String emailTrait;
|
||||
if (!commonConfig.isCloudHosting()) {
|
||||
emailTrait = userIdentifierService.hash(user.getEmail());
|
||||
} else {
|
||||
emailTrait = user.getEmail();
|
||||
}
|
||||
userTraits.put("email", emailTrait);
|
||||
userTraits.put("instanceId", instanceId);
|
||||
userTraits.put("tenantId", user.getTenantId());
|
||||
userTraits.put("isTelemetryOn", !commonConfig.isTelemetryDisabled());
|
||||
userTraits.put("createdAt", user.getCreatedAt());
|
||||
userTraits.put("defaultTraitsUpdatedAt", Instant.now().getEpochSecond());
|
||||
userTraits.put("type", "user");
|
||||
return userTraits;
|
||||
});
|
||||
return configService.getInstanceId().map(instanceId -> {
|
||||
Map<String, Object> userTraits = new HashMap<>();
|
||||
String emailTrait;
|
||||
if (!commonConfig.isCloudHosting()) {
|
||||
emailTrait = userIdentifierService.hash(user.getEmail());
|
||||
} else {
|
||||
emailTrait = user.getEmail();
|
||||
}
|
||||
userTraits.put("email", emailTrait);
|
||||
userTraits.put("instanceId", instanceId);
|
||||
userTraits.put("tenantId", user.getTenantId());
|
||||
userTraits.put("isTelemetryOn", !commonConfig.isTelemetryDisabled());
|
||||
userTraits.put("createdAt", user.getCreatedAt());
|
||||
userTraits.put("defaultTraitsUpdatedAt", Instant.now().getEpochSecond());
|
||||
userTraits.put("type", "user");
|
||||
return userTraits;
|
||||
});
|
||||
}
|
||||
|
||||
@CacheEvict(cacheName = "featureFlag", key = "{#userIdentifier}")
|
||||
|
|
@ -90,13 +92,8 @@ public class CacheableFeatureFlagHelperCEImpl implements CacheableFeatureFlagHel
|
|||
Mono<String> defaultTenantIdMono = tenantService.getDefaultTenantId();
|
||||
return Mono.zip(instanceIdMono, defaultTenantIdMono, getUserDefaultTraits(user))
|
||||
.flatMap(objects -> {
|
||||
return this.getRemoteFeatureFlagsByIdentity(
|
||||
new FeatureFlagIdentityTraits(
|
||||
objects.getT1(),
|
||||
objects.getT2(),
|
||||
Set.of(userIdentifier),
|
||||
objects.getT3())
|
||||
);
|
||||
return this.getRemoteFeatureFlagsByIdentity(new FeatureFlagIdentityTraits(
|
||||
objects.getT1(), objects.getT2(), Set.of(userIdentifier), objects.getT3()));
|
||||
})
|
||||
.map(newValue -> newValue.get(userIdentifier));
|
||||
}
|
||||
|
|
@ -108,16 +105,16 @@ public class CacheableFeatureFlagHelperCEImpl implements CacheableFeatureFlagHel
|
|||
* @param featureFlagIdentityTraits
|
||||
* @return
|
||||
*/
|
||||
private Mono<Map<String, Map<String, Boolean>>> getRemoteFeatureFlagsByIdentity(FeatureFlagIdentityTraits featureFlagIdentityTraits) {
|
||||
private Mono<Map<String, Map<String, Boolean>>> getRemoteFeatureFlagsByIdentity(
|
||||
FeatureFlagIdentityTraits featureFlagIdentityTraits) {
|
||||
return WebClientUtils.create(cloudServicesConfig.getBaseUrl())
|
||||
.post()
|
||||
.uri("/api/v1/feature-flags")
|
||||
.body(BodyInserters.fromValue(featureFlagIdentityTraits))
|
||||
.exchangeToMono(clientResponse -> {
|
||||
if (clientResponse.statusCode().is2xxSuccessful()) {
|
||||
return clientResponse.bodyToMono(new ParameterizedTypeReference<ResponseDTO<Map<String,
|
||||
Map<String, Boolean>>>>() {
|
||||
});
|
||||
return clientResponse.bodyToMono(
|
||||
new ParameterizedTypeReference<ResponseDTO<Map<String, Map<String, Boolean>>>>() {});
|
||||
} else {
|
||||
return clientResponse.createError();
|
||||
}
|
||||
|
|
@ -126,8 +123,7 @@ public class CacheableFeatureFlagHelperCEImpl implements CacheableFeatureFlagHel
|
|||
.onErrorMap(
|
||||
// Only map errors if we haven't already wrapped them into an AppsmithException
|
||||
e -> !(e instanceof AppsmithException),
|
||||
e -> new AppsmithException(AppsmithError.CLOUD_SERVICES_ERROR, e.getMessage())
|
||||
)
|
||||
e -> new AppsmithException(AppsmithError.CLOUD_SERVICES_ERROR, e.getMessage()))
|
||||
.onErrorResume(error -> {
|
||||
// We're gobbling up errors here so that all feature flags are turned off by default
|
||||
// This will be problematic if we do not maintain code to reflect validity of flags
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import com.appsmith.server.domains.User;
|
|||
import com.appsmith.server.featureflags.FeatureFlagEnum;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface FeatureFlagServiceCE {
|
||||
|
|
@ -36,5 +35,4 @@ public interface FeatureFlagServiceCE {
|
|||
* @return Mono<Map < String, Boolean>>
|
||||
*/
|
||||
Mono<Map<String, Boolean>> getAllFeatureFlagsForUser();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import java.time.Instant;
|
|||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class FeatureFlagServiceCEImpl implements FeatureFlagServiceCE {
|
||||
|
||||
|
|
@ -42,13 +41,14 @@ public class FeatureFlagServiceCEImpl implements FeatureFlagServiceCE {
|
|||
private final CacheableFeatureFlagHelper cacheableFeatureFlagHelper;
|
||||
|
||||
@Autowired
|
||||
public FeatureFlagServiceCEImpl(SessionUserService sessionUserService,
|
||||
FF4j ff4j,
|
||||
TenantService tenantService,
|
||||
ConfigService configService,
|
||||
CloudServicesConfig cloudServicesConfig,
|
||||
UserIdentifierService userIdentifierService,
|
||||
CacheableFeatureFlagHelper cacheableFeatureFlagHelper) {
|
||||
public FeatureFlagServiceCEImpl(
|
||||
SessionUserService sessionUserService,
|
||||
FF4j ff4j,
|
||||
TenantService tenantService,
|
||||
ConfigService configService,
|
||||
CloudServicesConfig cloudServicesConfig,
|
||||
UserIdentifierService userIdentifierService,
|
||||
CacheableFeatureFlagHelper cacheableFeatureFlagHelper) {
|
||||
this.sessionUserService = sessionUserService;
|
||||
this.ff4j = ff4j;
|
||||
this.tenantService = tenantService;
|
||||
|
|
@ -58,7 +58,6 @@ public class FeatureFlagServiceCEImpl implements FeatureFlagServiceCE {
|
|||
this.cacheableFeatureFlagHelper = cacheableFeatureFlagHelper;
|
||||
}
|
||||
|
||||
|
||||
private Mono<Boolean> checkAll(String featureName, User user) {
|
||||
Boolean check = check(featureName, user);
|
||||
|
||||
|
|
@ -81,8 +80,7 @@ public class FeatureFlagServiceCEImpl implements FeatureFlagServiceCE {
|
|||
|
||||
@Override
|
||||
public Mono<Boolean> check(FeatureFlagEnum featureEnum) {
|
||||
return sessionUserService.getCurrentUser()
|
||||
.flatMap(user -> check(featureEnum, user));
|
||||
return sessionUserService.getCurrentUser().flatMap(user -> check(featureEnum, user));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -93,15 +91,13 @@ public class FeatureFlagServiceCEImpl implements FeatureFlagServiceCE {
|
|||
@Override
|
||||
public Mono<Map<String, Boolean>> getAllFeatureFlagsForUser() {
|
||||
Mono<User> currentUser = sessionUserService.getCurrentUser().cache();
|
||||
Flux<Tuple2<String, User>> featureUserTuple = Flux.fromIterable(ff4j.getFeatures().keySet())
|
||||
Flux<Tuple2<String, User>> featureUserTuple = Flux.fromIterable(
|
||||
ff4j.getFeatures().keySet())
|
||||
.flatMap(featureName -> Mono.just(featureName).zipWith(currentUser));
|
||||
|
||||
Mono<Map<String, Boolean>> localFlagsForUser = featureUserTuple
|
||||
.filter(objects -> !objects.getT2().isAnonymous())
|
||||
.collectMap(
|
||||
Tuple2::getT1,
|
||||
tuple -> check(tuple.getT1(), tuple.getT2())
|
||||
);
|
||||
.collectMap(Tuple2::getT1, tuple -> check(tuple.getT1(), tuple.getT2()));
|
||||
|
||||
return Mono.zip(localFlagsForUser, this.getAllRemoteFeatureFlagsForUser())
|
||||
.map(tuple -> {
|
||||
|
|
@ -117,22 +113,23 @@ public class FeatureFlagServiceCEImpl implements FeatureFlagServiceCE {
|
|||
*/
|
||||
private Mono<Map<String, Boolean>> getAllRemoteFeatureFlagsForUser() {
|
||||
Mono<User> userMono = sessionUserService.getCurrentUser().cache();
|
||||
return userMono
|
||||
.flatMap(user -> {
|
||||
String userIdentifier = userIdentifierService.getUserIdentifier(user);
|
||||
// Checks for flags present in cache and if the cache is not expired
|
||||
return cacheableFeatureFlagHelper
|
||||
.fetchUserCachedFlags(userIdentifier, user)
|
||||
.flatMap(cachedFlags -> {
|
||||
if (cachedFlags.getRefreshedAt().until(Instant.now(), ChronoUnit.MINUTES) < this.featureFlagCacheTimeMin) {
|
||||
return Mono.just(cachedFlags.getFlags());
|
||||
} else {
|
||||
// empty the cache for the userIdentifier as expired
|
||||
return cacheableFeatureFlagHelper.evictUserCachedFlags(userIdentifier)
|
||||
.then(cacheableFeatureFlagHelper.fetchUserCachedFlags(userIdentifier, user))
|
||||
.flatMap(cachedFlagsUpdated -> Mono.just(cachedFlagsUpdated.getFlags()));
|
||||
}
|
||||
});
|
||||
});
|
||||
return userMono.flatMap(user -> {
|
||||
String userIdentifier = userIdentifierService.getUserIdentifier(user);
|
||||
// Checks for flags present in cache and if the cache is not expired
|
||||
return cacheableFeatureFlagHelper
|
||||
.fetchUserCachedFlags(userIdentifier, user)
|
||||
.flatMap(cachedFlags -> {
|
||||
if (cachedFlags.getRefreshedAt().until(Instant.now(), ChronoUnit.MINUTES)
|
||||
< this.featureFlagCacheTimeMin) {
|
||||
return Mono.just(cachedFlags.getFlags());
|
||||
} else {
|
||||
// empty the cache for the userIdentifier as expired
|
||||
return cacheableFeatureFlagHelper
|
||||
.evictUserCachedFlags(userIdentifier)
|
||||
.then(cacheableFeatureFlagHelper.fetchUserCachedFlags(userIdentifier, user))
|
||||
.flatMap(cachedFlagsUpdated -> Mono.just(cachedFlagsUpdated.getFlags()));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -516,13 +516,16 @@ public class ThemeServiceCEImpl extends BaseService<ThemeRepositoryCE, Theme, St
|
|||
destinationApp.setPublishedModeThemeId(publishedModeThemeId);
|
||||
// this will update the theme id in DB
|
||||
// also returning the updated application object so that theme id are available to the next pipeline
|
||||
return applicationService.setAppTheme(
|
||||
destinationApp.getId(), editModeThemeId, publishedModeThemeId, applicationPermission.getEditPermission())
|
||||
.thenReturn(destinationApp);
|
||||
return applicationService
|
||||
.setAppTheme(
|
||||
destinationApp.getId(),
|
||||
editModeThemeId,
|
||||
publishedModeThemeId,
|
||||
applicationPermission.getEditPermission())
|
||||
.thenReturn(destinationApp);
|
||||
})
|
||||
.switchIfEmpty(
|
||||
Mono.error(new AppsmithException(AppsmithError.GENERIC_BAD_REQUEST, "Failed to import theme"))
|
||||
);
|
||||
Mono.error(new AppsmithException(AppsmithError.GENERIC_BAD_REQUEST, "Failed to import theme")));
|
||||
}
|
||||
|
||||
private Mono<Theme> updateExistingAppThemeFromJSON(
|
||||
|
|
@ -531,7 +534,8 @@ public class ThemeServiceCEImpl extends BaseService<ThemeRepositoryCE, Theme, St
|
|||
return getOrSaveTheme(themeFromJson, destinationApp);
|
||||
}
|
||||
|
||||
return repository.findById(existingThemeId)
|
||||
return repository
|
||||
.findById(existingThemeId)
|
||||
.defaultIfEmpty(new Theme()) // fallback when application theme is deleted
|
||||
.flatMap(existingTheme -> {
|
||||
if (!StringUtils.hasLength(existingTheme.getId()) || existingTheme.isSystemTheme()) {
|
||||
|
|
|
|||
|
|
@ -1419,7 +1419,14 @@ public class ImportExportApplicationServiceCEImpl implements ImportExportApplica
|
|||
importedApplication.setPublishedPages(applicationPageMap.get(VIEW));
|
||||
return applicationPageMap;
|
||||
})
|
||||
.flatMap(unused -> newActionService.importActions(importedNewActionList, importedApplication, branchName, pageNameMap, pluginMap, datasourceMap, permissionProvider))
|
||||
.flatMap(unused -> newActionService.importActions(
|
||||
importedNewActionList,
|
||||
importedApplication,
|
||||
branchName,
|
||||
pageNameMap,
|
||||
pluginMap,
|
||||
datasourceMap,
|
||||
permissionProvider))
|
||||
.flatMap(importActionResultDTO -> {
|
||||
log.info(
|
||||
"Actions imported. applicationId {}, result: {}",
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
@Slf4j
|
||||
|
|
@ -92,7 +91,7 @@ public class FeatureFlagServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void getFeatureFlags_withUserIdentifier_redisKeyExists(){
|
||||
public void getFeatureFlags_withUserIdentifier_redisKeyExists() {
|
||||
String userIdentifier = "testIdentifier";
|
||||
User dummyUser = new User();
|
||||
Mono<CachedFlags> cachedFlagsMono = cacheableFeatureFlagHelper.fetchUserCachedFlags(userIdentifier, dummyUser);
|
||||
|
|
@ -127,5 +126,4 @@ public class FeatureFlagServiceTest {
|
|||
return ff4j;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -852,7 +852,8 @@ public class ThemeServiceTest {
|
|||
@WithUserDetails("api_user")
|
||||
@Test
|
||||
public void importThemesToApplication_ApplicationThemeNotFound_DefaultThemeImported() {
|
||||
Theme defaultTheme = themeRepository.getSystemThemeByName(Theme.DEFAULT_THEME_NAME).block();
|
||||
Theme defaultTheme =
|
||||
themeRepository.getSystemThemeByName(Theme.DEFAULT_THEME_NAME).block();
|
||||
|
||||
// create the theme information present in the application JSON
|
||||
Theme themeInJson = new Theme();
|
||||
|
|
@ -874,18 +875,18 @@ public class ThemeServiceTest {
|
|||
.flatMap(applicationRepository::save)
|
||||
.flatMap(savedApplication -> {
|
||||
assert savedApplication.getId() != null;
|
||||
return themeService.importThemesToApplication(savedApplication, applicationJson)
|
||||
return themeService
|
||||
.importThemesToApplication(savedApplication, applicationJson)
|
||||
.thenReturn(savedApplication.getId());
|
||||
})
|
||||
.flatMap(applicationId ->
|
||||
applicationRepository.findById(applicationId, MANAGE_APPLICATIONS)
|
||||
);
|
||||
.flatMap(applicationId -> applicationRepository.findById(applicationId, MANAGE_APPLICATIONS));
|
||||
|
||||
StepVerifier.create(applicationMono)
|
||||
.assertNext(app -> {
|
||||
// both edit mode and published mode should have default theme set
|
||||
assertThat(app.getEditModeThemeId()).isEqualTo(app.getPublishedModeThemeId());
|
||||
assertThat(app.getEditModeThemeId()).isEqualTo(defaultTheme.getId());
|
||||
}).verifyComplete();
|
||||
})
|
||||
.verifyComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@
|
|||
<goals>
|
||||
<goal>apply</goal>
|
||||
</goals>
|
||||
<!-- This gets triggered automatically when we run the build script -->
|
||||
<phase>compile</phase>
|
||||
</execution>
|
||||
</executions>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user