Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reset users' startpages if referenced stream/dashboard is deleted. (#…
…2702) * Add Listener to reset users' startpages if stream/dashboard is deleted. This change adds a listener and the necessary events, which are posted when a stream or dashboard is deleted. The listener will then reset any user's startpage if it references the deleted entity. * Adding licenses. * Refresh current user before redirecting to start page. * Reset currentUser on logout. * Check presence of currentUser first. * Switching back to Reflux.connect because initial state is correct now. * Checking for presence of currentUser too, because it can be undefined.
- Loading branch information
1 parent
d9de776
commit f167fb0
Showing
13 changed files
with
188 additions
and
24 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
36 changes: 36 additions & 0 deletions
36
graylog2-server/src/main/java/org/graylog2/dashboards/events/DashboardDeletedEvent.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
/** | |||
* This file is part of Graylog. | |||
* | |||
* Graylog is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Graylog 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 General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.graylog2.dashboards.events; | |||
|
|||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | |||
import com.fasterxml.jackson.annotation.JsonCreator; | |||
import com.fasterxml.jackson.annotation.JsonProperty; | |||
import com.google.auto.value.AutoValue; | |||
|
|||
@AutoValue | |||
@JsonAutoDetect | |||
public abstract class DashboardDeletedEvent { | |||
private static final String FIELD_DASHBOARD_ID = "dashboard_id"; | |||
|
|||
@JsonProperty(FIELD_DASHBOARD_ID) | |||
public abstract String dashboardId(); | |||
|
|||
@JsonCreator | |||
public static DashboardDeletedEvent create(@JsonProperty(FIELD_DASHBOARD_ID) String dashboardId) { | |||
return new AutoValue_DashboardDeletedEvent(dashboardId); | |||
} | |||
} |
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
36 changes: 36 additions & 0 deletions
36
graylog2-server/src/main/java/org/graylog2/streams/events/StreamDeletedEvent.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
/** | |||
* This file is part of Graylog. | |||
* | |||
* Graylog is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Graylog 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 General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.graylog2.streams.events; | |||
|
|||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | |||
import com.fasterxml.jackson.annotation.JsonCreator; | |||
import com.fasterxml.jackson.annotation.JsonProperty; | |||
import com.google.auto.value.AutoValue; | |||
|
|||
@AutoValue | |||
@JsonAutoDetect | |||
public abstract class StreamDeletedEvent { | |||
private static final String FIELD_STREAM_ID = "stream_id"; | |||
|
|||
@JsonProperty(FIELD_STREAM_ID) | |||
public abstract String streamId(); | |||
|
|||
@JsonCreator | |||
public static StreamDeletedEvent create(@JsonProperty(FIELD_STREAM_ID) String streamId) { | |||
return new AutoValue_StreamDeletedEvent(streamId); | |||
} | |||
} |
70 changes: 70 additions & 0 deletions
70
graylog2-server/src/main/java/org/graylog2/users/StartPageCleanupListener.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,70 @@ | |||
/** | |||
* This file is part of Graylog. | |||
* | |||
* Graylog is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* Graylog 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 General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with Graylog. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.graylog2.users; | |||
|
|||
import com.google.common.eventbus.EventBus; | |||
import com.google.common.eventbus.Subscribe; | |||
import org.graylog2.dashboards.events.DashboardDeletedEvent; | |||
import org.graylog2.plugin.database.ValidationException; | |||
import org.graylog2.rest.models.users.requests.Startpage; | |||
import org.graylog2.shared.users.UserService; | |||
import org.graylog2.streams.events.StreamDeletedEvent; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
|
|||
import javax.inject.Inject; | |||
|
|||
public class StartPageCleanupListener { | |||
private static final Logger LOG = LoggerFactory.getLogger(StartPageCleanupListener.class); | |||
|
|||
private final UserService userService; | |||
|
|||
@Inject | |||
public StartPageCleanupListener(EventBus serverEventBus, | |||
UserService userService) { | |||
this.userService = userService; | |||
serverEventBus.register(this); | |||
} | |||
|
|||
@Subscribe | |||
@SuppressWarnings("unused") | |||
public void removeStartpageReferencesIfStreamDeleted(StreamDeletedEvent streamDeletedEvent) { | |||
final Startpage deletedStartpage = Startpage.create("stream", streamDeletedEvent.streamId()); | |||
resetReferencesToStartpage(deletedStartpage); | |||
} | |||
|
|||
@Subscribe | |||
@SuppressWarnings("unused") | |||
public void removeStartpageReferencesIfDashboardDeleted(DashboardDeletedEvent dashboardDeletedEvent) { | |||
final Startpage deletedStartpage = Startpage.create("dashboard", dashboardDeletedEvent.dashboardId()); | |||
resetReferencesToStartpage(deletedStartpage); | |||
} | |||
|
|||
private void resetReferencesToStartpage(Startpage deletedStartpage) { | |||
this.userService.loadAll() | |||
.stream() | |||
.filter(user -> user.getStartpage() != null && user.getStartpage().equals(deletedStartpage)) | |||
.forEach(user -> { | |||
user.setStartpage(null); | |||
try { | |||
this.userService.save(user); | |||
} catch (ValidationException e) { | |||
LOG.error("Unable to reset start page for user which references deleted start page: ", e); | |||
} | |||
}); | |||
} | |||
} |
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
Oops, something went wrong.