Skip to content

Add Migration To Fix Existing Application Public View Bug #722

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Set;
import java.util.function.Supplier;

import lombok.Setter;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.lowcoder.domain.query.model.ApplicationQuery;
Expand All @@ -38,10 +39,13 @@ public class Application extends HasIdAndAuditing {

private final Map<String, Object> publishedApplicationDSL;

private final Boolean publicToAll;
private final Boolean publicToMarketplace;
@Setter
private Boolean publicToAll;
@Setter
private Boolean publicToMarketplace;

private final Boolean agencyProfile;
@Setter
private Boolean agencyProfile;

private Map<String, Object> editingApplicationDSL;

Expand Down Expand Up @@ -161,4 +165,5 @@ public Map<String, Object> getEditingApplicationDSL() {
public Object getLiveContainerSize() {
return liveContainerSize.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,8 @@ public Mono<Set<String>> getPublicApplicationIds(Collection<String> applicationI


}

public Flux<Application> findAll() {
return repository.findAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.lowcoder.infra.config.model.ServerConfig;
import org.lowcoder.infra.eventlog.EventLog;
import org.lowcoder.infra.serverlog.ServerLog;
import org.lowcoder.runner.migrations.job.AddPtmFieldsJob;
import org.lowcoder.runner.migrations.job.CompleteAuthType;
import org.lowcoder.runner.migrations.job.MigrateAuthConfigJob;
import org.springframework.data.domain.Sort;
Expand Down Expand Up @@ -182,6 +183,11 @@ public void addOrgIdIndexOnServerLog(MongockTemplate mongoTemplate) {
);
}

@ChangeSet(order = "020", id = "add-ptm-fields-to-applications", author = "")
public void addPtmFieldsToApplicatgions(AddPtmFieldsJob addPtmFieldsJob) {
addPtmFieldsJob.migrateApplicationsToInitPtmFields();
}

public static Index makeIndex(String... fields) {
if (fields.length == 1) {
return new Index(fields[0], Sort.Direction.ASC).named(fields[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.lowcoder.runner.migrations.job;

public interface AddPtmFieldsJob {

void migrateApplicationsToInitPtmFields();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.lowcoder.runner.migrations.job;

import org.lowcoder.domain.application.service.ApplicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AddPtmFieldsJobImpl implements AddPtmFieldsJob {

@Autowired
private ApplicationService applicationService;

@Override
public void migrateApplicationsToInitPtmFields() {
applicationService.findAll()
.doOnNext(application -> {
if(!application.isPublicToAll()) {
application.setPublicToAll(Boolean.FALSE);
}
if(!application.isPublicToMarketplace()) {
application.setPublicToMarketplace(Boolean.FALSE);
}
if(!application.agencyProfile()) {
application.setAgencyProfile(Boolean.FALSE);
}
}).flatMap(application -> applicationService.updateById(application.getId(), application))
.blockLast();
}
}