-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add methods to gather plugin versions from servers * Gathering and storage for plugin version history * Test plugin gathering * Test plugin metadata storage * /v1/pluginHistory endpoint * Plugin history tab * Plugin history to performance tab * Possibly fix ConfigChange.MovedValue being applied all the time * Updated locale files * Export pluginHistory for server page * Add plugin history to network page * Access control and improvements * Remove pluginHistory from export since it now requires auth * Fix access visibility tests * Fix VelocitySensor during test Affects issues: - Close #2360
- Loading branch information
Showing
66 changed files
with
1,464 additions
and
51 deletions.
There are no files selected for viewing
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
77 changes: 77 additions & 0 deletions
77
Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/PluginHistoryMetadata.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,77 @@ | ||
/* | ||
* This file is part of Player Analytics (Plan). | ||
* | ||
* Plan is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License v3 as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Plan is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Plan. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.djrapitops.plan.delivery.domain; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Represents plugin version history. | ||
* <p> | ||
* If version is null the plugin was uninstalled at that time. | ||
* | ||
* @author AuroraLS3 | ||
*/ | ||
public class PluginHistoryMetadata { | ||
|
||
private final String name; | ||
@Nullable | ||
private final String version; | ||
private final long modified; | ||
|
||
public PluginHistoryMetadata(String name, @Nullable String version, long modified) { | ||
this.name = name; | ||
this.version = version; | ||
this.modified = modified; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Nullable | ||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public long getModified() { | ||
return modified; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
PluginHistoryMetadata that = (PluginHistoryMetadata) o; | ||
return getModified() == that.getModified() && Objects.equals(getName(), that.getName()) && Objects.equals(getVersion(), that.getVersion()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getName(), getVersion(), getModified()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PluginHistoryMetadata{" + | ||
"name='" + name + '\'' + | ||
", version='" + version + '\'' + | ||
", modified=" + modified + | ||
'}'; | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
...mmon/src/main/java/com/djrapitops/plan/delivery/domain/datatransfer/PluginHistoryDto.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,60 @@ | ||
/* | ||
* This file is part of Player Analytics (Plan). | ||
* | ||
* Plan is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License v3 as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Plan is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Plan. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.djrapitops.plan.delivery.domain.datatransfer; | ||
|
||
import com.djrapitops.plan.delivery.domain.PluginHistoryMetadata; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* History of plugin versions, sorted most recent first. | ||
* | ||
* @author AuroraLS3 | ||
*/ | ||
public class PluginHistoryDto { | ||
|
||
private final List<PluginHistoryMetadata> history; | ||
|
||
public PluginHistoryDto(List<PluginHistoryMetadata> history) { | ||
this.history = history; | ||
} | ||
|
||
public List<PluginHistoryMetadata> getHistory() { | ||
return history; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
PluginHistoryDto that = (PluginHistoryDto) o; | ||
return Objects.equals(getHistory(), that.getHistory()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(getHistory()); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PluginHistoryDto{" + | ||
"history=" + history + | ||
'}'; | ||
} | ||
} |
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
100 changes: 100 additions & 0 deletions
100
...m/djrapitops/plan/delivery/webserver/resolver/json/plugins/PluginHistoryJSONResolver.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,100 @@ | ||
/* | ||
* This file is part of Player Analytics (Plan). | ||
* | ||
* Plan is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License v3 as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Plan is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with Plan. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package com.djrapitops.plan.delivery.webserver.resolver.json.plugins; | ||
|
||
import com.djrapitops.plan.delivery.domain.PluginHistoryMetadata; | ||
import com.djrapitops.plan.delivery.domain.auth.WebPermission; | ||
import com.djrapitops.plan.delivery.domain.datatransfer.PluginHistoryDto; | ||
import com.djrapitops.plan.delivery.web.resolver.MimeType; | ||
import com.djrapitops.plan.delivery.web.resolver.Resolver; | ||
import com.djrapitops.plan.delivery.web.resolver.Response; | ||
import com.djrapitops.plan.delivery.web.resolver.request.Request; | ||
import com.djrapitops.plan.identification.Identifiers; | ||
import com.djrapitops.plan.identification.ServerUUID; | ||
import com.djrapitops.plan.storage.database.DBSystem; | ||
import com.djrapitops.plan.storage.database.queries.objects.PluginMetadataQueries; | ||
import com.djrapitops.plan.utilities.dev.Untrusted; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.parameters.RequestBody; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Endpoint for getting plugin version history. | ||
* | ||
* @author AuroraLS3 | ||
*/ | ||
@Singleton | ||
@Path("/v1/pluginHistory") | ||
public class PluginHistoryJSONResolver implements Resolver { | ||
|
||
private final DBSystem dbSystem; | ||
private final Identifiers identifiers; | ||
|
||
@Inject | ||
public PluginHistoryJSONResolver(DBSystem dbSystem, Identifiers identifiers) { | ||
this.dbSystem = dbSystem; | ||
this.identifiers = identifiers; | ||
} | ||
|
||
@Override | ||
public boolean canAccess(Request request) { | ||
return request.getUser() | ||
.map(user -> user.hasPermission(WebPermission.PAGE_NETWORK_PLUGIN_HISTORY) | ||
|| user.hasPermission(WebPermission.PAGE_SERVER_PLUGIN_HISTORY)) | ||
.orElse(false); | ||
} | ||
|
||
@Override | ||
@Operation( | ||
description = "Get plugin history for a server since installation of Plan.", | ||
responses = { | ||
@ApiResponse(responseCode = "200", content = @Content(mediaType = MimeType.JSON, | ||
schema = @Schema(implementation = PluginHistoryDto.class))), | ||
}, | ||
parameters = @Parameter(in = ParameterIn.QUERY, name = "server", description = "Server identifier to get data for (optional)", examples = { | ||
@ExampleObject("Server 1"), | ||
@ExampleObject("1"), | ||
@ExampleObject("1fb39d2a-eb82-4868-b245-1fad17d823b3"), | ||
}), | ||
requestBody = @RequestBody(content = @Content(examples = @ExampleObject())) | ||
) | ||
@GET | ||
public Optional<Response> resolve(@Untrusted Request request) { | ||
return Optional.of(getResponse(request)); | ||
} | ||
|
||
private Response getResponse(@Untrusted Request request) { | ||
ServerUUID serverUUID = identifiers.getServerUUID(request); // Can throw BadRequestException | ||
List<PluginHistoryMetadata> history = dbSystem.getDatabase().query(PluginMetadataQueries.getPluginHistory(serverUUID)); | ||
return Response.builder() | ||
.setMimeType(MimeType.JSON) | ||
.setJSONContent(new PluginHistoryDto(history)) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.