From 520bbe9a612d75b5b012e040ce4c78bd216a48ee Mon Sep 17 00:00:00 2001 From: kahverengi Date: Sun, 3 Mar 2024 20:16:37 +0300 Subject: [PATCH] feat: add plugin system and improve infrastructure for it --- .gitignore | 9 +- Pano/build.gradle.kts | 151 ++++++++++ {src => Pano/src}/main/java/.gitkeep | 0 .../src}/main/java/util/StringUtil.java | 0 .../com/panomc/platform/AppConstants.kt | 0 .../main/kotlin/com/panomc/platform/Main.kt | 49 ++- .../com/panomc/platform/PanoPluginLoader.kt | 17 ++ .../com/panomc/platform/PluginEventManager.kt | 45 +++ .../com/panomc/platform/PluginFactory.kt | 56 ++++ .../com/panomc/platform/PluginManager.kt | 34 +++ .../com/panomc/platform/ReleaseStage.kt | 0 .../com/panomc/platform/SpringConfig.kt | 23 +- .../com/panomc/platform/annotation/Boot.kt | 0 .../com/panomc/platform/annotation/Dao.kt | 0 .../panomc/platform/annotation/Endpoint.kt | 0 .../com/panomc/platform/annotation/Event.kt | 0 .../com/panomc/platform/annotation/Ignore.kt | 0 .../panomc/platform/annotation/Migration.kt | 0 .../com/panomc/platform/api/EventListener.kt | 4 + .../panomc/platform/api/PanoEventListener.kt | 3 + .../com/panomc/platform/api/PanoPlugin.kt | 98 ++++++ .../platform/api/PluginEventListener.kt | 4 + .../platform/api/annotation/EventListener.kt | 10 + .../com/panomc/platform/auth/AuthProvider.kt | 0 .../panomc/platform/auth/PanelPermission.kt | 0 .../panomc/platform/config/ConfigManager.kt | 0 .../panomc/platform/config/ConfigMigration.kt | 0 .../panomc/platform/config/migration/.gitkeep | 0 .../kotlin/com/panomc/platform/db/DBEntity.kt | 0 .../main/kotlin/com/panomc/platform/db/Dao.kt | 0 .../kotlin/com/panomc/platform/db/DaoImpl.kt | 0 .../com/panomc/platform/db/DatabaseManager.kt | 0 .../panomc/platform/db/DatabaseMigration.kt | 0 .../panomc/platform/db/dao/NotificationDao.kt | 0 .../panomc/platform/db/dao/PanelConfigDao.kt | 0 .../platform/db/dao/PanelNotificationDao.kt | 0 .../panomc/platform/db/dao/PermissionDao.kt | 0 .../platform/db/dao/PermissionGroupDao.kt | 0 .../db/dao/PermissionGroupPermsDao.kt | 0 .../panomc/platform/db/dao/PostCategoryDao.kt | 0 .../com/panomc/platform/db/dao/PostDao.kt | 0 .../platform/db/dao/SchemeVersionDao.kt | 0 .../com/panomc/platform/db/dao/ServerDao.kt | 0 .../panomc/platform/db/dao/ServerPlayerDao.kt | 0 .../platform/db/dao/SystemPropertyDao.kt | 0 .../platform/db/dao/TicketCategoryDao.kt | 0 .../com/panomc/platform/db/dao/TicketDao.kt | 0 .../platform/db/dao/TicketMessageDao.kt | 0 .../com/panomc/platform/db/dao/TokenDao.kt | 0 .../com/panomc/platform/db/dao/UserDao.kt | 0 .../panomc/platform/db/dao/WebsiteViewDao.kt | 0 .../db/implementation/NotificationDaoImpl.kt | 0 .../db/implementation/PanelConfigDaoImpl.kt | 0 .../PanelNotificationDaoImpl.kt | 0 .../db/implementation/PermissionDaoImpl.kt | 0 .../implementation/PermissionGroupDaoImpl.kt | 0 .../PermissionGroupPermsDaoImpl.kt | 0 .../db/implementation/PostCategoryDaoImpl.kt | 0 .../platform/db/implementation/PostDaoImpl.kt | 0 .../db/implementation/SchemeVersionDaoImpl.kt | 0 .../db/implementation/ServerDaoImpl.kt | 0 .../db/implementation/ServerPlayerDaoImpl.kt | 0 .../implementation/SystemPropertyDaoImpl.kt | 0 .../implementation/TicketCategoryDaoImpl.kt | 0 .../db/implementation/TicketDaoImpl.kt | 0 .../db/implementation/TicketMessageDaoImpl.kt | 0 .../db/implementation/TokenDaoImpl.kt | 0 .../platform/db/implementation/UserDaoImpl.kt | 0 .../db/implementation/WebsiteViewDaoImpl.kt | 0 .../com/panomc/platform/db/migration/.gitkeep | 0 .../panomc/platform/db/model/Notification.kt | 0 .../panomc/platform/db/model/PanelConfig.kt | 0 .../platform/db/model/PanelNotification.kt | 0 .../panomc/platform/db/model/Permission.kt | 0 .../platform/db/model/PermissionGroup.kt | 0 .../platform/db/model/PermissionGroupPerms.kt | 0 .../com/panomc/platform/db/model/Post.kt | 0 .../panomc/platform/db/model/PostCategory.kt | 0 .../panomc/platform/db/model/SchemeVersion.kt | 0 .../com/panomc/platform/db/model/Server.kt | 0 .../panomc/platform/db/model/ServerPlayer.kt | 0 .../platform/db/model/SystemProperty.kt | 0 .../com/panomc/platform/db/model/Ticket.kt | 0 .../platform/db/model/TicketCategory.kt | 0 .../panomc/platform/db/model/TicketMessage.kt | 0 .../com/panomc/platform/db/model/Token.kt | 0 .../com/panomc/platform/db/model/User.kt | 0 .../panomc/platform/db/model/WebsiteView.kt | 0 .../panomc/platform/error/AlreadyBanned.kt | 0 .../com/panomc/platform/error/BadRequest.kt | 0 .../panomc/platform/error/CantBanYourself.kt | 0 .../error/CantChangeEmailWait15Minutes.kt | 0 .../error/CantDeleteAdminPermission.kt | 0 .../platform/error/CantDeleteYourself.kt | 0 .../error/CantResetPasswordWait15Minutes.kt | 0 .../error/CantUpdateAdminPermission.kt | 0 .../error/CantUpdatePermGroupYourself.kt | 0 .../platform/error/CategoryNotExists.kt | 0 .../error/CurrentPasswordNotCorrect.kt | 0 .../platform/error/EmailAlreadyVerified.kt | 0 .../platform/error/FaviconExceedsSize.kt | 0 .../platform/error/FaviconWrongContentType.kt | 0 .../platform/error/InstallationRequired.kt | 0 .../platform/error/InternalServerError.kt | 0 .../com/panomc/platform/error/InvalidData.kt | 0 .../com/panomc/platform/error/InvalidEmail.kt | 0 .../panomc/platform/error/InvalidIpAddress.kt | 0 .../com/panomc/platform/error/InvalidLink.kt | 0 .../platform/error/InvalidPlatformCode.kt | 0 .../com/panomc/platform/error/InvalidToken.kt | 0 .../com/panomc/platform/error/LastAdmin.kt | 0 .../platform/error/LoginEmailNotVerified.kt | 0 .../panomc/platform/error/LoginIsInvalid.kt | 0 .../platform/error/LoginUserIsBanned.kt | 0 .../platform/error/MessageCantBeEmpty.kt | 0 .../panomc/platform/error/NeedPermission.kt | 0 .../panomc/platform/error/NewEmailExists.kt | 0 .../panomc/platform/error/NewPasswordEmpty.kt | 0 .../error/NewPasswordRepeatDoesntMatch.kt | 0 .../platform/error/NewPasswordTooLong.kt | 0 .../platform/error/NewPasswordTooShort.kt | 0 .../com/panomc/platform/error/NoPermission.kt | 0 .../NoPermissionToUpdateAdminPermGroup.kt | 0 .../error/NoPermissionToUpdateAdminUser.kt | 0 .../com/panomc/platform/error/NotBanned.kt | 0 .../com/panomc/platform/error/NotExists.kt | 0 .../com/panomc/platform/error/NotLoggedIn.kt | 0 .../com/panomc/platform/error/PageNotFound.kt | 0 .../panomc/platform/error/PasswordEmpty.kt | 0 .../panomc/platform/error/PasswordTooLong.kt | 0 .../panomc/platform/error/PasswordTooShort.kt | 0 .../platform/error/PermGroupNotExists.kt | 0 .../error/PlatformAlreadyInstalled.kt | 0 .../com/panomc/platform/error/PostNotFound.kt | 0 .../error/PostThumbnailExceedsSize.kt | 0 .../error/PostThumbnailWrongContentType.kt | 0 .../platform/error/RegisterCantVerifyRobot.kt | 0 .../platform/error/RegisterEmailEmpty.kt | 0 .../error/RegisterEmailNotAvailable.kt | 0 .../platform/error/RegisterInvalidEmail.kt | 0 .../platform/error/RegisterInvalidUsername.kt | 0 .../error/RegisterNotAcceptedAgreement.kt | 0 ...egisterPasswordAndPasswordRepeatNotSame.kt | 0 .../platform/error/RegisterUsernameEmpty.kt | 0 .../error/RegisterUsernameNotAvailable.kt | 0 .../platform/error/RegisterUsernameTooLong.kt | 0 .../error/RegisterUsernameTooShort.kt | 0 .../error/SomePermissionsArentExists.kt | 0 .../platform/error/SomeTicketsArentExists.kt | 0 .../platform/error/SomeUsersArentExists.kt | 0 .../panomc/platform/error/TicketIsClosed.kt | 0 .../panomc/platform/error/TitleCantBeEmpty.kt | 0 .../platform/error/WebsiteLogoExceedsSize.kt | 0 .../error/WebsiteLogoWrongContentType.kt | 0 .../kotlin/com/panomc/platform/mail/Mail.kt | 0 .../platform/mail/MailClientProvider.kt | 0 .../com/panomc/platform/mail/MailManager.kt | 0 .../panomc/platform/mail/NotificationMail.kt | 0 .../platform/mail/mails/ActivationMail.kt | 0 .../platform/mail/mails/ChangeEmailMail.kt | 0 .../platform/mail/mails/ResetPasswordMail.kt | 0 .../platform/mail/notification/BannedMail.kt | 0 .../mail/notification/PasswordUpdatedMail.kt | 0 .../kotlin/com/panomc/platform/model/Api.kt | 0 .../kotlin/com/panomc/platform/model/Error.kt | 0 .../com/panomc/platform/model/Errors.kt | 0 .../com/panomc/platform/model/LoggedInApi.kt | 0 .../com/panomc/platform/model/PanelApi.kt | 0 .../kotlin/com/panomc/platform/model/Path.kt | 0 .../com/panomc/platform/model/Result.kt | 0 .../kotlin/com/panomc/platform/model/Route.kt | 0 .../com/panomc/platform/model/RouteType.kt | 0 .../com/panomc/platform/model/SetupApi.kt | 0 .../com/panomc/platform/model/Successful.kt | 0 .../com/panomc/platform/model/Template.kt | 0 .../notification/NotificationManager.kt | 0 .../notification/NotificationStatus.kt | 0 .../platform/notification/Notifications.kt | 0 .../panomc/platform/route/RouterProvider.kt | 28 +- .../platform/server/PlatformCodeManager.kt | 0 .../platform/server/ServerAuthProvider.kt | 0 .../com/panomc/platform/server/ServerEvent.kt | 0 .../platform/server/ServerEventListener.kt | 0 .../panomc/platform/server/ServerManager.kt | 0 .../panomc/platform/server/ServerStatus.kt | 0 .../com/panomc/platform/server/ServerType.kt | 0 .../server/event/OnPlayerDisconnect.kt | 0 .../platform/server/event/OnPlayerJoin.kt | 0 .../platform/server/event/OnServerConnect.kt | 0 .../com/panomc/platform/setup/SetupManager.kt | 0 .../panomc/platform/token/TokenProvider.kt | 0 .../com/panomc/platform/token/TokenType.kt | 0 .../platform/util/CSRFTokenGenerator.kt | 0 .../platform/util/DashboardPeriodType.kt | 0 .../com/panomc/platform/util/DateUtil.kt | 0 .../panomc/platform/util/FileUploadUtil.kt | 0 .../panomc/platform/util/KeyGeneratorUtil.kt | 0 .../com/panomc/platform/util/PlayerStatus.kt | 0 .../com/panomc/platform/util/PostStatus.kt | 0 .../com/panomc/platform/util/Regexes.kt | 0 .../com/panomc/platform/util/RegisterUtil.kt | 0 .../com/panomc/platform/util/TextUtil.kt | 0 .../panomc/platform/util/TicketPageType.kt | 0 .../com/panomc/platform/util/TicketStatus.kt | 0 .../com/panomc/platform/util/TimeUtil.kt | 0 .../com/panomc/platform/util/UIHelper.kt | 0 .../com/panomc/platform/util/UpdatePeriod.kt | 0 .../util/deserializer/BooleanDeserializer.kt | 0 .../deserializer/JsonObjectDeserializer.kt | 0 .../resources/assets/img/minecraft-icon.png | Bin .../resources/assets/img/minecraft-logo.png | Bin .../src}/main/resources/log4j2.properties | 2 +- .../src}/main/resources/mail/activation.hbs | 0 .../src}/main/resources/mail/change-email.hbs | 0 .../resources/mail/notification/banned.hbs | 0 .../mail/notification/password-updated.hbs | 0 .../main/resources/mail/reset-password.hbs | 0 {src => Pano/src}/test/java/.gitkeep | 0 {src => Pano/src}/test/kotlin/.gitkeep | 0 {src => Pano/src}/test/resources/.gitkeep | 0 build.gradle.kts | 153 ++-------- gradle.properties | 8 +- plugins/build.gradle.kts | 36 +++ settings.gradle.kts | 10 + .../platform/route/api/GetFaviconAPI.kt | 47 --- .../platform/route/api/GetPostThumbnailAPI.kt | 48 --- .../platform/route/api/GetSiteInfoAPI.kt | 28 -- .../platform/route/api/GetWebsiteLogoAPI.kt | 47 --- .../com/panomc/platform/route/api/TestAPI.kt | 17 -- .../platform/route/api/VisitorVisitAPI.kt | 41 --- .../route/api/auth/GetCredentialsAPI.kt | 34 --- .../platform/route/api/auth/LoginAPI.kt | 82 ----- .../platform/route/api/auth/LogoutAPI.kt | 36 --- .../platform/route/api/auth/RegisterAPI.kt | 74 ----- .../route/api/auth/RenewPasswordAPI.kt | 93 ------ .../route/api/auth/ResetPasswordAPI.kt | 71 ----- .../platform/route/api/auth/VerifyEmailAPI.kt | 68 ----- .../route/api/auth/VerifyNewEmailAPI.kt | 78 ----- .../notification/DeleteAllNotificationAPI.kt | 28 -- .../api/notification/DeleteNotificationAPI.kt | 52 ---- .../notification/GetMoreNotificationsAPI.kt | 61 ---- .../api/notification/GetNotificationsAPI.kt | 52 ---- .../notification/GetQuickNotificationsAPI.kt | 50 --- .../notification/MarkNotificationAsReadAPI.kt | 52 ---- .../MarkQuickNotificationsAsReadAPI.kt | 34 --- .../route/api/panel/PanelGetBasicDataAPI.kt | 90 ------ .../route/api/panel/PanelGetDashboardAPI.kt | 93 ------ .../route/api/panel/PanelGetStatisticsAPI.kt | 143 --------- .../route/api/panel/PanelIsUserExistsAPI.kt | 42 --- .../PanelCloseConnectServerCardAPI.kt | 41 --- .../PanelCloseGettingStartedCardAPI.kt | 41 --- .../PanelDeleteAllNotificationAPI.kt | 28 -- .../PanelDeleteNotificationAPI.kt | 52 ---- .../PanelGetMoreNotificationsAPI.kt | 61 ---- .../notification/PanelGetNotificationsAPI.kt | 52 ---- .../PanelGetQuickNotificationsAPI.kt | 50 --- .../PanelMarkNotificationAsReadAPI.kt | 52 ---- .../PanelMarkQuickNotificationsAsReadAPI.kt | 34 --- .../permission/PanelAddPermissionGroupAPI.kt | 180 ----------- .../PanelDeletePermissionGroupAPI.kt | 60 ---- .../permission/PanelGetPermissionGroupAPI.kt | 65 ---- .../permission/PanelGetPermissionGroupsAPI.kt | 104 ------- .../permission/PanelGetPermissionsAPI.kt | 37 --- .../PanelSetPermissionGroupPermissionAPI.kt | 95 ------ .../PanelUpdatePermissionGroupAPI.kt | 284 ------------------ .../platformAuth/PanelGetRefreshKeyAPI.kt | 30 -- .../api/panel/player/PanelBanPlayerAPI.kt | 110 ------- .../api/panel/player/PanelDeletePlayerAPI.kt | 117 -------- .../api/panel/player/PanelGetPlayerAPI.kt | 151 ---------- .../api/panel/player/PanelGetPlayersAPI.kt | 164 ---------- .../player/PanelSendValidationEmailAPI.kt | 73 ----- .../api/panel/player/PanelUnbanPlayerAPI.kt | 69 ----- .../api/panel/player/PanelUpdatePlayerAPI.kt | 143 --------- .../PanelUpdatePlayerPermissionGroupAPI.kt | 125 -------- .../panel/post/PanelCreateOrUpdatePostAPI.kt | 137 --------- .../api/panel/post/PanelDeletePostAPI.kt | 54 ---- .../route/api/panel/post/PanelGetPostAPI.kt | 62 ---- .../panel/post/PanelGetPostCategoriesAPI.kt | 112 ------- .../route/api/panel/post/PanelGetPostsAPI.kt | 160 ---------- .../panel/post/PanelUpdatePostStatusAPI.kt | 72 ----- .../post/category/PanelAddPostCategoryAPI.kt | 101 ------- .../category/PanelDeletePostCategoryAPI.kt | 49 --- .../category/PanelUpdatePostCategoryAPI.kt | 101 ------- .../PanelAcceptServerConnectRequestAPI.kt | 61 ---- .../api/panel/server/PanelDeleteServerAPI.kt | 92 ------ .../server/PanelGetConnectedServersAPI.kt | 33 -- .../api/panel/server/PanelGetServerAPI.kt | 45 --- .../server/PanelGetServerDashboardAPI.kt | 48 --- .../panel/server/PanelMakeMainServerAPI.kt | 51 ---- .../PanelRejectServerConnectRequestAPI.kt | 53 ---- .../api/panel/server/PanelSelectServerAPI.kt | 62 ---- .../api/panel/settings/PanelGetAboutAPI.kt | 31 -- .../api/panel/settings/PanelGetSettingsAPI.kt | 70 ----- .../panel/settings/PanelUpdateSettingAPI.kt | 168 ----------- .../api/panel/ticket/PanelDeleteTicketsAPI.kt | 48 --- .../api/panel/ticket/PanelGetTicketAPI.kt | 114 ------- .../panel/ticket/PanelGetTicketMessagesAPI.kt | 88 ------ .../api/panel/ticket/PanelGetTicketsAPI.kt | 159 ---------- .../panel/ticket/PanelSendTicketMessageAPI.kt | 104 ------- .../api/panel/ticket/PanelUpdateTicketsAPI.kt | 88 ------ .../category/PanelAddTicketCategoryAPI.kt | 79 ----- .../category/PanelDeleteTicketCategoryAPI.kt | 49 --- .../category/PanelGetTicketCategoriesAPI.kt | 112 ------- .../category/PanelUpdateTicketCategoryAPI.kt | 86 ------ .../route/api/posts/GetPostDetailAPI.kt | 114 ------- .../route/api/posts/GetPostPreviewAPI.kt | 75 ----- .../platform/route/api/posts/GetPostsAPI.kt | 33 -- .../route/api/posts/GetPostsService.kt | 128 -------- .../route/api/profile/ChangeEmailAPI.kt | 90 ------ .../route/api/profile/GetPlayerProfileAPI.kt | 41 --- .../route/api/profile/GetProfileAPI.kt | 33 -- .../api/profile/SendResetPasswordEmailAPI.kt | 44 --- .../route/api/server/ServerConnectAPI.kt | 113 ------- .../route/api/server/ServerConnectNewAPI.kt | 107 ------- .../route/api/server/ServerDisconnectAPI.kt | 61 ---- .../platform/route/api/setup/CheckAPI.kt | 20 -- .../route/api/setup/DBConnectionTestAPI.kt | 81 ----- .../platform/route/api/setup/FinishAPI.kt | 126 -------- .../api/setup/VerifyMailConfigurationAPI.kt | 99 ------ .../route/api/setup/step/BackStepAPI.kt | 22 -- .../route/api/setup/step/GoAnyBackStepAPI.kt | 42 --- .../route/api/setup/step/NextStepAPI.kt | 121 -------- .../route/api/sidebar/HomeSidebarAPI.kt | 45 --- .../api/sidebar/PlayerProfileSidebarAPI.kt | 54 ---- .../route/api/sidebar/ProfileSidebarAPI.kt | 45 --- .../route/api/sidebar/SupportSidebarAPI.kt | 24 -- .../route/api/ticket/CreateTicketAPI.kt | 104 ------- .../platform/route/api/ticket/GetTicketAPI.kt | 122 -------- .../api/ticket/GetTicketCategoriesAPI.kt | 39 --- .../route/api/ticket/GetTicketMessagesAPI.kt | 93 ------ .../route/api/ticket/GetTicketsAPI.kt | 48 --- .../route/api/ticket/GetTicketsService.kt | 135 --------- .../route/api/ticket/SendTicketMessageAPI.kt | 115 ------- .../route/api/ticket/UpdateTicketAPI.kt | 82 ----- .../platform/route/template/IndexTemplate.kt | 33 -- 335 files changed, 597 insertions(+), 8600 deletions(-) create mode 100755 Pano/build.gradle.kts rename {src => Pano/src}/main/java/.gitkeep (100%) rename {src => Pano/src}/main/java/util/StringUtil.java (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/AppConstants.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/Main.kt (80%) create mode 100644 Pano/src/main/kotlin/com/panomc/platform/PanoPluginLoader.kt create mode 100644 Pano/src/main/kotlin/com/panomc/platform/PluginEventManager.kt create mode 100644 Pano/src/main/kotlin/com/panomc/platform/PluginFactory.kt create mode 100644 Pano/src/main/kotlin/com/panomc/platform/PluginManager.kt rename {src => Pano/src}/main/kotlin/com/panomc/platform/ReleaseStage.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/SpringConfig.kt (81%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/annotation/Boot.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/annotation/Dao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/annotation/Endpoint.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/annotation/Event.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/annotation/Ignore.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/annotation/Migration.kt (100%) create mode 100644 Pano/src/main/kotlin/com/panomc/platform/api/EventListener.kt create mode 100644 Pano/src/main/kotlin/com/panomc/platform/api/PanoEventListener.kt create mode 100644 Pano/src/main/kotlin/com/panomc/platform/api/PanoPlugin.kt create mode 100644 Pano/src/main/kotlin/com/panomc/platform/api/PluginEventListener.kt create mode 100755 Pano/src/main/kotlin/com/panomc/platform/api/annotation/EventListener.kt rename {src => Pano/src}/main/kotlin/com/panomc/platform/auth/AuthProvider.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/auth/PanelPermission.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/config/ConfigManager.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/config/ConfigMigration.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/config/migration/.gitkeep (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/DBEntity.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/Dao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/DaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/DatabaseManager.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/DatabaseMigration.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/NotificationDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/PanelConfigDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/PanelNotificationDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/PermissionDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/PermissionGroupDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/PermissionGroupPermsDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/PostCategoryDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/PostDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/SchemeVersionDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/ServerDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/ServerPlayerDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/SystemPropertyDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/TicketCategoryDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/TicketDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/TicketMessageDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/TokenDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/UserDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/dao/WebsiteViewDao.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/NotificationDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/PanelConfigDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/PanelNotificationDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/PermissionDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupPermsDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/PostCategoryDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/PostDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/SchemeVersionDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/ServerDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/ServerPlayerDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/SystemPropertyDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/TicketCategoryDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/TicketDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/TicketMessageDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/TokenDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/UserDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/implementation/WebsiteViewDaoImpl.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/migration/.gitkeep (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/Notification.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/PanelConfig.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/PanelNotification.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/Permission.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/PermissionGroup.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/PermissionGroupPerms.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/Post.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/PostCategory.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/SchemeVersion.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/Server.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/ServerPlayer.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/SystemProperty.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/Ticket.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/TicketCategory.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/TicketMessage.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/Token.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/User.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/db/model/WebsiteView.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/AlreadyBanned.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/BadRequest.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/CantBanYourself.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/CantChangeEmailWait15Minutes.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/CantDeleteAdminPermission.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/CantDeleteYourself.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/CantResetPasswordWait15Minutes.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/CantUpdateAdminPermission.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/CantUpdatePermGroupYourself.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/CategoryNotExists.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/CurrentPasswordNotCorrect.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/EmailAlreadyVerified.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/FaviconExceedsSize.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/FaviconWrongContentType.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/InstallationRequired.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/InternalServerError.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/InvalidData.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/InvalidEmail.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/InvalidIpAddress.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/InvalidLink.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/InvalidPlatformCode.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/InvalidToken.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/LastAdmin.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/LoginEmailNotVerified.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/LoginIsInvalid.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/LoginUserIsBanned.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/MessageCantBeEmpty.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NeedPermission.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NewEmailExists.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NewPasswordEmpty.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NewPasswordRepeatDoesntMatch.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NewPasswordTooLong.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NewPasswordTooShort.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NoPermission.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminPermGroup.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminUser.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NotBanned.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NotExists.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/NotLoggedIn.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/PageNotFound.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/PasswordEmpty.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/PasswordTooLong.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/PasswordTooShort.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/PermGroupNotExists.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/PlatformAlreadyInstalled.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/PostNotFound.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/PostThumbnailExceedsSize.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/PostThumbnailWrongContentType.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterCantVerifyRobot.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterEmailEmpty.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterEmailNotAvailable.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterInvalidEmail.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterInvalidUsername.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterNotAcceptedAgreement.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterPasswordAndPasswordRepeatNotSame.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterUsernameEmpty.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterUsernameNotAvailable.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterUsernameTooLong.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/RegisterUsernameTooShort.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/SomePermissionsArentExists.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/SomeTicketsArentExists.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/SomeUsersArentExists.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/TicketIsClosed.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/TitleCantBeEmpty.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/WebsiteLogoExceedsSize.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/error/WebsiteLogoWrongContentType.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/mail/Mail.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/mail/MailClientProvider.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/mail/MailManager.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/mail/NotificationMail.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/mail/mails/ActivationMail.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/mail/mails/ChangeEmailMail.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/mail/mails/ResetPasswordMail.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/mail/notification/BannedMail.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/mail/notification/PasswordUpdatedMail.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/Api.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/Error.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/Errors.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/LoggedInApi.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/PanelApi.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/Path.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/Result.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/Route.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/RouteType.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/SetupApi.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/Successful.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/model/Template.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/notification/NotificationManager.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/notification/NotificationStatus.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/notification/Notifications.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/route/RouterProvider.kt (78%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/PlatformCodeManager.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/ServerAuthProvider.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/ServerEvent.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/ServerEventListener.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/ServerManager.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/ServerStatus.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/ServerType.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/event/OnPlayerDisconnect.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/event/OnPlayerJoin.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/server/event/OnServerConnect.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/setup/SetupManager.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/token/TokenProvider.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/token/TokenType.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/CSRFTokenGenerator.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/DashboardPeriodType.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/DateUtil.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/FileUploadUtil.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/KeyGeneratorUtil.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/PlayerStatus.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/PostStatus.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/Regexes.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/RegisterUtil.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/TextUtil.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/TicketPageType.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/TicketStatus.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/TimeUtil.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/UIHelper.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/UpdatePeriod.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/deserializer/BooleanDeserializer.kt (100%) rename {src => Pano/src}/main/kotlin/com/panomc/platform/util/deserializer/JsonObjectDeserializer.kt (100%) rename {src => Pano/src}/main/resources/assets/img/minecraft-icon.png (100%) rename {src => Pano/src}/main/resources/assets/img/minecraft-logo.png (100%) rename {src => Pano/src}/main/resources/log4j2.properties (94%) rename {src => Pano/src}/main/resources/mail/activation.hbs (100%) rename {src => Pano/src}/main/resources/mail/change-email.hbs (100%) rename {src => Pano/src}/main/resources/mail/notification/banned.hbs (100%) rename {src => Pano/src}/main/resources/mail/notification/password-updated.hbs (100%) rename {src => Pano/src}/main/resources/mail/reset-password.hbs (100%) rename {src => Pano/src}/test/java/.gitkeep (100%) rename {src => Pano/src}/test/kotlin/.gitkeep (100%) rename {src => Pano/src}/test/resources/.gitkeep (100%) create mode 100644 plugins/build.gradle.kts delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/GetFaviconAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/GetPostThumbnailAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/GetWebsiteLogoAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/TestAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/VisitorVisitAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/auth/GetCredentialsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/auth/LoginAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/auth/LogoutAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/auth/RegisterAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/auth/RenewPasswordAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/auth/ResetPasswordAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/auth/VerifyEmailAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/auth/VerifyNewEmailAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/notification/DeleteAllNotificationAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/notification/DeleteNotificationAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/notification/GetMoreNotificationsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/notification/GetNotificationsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/notification/GetQuickNotificationsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/notification/MarkNotificationAsReadAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/notification/MarkQuickNotificationsAsReadAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetBasicDataAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetDashboardAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetStatisticsAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/panel/PanelIsUserExistsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/dashboard/PanelCloseConnectServerCardAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/dashboard/PanelCloseGettingStartedCardAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelDeleteAllNotificationAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelDeleteNotificationAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetMoreNotificationsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetNotificationsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetQuickNotificationsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelMarkNotificationAsReadAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelMarkQuickNotificationsAsReadAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelAddPermissionGroupAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelDeletePermissionGroupAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionGroupAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionGroupsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelSetPermissionGroupPermissionAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelUpdatePermissionGroupAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/platformAuth/PanelGetRefreshKeyAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelBanPlayerAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelDeletePlayerAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelGetPlayerAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelGetPlayersAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelSendValidationEmailAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUnbanPlayerAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUpdatePlayerAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUpdatePlayerPermissionGroupAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelCreateOrUpdatePostAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelDeletePostAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostCategoriesAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelUpdatePostStatusAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelAddPostCategoryAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelDeletePostCategoryAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelUpdatePostCategoryAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelAcceptServerConnectRequestAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelDeleteServerAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetConnectedServersAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetServerAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetServerDashboardAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelMakeMainServerAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelRejectServerConnectRequestAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelSelectServerAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelGetAboutAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelGetSettingsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelUpdateSettingAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelDeleteTicketsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketMessagesAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelSendTicketMessageAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelUpdateTicketsAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelAddTicketCategoryAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelDeleteTicketCategoryAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelGetTicketCategoriesAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelUpdateTicketCategoryAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/posts/GetPostDetailAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/posts/GetPostPreviewAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/posts/GetPostsAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/posts/GetPostsService.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/profile/ChangeEmailAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/profile/GetPlayerProfileAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/profile/GetProfileAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/profile/SendResetPasswordEmailAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/server/ServerConnectAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/server/ServerConnectNewAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/server/ServerDisconnectAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/setup/CheckAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/setup/DBConnectionTestAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/setup/FinishAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/setup/VerifyMailConfigurationAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/setup/step/BackStepAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/setup/step/GoAnyBackStepAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/setup/step/NextStepAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/sidebar/HomeSidebarAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/sidebar/PlayerProfileSidebarAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/sidebar/ProfileSidebarAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/sidebar/SupportSidebarAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/ticket/CreateTicketAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketCategoriesAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketMessagesAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketsAPI.kt delete mode 100644 src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketsService.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/ticket/SendTicketMessageAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/api/ticket/UpdateTicketAPI.kt delete mode 100755 src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt diff --git a/.gitignore b/.gitignore index e34ec497..63135483 100755 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,11 @@ config.conf .docker -file-uploads \ No newline at end of file +file-uploads + +# Ignore everything under plugins/ +plugins/* + +# Except the following files +!plugins/build.gradle.kts +!plugins/*.jar \ No newline at end of file diff --git a/Pano/build.gradle.kts b/Pano/build.gradle.kts new file mode 100755 index 00000000..73e577dc --- /dev/null +++ b/Pano/build.gradle.kts @@ -0,0 +1,151 @@ +val vertxVersion: String by project +val gsonVersion: String by project +val handlebarsVersion: String by project +val log4jVersion = "2.21.1" +val appMainClass = "com.panomc.platform.Main" +val pf4jVersion: String by project +val pluginsDir: File? by rootProject.extra + +plugins { + kotlin("jvm") version "1.9.20" + kotlin("kapt") version "1.9.20" + id("com.github.johnrengelman.shadow") version "8.1.1" + application + `maven-publish` +} + +group = "com.panomc" +version = + (if (project.hasProperty("version") && project.findProperty("version") != "unspecified") project.findProperty("version") else "local-build")!! + +val buildType = project.findProperty("buildType") as String? ?: "alpha" +val timeStamp: String by project +val buildDir by extra { file("${rootProject.layout.buildDirectory.get()}/libs") } + +repositories { + mavenCentral() + maven("https://oss.sonatype.org/content/repositories/iovertx-3720/") + maven("https://jitpack.io") +} + +dependencies { + implementation(kotlin("stdlib-jdk8")) + implementation(kotlin("reflect")) + + testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0") + testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0") + testImplementation("io.vertx:vertx-unit:$vertxVersion") + + implementation("io.vertx:vertx-web:$vertxVersion") + implementation("io.vertx:vertx-web-client:$vertxVersion") + implementation("io.vertx:vertx-mysql-client:$vertxVersion") + implementation("io.vertx:vertx-mail-client:$vertxVersion") + implementation("io.vertx:vertx-lang-kotlin:$vertxVersion") + implementation("io.vertx:vertx-web-templ-handlebars:$vertxVersion") + implementation("io.vertx:vertx-config:$vertxVersion") + implementation("io.vertx:vertx-config-hocon:$vertxVersion") + implementation("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion") + implementation("io.vertx:vertx-web-validation:$vertxVersion") + implementation("io.vertx:vertx-json-schema:$vertxVersion") + implementation("io.vertx:vertx-web-proxy:$vertxVersion") + + // https://mvnrepository.com/artifact/com.auth0/java-jwt + implementation("com.auth0:java-jwt:4.4.0") + + implementation(group = "org.apache.logging.log4j", name = "log4j-api", version = log4jVersion) + implementation(group = "org.apache.logging.log4j", name = "log4j-core", version = log4jVersion) + implementation(group = "org.apache.logging.log4j", name = "log4j-slf4j2-impl", version = log4jVersion) + + // recaptcha v2 1.0.4 + implementation("com.github.triologygmbh:reCAPTCHA-V2-java:1.0.4") + + // https://mvnrepository.com/artifact/commons-codec/commons-codec + implementation(group = "commons-codec", name = "commons-codec", version = "1.16.1") + + // https://mvnrepository.com/artifact/org.springframework/spring-context + implementation("org.springframework:spring-context:5.3.32") + + // https://mvnrepository.com/artifact/com.google.code.gson/gson + implementation("com.google.code.gson:gson:2.10.1") + + implementation("org.pf4j:pf4j:${pf4jVersion}") +} + +tasks { + register("copyJar") { + if (shadowJar.get().archiveFile.get().asFile.parentFile.absolutePath != buildDir.absolutePath) { + doLast { + copy { + from(shadowJar.get().archiveFile.get().asFile.absolutePath) + into(buildDir) + } + } + } + + outputs.upToDateWhen { false } + mustRunAfter(shadowJar) + } + + register("buildDev") { + dependsOn("build") + } + + shadowJar { + manifest { + val attrMap = mutableMapOf() + + if (project.gradle.startParameter.taskNames.contains("buildDev")) + attrMap["MODE"] = "DEVELOPMENT" + + attrMap["VERSION"] = version.toString() + attrMap["BUILD_TYPE"] = buildType + + attributes(attrMap) + } + + archiveFileName.set("${rootProject.name}-${version}.jar") + + if (project.gradle.startParameter.taskNames.contains("publish")) { + archiveFileName.set(archiveFileName.get().lowercase()) + } + } + + jar { + enabled = false + dependsOn(shadowJar) + dependsOn("copyJar") + } +} + +tasks.named("run") { + environment("EnvironmentType", "DEVELOPMENT") + environment("PanoVersion", version) + environment("PanoBuildType", buildType) + pluginsDir?.let { systemProperty("pf4j.pluginsDir", it.absolutePath) } +} + +application { + mainClass.set(appMainClass) +} + +publishing { + repositories { + maven { + name = "Pano" + url = uri("https://maven.pkg.github.com/panocms/pano") + credentials { + username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME_GITHUB") + password = project.findProperty("gpr.token") as String? ?: System.getenv("TOKEN_GITHUB") + } + } + } + + publications { + create("shadow") { + project.extensions.configure { + artifactId = "pano" + component(this@create) + } + } + } +} \ No newline at end of file diff --git a/src/main/java/.gitkeep b/Pano/src/main/java/.gitkeep similarity index 100% rename from src/main/java/.gitkeep rename to Pano/src/main/java/.gitkeep diff --git a/src/main/java/util/StringUtil.java b/Pano/src/main/java/util/StringUtil.java similarity index 100% rename from src/main/java/util/StringUtil.java rename to Pano/src/main/java/util/StringUtil.java diff --git a/src/main/kotlin/com/panomc/platform/AppConstants.kt b/Pano/src/main/kotlin/com/panomc/platform/AppConstants.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/AppConstants.kt rename to Pano/src/main/kotlin/com/panomc/platform/AppConstants.kt diff --git a/src/main/kotlin/com/panomc/platform/Main.kt b/Pano/src/main/kotlin/com/panomc/platform/Main.kt similarity index 80% rename from src/main/kotlin/com/panomc/platform/Main.kt rename to Pano/src/main/kotlin/com/panomc/platform/Main.kt index d30ac3c3..7106e229 100755 --- a/src/main/kotlin/com/panomc/platform/Main.kt +++ b/Pano/src/main/kotlin/com/panomc/platform/Main.kt @@ -71,7 +71,7 @@ class Main : CoroutineVerticle() { } catch (e: Exception) { System.getenv("PanoBuildType").toString() } - ) + )!! } @JvmStatic @@ -82,6 +82,8 @@ class Main : CoroutineVerticle() { enum class EnvironmentType { DEVELOPMENT, RELEASE } + + lateinit var applicationContext: AnnotationConfigApplicationContext } private val logger by lazy { @@ -89,8 +91,8 @@ class Main : CoroutineVerticle() { } private lateinit var router: Router - private lateinit var applicationContext: AnnotationConfigApplicationContext private lateinit var configManager: ConfigManager + private lateinit var pluginManager: PluginManager override suspend fun start() { println( @@ -112,6 +114,8 @@ class Main : CoroutineVerticle() { private suspend fun init() { initDependencyInjection() + initPlugins() + initConfigManager() clearTempFiles() @@ -127,6 +131,47 @@ class Main : CoroutineVerticle() { initRoutes() } + private fun initPlugins() { + logger.info("Initializing plugin manager") + + pluginManager = applicationContext.getBean(PluginManager::class.java) + + logger.info("Loading plugins") + + pluginManager.loadPlugins() + + +// pluginManager.plugins + + logger.info("Enabling plugins") + + pluginManager.startPlugins() +// try { +// +// // Iterate through each plugin +// for (plugin in pluginManager.plugins) { +// // Get the main class of the plugin +// val mainClass = plugin.pluginClassLoader.loadClass(plugin.descriptor.pluginClass) +// +// // Get the package of the main class +// val mainPackage = mainClass.`package` +// +// // Print the base package of the main class +// if (mainPackage != null) { +// println("Base package of main class of plugin ${plugin.descriptor.pluginId}: ${mainPackage.name}") +//// applicationContext.scan(mainPackage.name) +// } else { +// println("Main class package not found for plugin ${plugin.descriptor.pluginId}") +// } +// } +//// pluginManager.plugins.map {(it.plugin as PanoPlugin).context.pluginBeanContext.getBeansWithAnnotation(Endpoint::class.java)} +// } catch (e: Exception) { +// logger.error(e.toString()) +// } + + + } + private fun clearTempFiles() { val tempFolder = File(configManager.getConfig().getString("file-uploads-folder") + "/temp") diff --git a/Pano/src/main/kotlin/com/panomc/platform/PanoPluginLoader.kt b/Pano/src/main/kotlin/com/panomc/platform/PanoPluginLoader.kt new file mode 100644 index 00000000..7fc2fb44 --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/PanoPluginLoader.kt @@ -0,0 +1,17 @@ +package com.panomc.platform + +import org.pf4j.JarPluginLoader +import org.pf4j.PluginClassLoader +import org.pf4j.PluginDescriptor +import org.pf4j.PluginManager +import java.nio.file.Path + +class PanoPluginLoader(pluginManager: PluginManager) : JarPluginLoader(pluginManager) { + override fun loadPlugin(pluginPath: Path, pluginDescriptor: PluginDescriptor): ClassLoader { + val pluginClassLoader = PluginClassLoader(pluginManager, pluginDescriptor, javaClass.classLoader) + + pluginClassLoader.addFile(pluginPath.toFile()) + + return pluginClassLoader + } +} \ No newline at end of file diff --git a/Pano/src/main/kotlin/com/panomc/platform/PluginEventManager.kt b/Pano/src/main/kotlin/com/panomc/platform/PluginEventManager.kt new file mode 100644 index 00000000..9ce83d1e --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/PluginEventManager.kt @@ -0,0 +1,45 @@ +package com.panomc.platform + +import com.panomc.platform.api.EventListener +import com.panomc.platform.api.PanoEventListener +import com.panomc.platform.api.PanoPlugin +import com.panomc.platform.api.PluginEventListener +import org.springframework.context.annotation.AnnotationConfigApplicationContext + +class PluginEventManager { + companion object { + private val eventListeners = mutableMapOf>() + + fun getEventListeners() = eventListeners.toMap() + + internal inline fun getPanoEventListeners() = + eventListeners.flatMap { it.value }.filterIsInstance() + + + inline fun getEventListeners() = + getEventListeners().flatMap { it.value }.filter { it !is PanoEventListener }.filterIsInstance() + } + + internal fun initializePlugin(plugin: PanoPlugin, pluginBeanContext: AnnotationConfigApplicationContext) { + if (eventListeners[plugin] == null) { + eventListeners[plugin] = pluginBeanContext + .getBeansWithAnnotation(com.panomc.platform.api.annotation.EventListener::class.java) + .map { it.value as EventListener } + .toMutableList() + } + } + + internal fun unregisterPlugin(plugin: PanoPlugin) { + eventListeners.remove(plugin) + } + + fun register(plugin: PanoPlugin, eventListener: EventListener) { + if (eventListeners[plugin]!!.none { it::class == eventListener::class }) { + eventListeners[plugin]!!.add(eventListener) + } + } + + fun unRegister(plugin: PanoPlugin, eventListener: EventListener) { + eventListeners[plugin]?.remove(eventListener) + } +} \ No newline at end of file diff --git a/Pano/src/main/kotlin/com/panomc/platform/PluginFactory.kt b/Pano/src/main/kotlin/com/panomc/platform/PluginFactory.kt new file mode 100644 index 00000000..34b88d3c --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/PluginFactory.kt @@ -0,0 +1,56 @@ +package com.panomc.platform + +import com.panomc.platform.PluginManager.Companion.pluginEventManager +import com.panomc.platform.SpringConfig.Companion.vertx +import com.panomc.platform.api.PanoPlugin +import kotlinx.coroutines.runBlocking +import org.pf4j.DefaultPluginFactory +import org.pf4j.Plugin +import org.pf4j.PluginWrapper +import org.slf4j.LoggerFactory +import org.springframework.context.annotation.AnnotationConfigApplicationContext + +class PluginFactory : DefaultPluginFactory() { + companion object { + private val logger = LoggerFactory.getLogger(PluginFactory::class.java) + } + + override fun createInstance(pluginClass: Class<*>, pluginWrapper: PluginWrapper): Plugin? { + val pluginBeanContext by lazy { + val pluginBeanContext = AnnotationConfigApplicationContext() + + pluginBeanContext.parent = Main.applicationContext + pluginBeanContext.classLoader = pluginClass.classLoader + pluginBeanContext.scan(pluginClass.`package`.name) + pluginBeanContext.refresh() + + pluginBeanContext + } + + try { + val constructor = pluginClass.getConstructor() + + val plugin = constructor.newInstance() as PanoPlugin + + pluginEventManager.initializePlugin(plugin, pluginBeanContext) + + plugin.pluginId = pluginWrapper.pluginId + plugin.vertx = vertx + plugin.pluginEventManager = pluginEventManager + plugin.environmentType = Main.ENVIRONMENT + plugin.releaseStage = Main.STAGE + plugin.pluginBeanContext = pluginBeanContext + plugin.applicationContext = Main.applicationContext + + runBlocking { + plugin.onLoad() + } + + return plugin + } catch (e: Exception) { + logger.error(e.message, e) + } + + return null + } +} \ No newline at end of file diff --git a/Pano/src/main/kotlin/com/panomc/platform/PluginManager.kt b/Pano/src/main/kotlin/com/panomc/platform/PluginManager.kt new file mode 100644 index 00000000..a5861f1a --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/PluginManager.kt @@ -0,0 +1,34 @@ +package com.panomc.platform + +import org.pf4j.* +import java.nio.file.Path + +class PluginManager(importPaths: List) : DefaultPluginManager(importPaths) { + companion object { + internal val pluginEventManager = PluginEventManager() + } + + override fun startPlugins() { + super.startPlugins() + } + + override fun createPluginDescriptorFinder(): CompoundPluginDescriptorFinder { + return CompoundPluginDescriptorFinder() // Demo is using the Manifest file + // PropertiesPluginDescriptorFinder is commented out just to avoid error log + //.add(PropertiesPluginDescriptorFinder()) + .add(ManifestPluginDescriptorFinder()) + } + + override fun createPluginFactory(): PluginFactory { + return PluginFactory() + } + + override fun createPluginLoader(): PluginLoader { + return CompoundPluginLoader() + .add(PanoPluginLoader(this)) { this.isNotDevelopment } + } + + override fun loadPlugins() { + super.loadPlugins() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/ReleaseStage.kt b/Pano/src/main/kotlin/com/panomc/platform/ReleaseStage.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/ReleaseStage.kt rename to Pano/src/main/kotlin/com/panomc/platform/ReleaseStage.kt diff --git a/src/main/kotlin/com/panomc/platform/SpringConfig.kt b/Pano/src/main/kotlin/com/panomc/platform/SpringConfig.kt similarity index 81% rename from src/main/kotlin/com/panomc/platform/SpringConfig.kt rename to Pano/src/main/kotlin/com/panomc/platform/SpringConfig.kt index 61415ed1..7716acf4 100755 --- a/src/main/kotlin/com/panomc/platform/SpringConfig.kt +++ b/Pano/src/main/kotlin/com/panomc/platform/SpringConfig.kt @@ -16,6 +16,7 @@ import org.slf4j.Logger import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.annotation.* +import java.nio.file.Paths @Configuration @@ -24,7 +25,7 @@ open class SpringConfig { companion object { private const val SECRET_KEY = "" - private lateinit var vertx: Vertx + internal lateinit var vertx: Vertx private lateinit var logger: Logger internal fun setDefaults(vertx: Vertx, logger: Logger) { @@ -33,6 +34,8 @@ open class SpringConfig { } } + private val pluginsDir = System.getProperty("pf4j.pluginsDir", "./plugins") + @Autowired private lateinit var applicationContext: AnnotationConfigApplicationContext @@ -61,9 +64,18 @@ open class SpringConfig { schemaParser: SchemaParser, configManager: ConfigManager, httpClient: HttpClient, - setupManager: SetupManager + setupManager: SetupManager, + pluginManager: PluginManager ) = - RouterProvider.create(vertx, applicationContext, schemaParser, configManager, httpClient, setupManager) + RouterProvider.create( + vertx, + applicationContext, + schemaParser, + configManager, + httpClient, + setupManager, + pluginManager + ) .provide() @Bean @@ -87,4 +99,9 @@ open class SpringConfig { @Lazy @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) open fun provideHttpClient(): HttpClient = vertx.createHttpClient() + + @Bean + @Lazy + @Scope(value = ConfigurableBeanFactory.SCOPE_SINGLETON) + open fun pluginManager(): PluginManager = PluginManager(listOf(Paths.get(pluginsDir))) } \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/annotation/Boot.kt b/Pano/src/main/kotlin/com/panomc/platform/annotation/Boot.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/annotation/Boot.kt rename to Pano/src/main/kotlin/com/panomc/platform/annotation/Boot.kt diff --git a/src/main/kotlin/com/panomc/platform/annotation/Dao.kt b/Pano/src/main/kotlin/com/panomc/platform/annotation/Dao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/annotation/Dao.kt rename to Pano/src/main/kotlin/com/panomc/platform/annotation/Dao.kt diff --git a/src/main/kotlin/com/panomc/platform/annotation/Endpoint.kt b/Pano/src/main/kotlin/com/panomc/platform/annotation/Endpoint.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/annotation/Endpoint.kt rename to Pano/src/main/kotlin/com/panomc/platform/annotation/Endpoint.kt diff --git a/src/main/kotlin/com/panomc/platform/annotation/Event.kt b/Pano/src/main/kotlin/com/panomc/platform/annotation/Event.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/annotation/Event.kt rename to Pano/src/main/kotlin/com/panomc/platform/annotation/Event.kt diff --git a/src/main/kotlin/com/panomc/platform/annotation/Ignore.kt b/Pano/src/main/kotlin/com/panomc/platform/annotation/Ignore.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/annotation/Ignore.kt rename to Pano/src/main/kotlin/com/panomc/platform/annotation/Ignore.kt diff --git a/src/main/kotlin/com/panomc/platform/annotation/Migration.kt b/Pano/src/main/kotlin/com/panomc/platform/annotation/Migration.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/annotation/Migration.kt rename to Pano/src/main/kotlin/com/panomc/platform/annotation/Migration.kt diff --git a/Pano/src/main/kotlin/com/panomc/platform/api/EventListener.kt b/Pano/src/main/kotlin/com/panomc/platform/api/EventListener.kt new file mode 100644 index 00000000..b6c2bf59 --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/api/EventListener.kt @@ -0,0 +1,4 @@ +package com.panomc.platform.api + +interface EventListener { +} \ No newline at end of file diff --git a/Pano/src/main/kotlin/com/panomc/platform/api/PanoEventListener.kt b/Pano/src/main/kotlin/com/panomc/platform/api/PanoEventListener.kt new file mode 100644 index 00000000..10b30f70 --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/api/PanoEventListener.kt @@ -0,0 +1,3 @@ +package com.panomc.platform.api + +interface PanoEventListener : EventListener \ No newline at end of file diff --git a/Pano/src/main/kotlin/com/panomc/platform/api/PanoPlugin.kt b/Pano/src/main/kotlin/com/panomc/platform/api/PanoPlugin.kt new file mode 100644 index 00000000..99da3e57 --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/api/PanoPlugin.kt @@ -0,0 +1,98 @@ +package com.panomc.platform.api + +import com.panomc.platform.Main +import com.panomc.platform.PluginEventManager +import com.panomc.platform.ReleaseStage +import io.vertx.core.Vertx +import kotlinx.coroutines.runBlocking +import org.pf4j.Plugin +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.support.BeanDefinitionRegistry +import org.springframework.context.annotation.AnnotationConfigApplicationContext + +abstract class PanoPlugin : Plugin() { + lateinit var pluginId: String + internal set + lateinit var vertx: Vertx + internal set + lateinit var pluginEventManager: PluginEventManager + internal set + lateinit var environmentType: Main.Companion.EnvironmentType + internal set + lateinit var releaseStage: ReleaseStage + internal set + lateinit var pluginBeanContext: AnnotationConfigApplicationContext + internal set + + internal lateinit var applicationContext: AnnotationConfigApplicationContext + + val logger: Logger = LoggerFactory.getLogger(this::class.java) + + private val registeredBeans = mutableListOf>() + + fun register(bean: Class<*>) { + if (registeredBeans.contains(bean)) { + return + } + + applicationContext.register(bean) + + registeredBeans.add(bean) + } + + fun register(eventListener: PluginEventListener) { + pluginEventManager.register(this, eventListener) + } + + fun unRegister(bean: Class<*>) { + if (!registeredBeans.contains(bean)) { + return + } + + val registry = applicationContext.beanFactory as BeanDefinitionRegistry + val beanNames = registry.beanDefinitionNames + + for (beanName in beanNames) { + if (registry.getBeanDefinition(beanName).beanClassName == bean.name) { + registry.removeBeanDefinition(beanName) + return // Stop after removing the first bean definition of the given class + } + } + + registeredBeans.remove(bean) + } + + fun unRegister(eventListener: PluginEventListener) { + pluginEventManager.unRegister(this, eventListener) + } + + @Deprecated("Use onEnable method.") + override fun start() { + runBlocking { + onEnable() + } + } + + @Deprecated("Use onDisable method.") + override fun stop() { + pluginBeanContext.close() + + val copyOfRegisteredBeans = registeredBeans.toList() + + copyOfRegisteredBeans.forEach { + unRegister(it) + } + + pluginEventManager.unregisterPlugin(this) + + runBlocking { + onDisable() + } + } + + open suspend fun onLoad() {} + + open suspend fun onEnable() {} + open suspend fun onDisable() {} +} \ No newline at end of file diff --git a/Pano/src/main/kotlin/com/panomc/platform/api/PluginEventListener.kt b/Pano/src/main/kotlin/com/panomc/platform/api/PluginEventListener.kt new file mode 100644 index 00000000..0a572531 --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/api/PluginEventListener.kt @@ -0,0 +1,4 @@ +package com.panomc.platform.api + +interface PluginEventListener : EventListener { +} \ No newline at end of file diff --git a/Pano/src/main/kotlin/com/panomc/platform/api/annotation/EventListener.kt b/Pano/src/main/kotlin/com/panomc/platform/api/annotation/EventListener.kt new file mode 100755 index 00000000..5409ca35 --- /dev/null +++ b/Pano/src/main/kotlin/com/panomc/platform/api/annotation/EventListener.kt @@ -0,0 +1,10 @@ +package com.panomc.platform.api.annotation + +import org.springframework.stereotype.Component + +@Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +@Component +annotation class EventListener( + val value: String = "" +) diff --git a/src/main/kotlin/com/panomc/platform/auth/AuthProvider.kt b/Pano/src/main/kotlin/com/panomc/platform/auth/AuthProvider.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/auth/AuthProvider.kt rename to Pano/src/main/kotlin/com/panomc/platform/auth/AuthProvider.kt diff --git a/src/main/kotlin/com/panomc/platform/auth/PanelPermission.kt b/Pano/src/main/kotlin/com/panomc/platform/auth/PanelPermission.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/auth/PanelPermission.kt rename to Pano/src/main/kotlin/com/panomc/platform/auth/PanelPermission.kt diff --git a/src/main/kotlin/com/panomc/platform/config/ConfigManager.kt b/Pano/src/main/kotlin/com/panomc/platform/config/ConfigManager.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/config/ConfigManager.kt rename to Pano/src/main/kotlin/com/panomc/platform/config/ConfigManager.kt diff --git a/src/main/kotlin/com/panomc/platform/config/ConfigMigration.kt b/Pano/src/main/kotlin/com/panomc/platform/config/ConfigMigration.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/config/ConfigMigration.kt rename to Pano/src/main/kotlin/com/panomc/platform/config/ConfigMigration.kt diff --git a/src/main/kotlin/com/panomc/platform/config/migration/.gitkeep b/Pano/src/main/kotlin/com/panomc/platform/config/migration/.gitkeep similarity index 100% rename from src/main/kotlin/com/panomc/platform/config/migration/.gitkeep rename to Pano/src/main/kotlin/com/panomc/platform/config/migration/.gitkeep diff --git a/src/main/kotlin/com/panomc/platform/db/DBEntity.kt b/Pano/src/main/kotlin/com/panomc/platform/db/DBEntity.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/DBEntity.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/DBEntity.kt diff --git a/src/main/kotlin/com/panomc/platform/db/Dao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/Dao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/Dao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/Dao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/DaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/DaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/DaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/DaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/DatabaseManager.kt b/Pano/src/main/kotlin/com/panomc/platform/db/DatabaseManager.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/DatabaseManager.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/DatabaseManager.kt diff --git a/src/main/kotlin/com/panomc/platform/db/DatabaseMigration.kt b/Pano/src/main/kotlin/com/panomc/platform/db/DatabaseMigration.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/DatabaseMigration.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/DatabaseMigration.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/NotificationDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/NotificationDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/NotificationDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/NotificationDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/PanelConfigDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/PanelConfigDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/PanelConfigDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/PanelConfigDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/PanelNotificationDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/PanelNotificationDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/PanelNotificationDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/PanelNotificationDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/PermissionDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/PermissionDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/PermissionDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/PermissionDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/PermissionGroupDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/PermissionGroupDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/PermissionGroupDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/PermissionGroupDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/PermissionGroupPermsDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/PermissionGroupPermsDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/PermissionGroupPermsDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/PermissionGroupPermsDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/PostCategoryDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/PostCategoryDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/PostCategoryDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/PostCategoryDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/PostDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/PostDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/PostDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/PostDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/SchemeVersionDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/SchemeVersionDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/SchemeVersionDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/SchemeVersionDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/ServerDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/ServerDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/ServerDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/ServerDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/ServerPlayerDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/ServerPlayerDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/ServerPlayerDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/ServerPlayerDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/SystemPropertyDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/SystemPropertyDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/SystemPropertyDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/SystemPropertyDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/TicketCategoryDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/TicketCategoryDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/TicketCategoryDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/TicketCategoryDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/TicketDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/TicketDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/TicketDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/TicketDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/TicketMessageDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/TicketMessageDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/TicketMessageDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/TicketMessageDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/TokenDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/TokenDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/TokenDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/TokenDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/UserDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/UserDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/UserDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/UserDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/dao/WebsiteViewDao.kt b/Pano/src/main/kotlin/com/panomc/platform/db/dao/WebsiteViewDao.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/dao/WebsiteViewDao.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/dao/WebsiteViewDao.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/NotificationDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/NotificationDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/NotificationDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/NotificationDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/PanelConfigDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/PanelConfigDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/PanelConfigDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/PanelConfigDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/PanelNotificationDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/PanelNotificationDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/PanelNotificationDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/PanelNotificationDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/PermissionDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/PermissionDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/PermissionDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/PermissionDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupPermsDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupPermsDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupPermsDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/PermissionGroupPermsDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/PostCategoryDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/PostCategoryDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/PostCategoryDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/PostCategoryDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/PostDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/PostDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/PostDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/PostDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/SchemeVersionDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/SchemeVersionDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/SchemeVersionDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/SchemeVersionDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/ServerDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/ServerDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/ServerDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/ServerDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/ServerPlayerDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/ServerPlayerDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/ServerPlayerDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/ServerPlayerDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/SystemPropertyDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/SystemPropertyDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/SystemPropertyDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/SystemPropertyDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/TicketCategoryDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/TicketCategoryDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/TicketCategoryDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/TicketCategoryDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/TicketDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/TicketDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/TicketDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/TicketDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/TicketMessageDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/TicketMessageDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/TicketMessageDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/TicketMessageDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/TokenDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/TokenDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/TokenDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/TokenDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/UserDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/UserDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/UserDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/UserDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/implementation/WebsiteViewDaoImpl.kt b/Pano/src/main/kotlin/com/panomc/platform/db/implementation/WebsiteViewDaoImpl.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/implementation/WebsiteViewDaoImpl.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/implementation/WebsiteViewDaoImpl.kt diff --git a/src/main/kotlin/com/panomc/platform/db/migration/.gitkeep b/Pano/src/main/kotlin/com/panomc/platform/db/migration/.gitkeep similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/migration/.gitkeep rename to Pano/src/main/kotlin/com/panomc/platform/db/migration/.gitkeep diff --git a/src/main/kotlin/com/panomc/platform/db/model/Notification.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/Notification.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/Notification.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/Notification.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/PanelConfig.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/PanelConfig.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/PanelConfig.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/PanelConfig.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/PanelNotification.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/PanelNotification.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/PanelNotification.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/PanelNotification.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/Permission.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/Permission.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/Permission.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/Permission.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/PermissionGroup.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/PermissionGroup.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/PermissionGroup.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/PermissionGroup.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/PermissionGroupPerms.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/PermissionGroupPerms.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/PermissionGroupPerms.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/PermissionGroupPerms.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/Post.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/Post.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/Post.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/Post.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/PostCategory.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/PostCategory.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/PostCategory.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/PostCategory.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/SchemeVersion.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/SchemeVersion.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/SchemeVersion.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/SchemeVersion.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/Server.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/Server.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/Server.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/Server.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/ServerPlayer.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/ServerPlayer.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/ServerPlayer.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/ServerPlayer.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/SystemProperty.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/SystemProperty.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/SystemProperty.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/SystemProperty.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/Ticket.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/Ticket.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/Ticket.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/Ticket.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/TicketCategory.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/TicketCategory.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/TicketCategory.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/TicketCategory.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/TicketMessage.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/TicketMessage.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/TicketMessage.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/TicketMessage.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/Token.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/Token.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/Token.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/Token.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/User.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/User.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/User.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/User.kt diff --git a/src/main/kotlin/com/panomc/platform/db/model/WebsiteView.kt b/Pano/src/main/kotlin/com/panomc/platform/db/model/WebsiteView.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/db/model/WebsiteView.kt rename to Pano/src/main/kotlin/com/panomc/platform/db/model/WebsiteView.kt diff --git a/src/main/kotlin/com/panomc/platform/error/AlreadyBanned.kt b/Pano/src/main/kotlin/com/panomc/platform/error/AlreadyBanned.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/AlreadyBanned.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/AlreadyBanned.kt diff --git a/src/main/kotlin/com/panomc/platform/error/BadRequest.kt b/Pano/src/main/kotlin/com/panomc/platform/error/BadRequest.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/BadRequest.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/BadRequest.kt diff --git a/src/main/kotlin/com/panomc/platform/error/CantBanYourself.kt b/Pano/src/main/kotlin/com/panomc/platform/error/CantBanYourself.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/CantBanYourself.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/CantBanYourself.kt diff --git a/src/main/kotlin/com/panomc/platform/error/CantChangeEmailWait15Minutes.kt b/Pano/src/main/kotlin/com/panomc/platform/error/CantChangeEmailWait15Minutes.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/CantChangeEmailWait15Minutes.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/CantChangeEmailWait15Minutes.kt diff --git a/src/main/kotlin/com/panomc/platform/error/CantDeleteAdminPermission.kt b/Pano/src/main/kotlin/com/panomc/platform/error/CantDeleteAdminPermission.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/CantDeleteAdminPermission.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/CantDeleteAdminPermission.kt diff --git a/src/main/kotlin/com/panomc/platform/error/CantDeleteYourself.kt b/Pano/src/main/kotlin/com/panomc/platform/error/CantDeleteYourself.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/CantDeleteYourself.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/CantDeleteYourself.kt diff --git a/src/main/kotlin/com/panomc/platform/error/CantResetPasswordWait15Minutes.kt b/Pano/src/main/kotlin/com/panomc/platform/error/CantResetPasswordWait15Minutes.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/CantResetPasswordWait15Minutes.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/CantResetPasswordWait15Minutes.kt diff --git a/src/main/kotlin/com/panomc/platform/error/CantUpdateAdminPermission.kt b/Pano/src/main/kotlin/com/panomc/platform/error/CantUpdateAdminPermission.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/CantUpdateAdminPermission.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/CantUpdateAdminPermission.kt diff --git a/src/main/kotlin/com/panomc/platform/error/CantUpdatePermGroupYourself.kt b/Pano/src/main/kotlin/com/panomc/platform/error/CantUpdatePermGroupYourself.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/CantUpdatePermGroupYourself.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/CantUpdatePermGroupYourself.kt diff --git a/src/main/kotlin/com/panomc/platform/error/CategoryNotExists.kt b/Pano/src/main/kotlin/com/panomc/platform/error/CategoryNotExists.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/CategoryNotExists.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/CategoryNotExists.kt diff --git a/src/main/kotlin/com/panomc/platform/error/CurrentPasswordNotCorrect.kt b/Pano/src/main/kotlin/com/panomc/platform/error/CurrentPasswordNotCorrect.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/CurrentPasswordNotCorrect.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/CurrentPasswordNotCorrect.kt diff --git a/src/main/kotlin/com/panomc/platform/error/EmailAlreadyVerified.kt b/Pano/src/main/kotlin/com/panomc/platform/error/EmailAlreadyVerified.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/EmailAlreadyVerified.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/EmailAlreadyVerified.kt diff --git a/src/main/kotlin/com/panomc/platform/error/FaviconExceedsSize.kt b/Pano/src/main/kotlin/com/panomc/platform/error/FaviconExceedsSize.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/FaviconExceedsSize.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/FaviconExceedsSize.kt diff --git a/src/main/kotlin/com/panomc/platform/error/FaviconWrongContentType.kt b/Pano/src/main/kotlin/com/panomc/platform/error/FaviconWrongContentType.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/FaviconWrongContentType.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/FaviconWrongContentType.kt diff --git a/src/main/kotlin/com/panomc/platform/error/InstallationRequired.kt b/Pano/src/main/kotlin/com/panomc/platform/error/InstallationRequired.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/InstallationRequired.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/InstallationRequired.kt diff --git a/src/main/kotlin/com/panomc/platform/error/InternalServerError.kt b/Pano/src/main/kotlin/com/panomc/platform/error/InternalServerError.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/InternalServerError.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/InternalServerError.kt diff --git a/src/main/kotlin/com/panomc/platform/error/InvalidData.kt b/Pano/src/main/kotlin/com/panomc/platform/error/InvalidData.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/InvalidData.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/InvalidData.kt diff --git a/src/main/kotlin/com/panomc/platform/error/InvalidEmail.kt b/Pano/src/main/kotlin/com/panomc/platform/error/InvalidEmail.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/InvalidEmail.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/InvalidEmail.kt diff --git a/src/main/kotlin/com/panomc/platform/error/InvalidIpAddress.kt b/Pano/src/main/kotlin/com/panomc/platform/error/InvalidIpAddress.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/InvalidIpAddress.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/InvalidIpAddress.kt diff --git a/src/main/kotlin/com/panomc/platform/error/InvalidLink.kt b/Pano/src/main/kotlin/com/panomc/platform/error/InvalidLink.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/InvalidLink.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/InvalidLink.kt diff --git a/src/main/kotlin/com/panomc/platform/error/InvalidPlatformCode.kt b/Pano/src/main/kotlin/com/panomc/platform/error/InvalidPlatformCode.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/InvalidPlatformCode.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/InvalidPlatformCode.kt diff --git a/src/main/kotlin/com/panomc/platform/error/InvalidToken.kt b/Pano/src/main/kotlin/com/panomc/platform/error/InvalidToken.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/InvalidToken.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/InvalidToken.kt diff --git a/src/main/kotlin/com/panomc/platform/error/LastAdmin.kt b/Pano/src/main/kotlin/com/panomc/platform/error/LastAdmin.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/LastAdmin.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/LastAdmin.kt diff --git a/src/main/kotlin/com/panomc/platform/error/LoginEmailNotVerified.kt b/Pano/src/main/kotlin/com/panomc/platform/error/LoginEmailNotVerified.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/LoginEmailNotVerified.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/LoginEmailNotVerified.kt diff --git a/src/main/kotlin/com/panomc/platform/error/LoginIsInvalid.kt b/Pano/src/main/kotlin/com/panomc/platform/error/LoginIsInvalid.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/LoginIsInvalid.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/LoginIsInvalid.kt diff --git a/src/main/kotlin/com/panomc/platform/error/LoginUserIsBanned.kt b/Pano/src/main/kotlin/com/panomc/platform/error/LoginUserIsBanned.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/LoginUserIsBanned.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/LoginUserIsBanned.kt diff --git a/src/main/kotlin/com/panomc/platform/error/MessageCantBeEmpty.kt b/Pano/src/main/kotlin/com/panomc/platform/error/MessageCantBeEmpty.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/MessageCantBeEmpty.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/MessageCantBeEmpty.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NeedPermission.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NeedPermission.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NeedPermission.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NeedPermission.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NewEmailExists.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NewEmailExists.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NewEmailExists.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NewEmailExists.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NewPasswordEmpty.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NewPasswordEmpty.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NewPasswordEmpty.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NewPasswordEmpty.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NewPasswordRepeatDoesntMatch.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NewPasswordRepeatDoesntMatch.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NewPasswordRepeatDoesntMatch.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NewPasswordRepeatDoesntMatch.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NewPasswordTooLong.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NewPasswordTooLong.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NewPasswordTooLong.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NewPasswordTooLong.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NewPasswordTooShort.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NewPasswordTooShort.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NewPasswordTooShort.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NewPasswordTooShort.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NoPermission.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NoPermission.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NoPermission.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NoPermission.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminPermGroup.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminPermGroup.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminPermGroup.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminPermGroup.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminUser.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminUser.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminUser.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NoPermissionToUpdateAdminUser.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NotBanned.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NotBanned.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NotBanned.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NotBanned.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NotExists.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NotExists.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NotExists.kt diff --git a/src/main/kotlin/com/panomc/platform/error/NotLoggedIn.kt b/Pano/src/main/kotlin/com/panomc/platform/error/NotLoggedIn.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/NotLoggedIn.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/NotLoggedIn.kt diff --git a/src/main/kotlin/com/panomc/platform/error/PageNotFound.kt b/Pano/src/main/kotlin/com/panomc/platform/error/PageNotFound.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/PageNotFound.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/PageNotFound.kt diff --git a/src/main/kotlin/com/panomc/platform/error/PasswordEmpty.kt b/Pano/src/main/kotlin/com/panomc/platform/error/PasswordEmpty.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/PasswordEmpty.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/PasswordEmpty.kt diff --git a/src/main/kotlin/com/panomc/platform/error/PasswordTooLong.kt b/Pano/src/main/kotlin/com/panomc/platform/error/PasswordTooLong.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/PasswordTooLong.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/PasswordTooLong.kt diff --git a/src/main/kotlin/com/panomc/platform/error/PasswordTooShort.kt b/Pano/src/main/kotlin/com/panomc/platform/error/PasswordTooShort.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/PasswordTooShort.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/PasswordTooShort.kt diff --git a/src/main/kotlin/com/panomc/platform/error/PermGroupNotExists.kt b/Pano/src/main/kotlin/com/panomc/platform/error/PermGroupNotExists.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/PermGroupNotExists.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/PermGroupNotExists.kt diff --git a/src/main/kotlin/com/panomc/platform/error/PlatformAlreadyInstalled.kt b/Pano/src/main/kotlin/com/panomc/platform/error/PlatformAlreadyInstalled.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/PlatformAlreadyInstalled.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/PlatformAlreadyInstalled.kt diff --git a/src/main/kotlin/com/panomc/platform/error/PostNotFound.kt b/Pano/src/main/kotlin/com/panomc/platform/error/PostNotFound.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/PostNotFound.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/PostNotFound.kt diff --git a/src/main/kotlin/com/panomc/platform/error/PostThumbnailExceedsSize.kt b/Pano/src/main/kotlin/com/panomc/platform/error/PostThumbnailExceedsSize.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/PostThumbnailExceedsSize.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/PostThumbnailExceedsSize.kt diff --git a/src/main/kotlin/com/panomc/platform/error/PostThumbnailWrongContentType.kt b/Pano/src/main/kotlin/com/panomc/platform/error/PostThumbnailWrongContentType.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/PostThumbnailWrongContentType.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/PostThumbnailWrongContentType.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterCantVerifyRobot.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterCantVerifyRobot.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterCantVerifyRobot.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterCantVerifyRobot.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterEmailEmpty.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterEmailEmpty.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterEmailEmpty.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterEmailEmpty.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterEmailNotAvailable.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterEmailNotAvailable.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterEmailNotAvailable.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterEmailNotAvailable.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterInvalidEmail.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterInvalidEmail.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterInvalidEmail.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterInvalidEmail.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterInvalidUsername.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterInvalidUsername.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterInvalidUsername.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterInvalidUsername.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterNotAcceptedAgreement.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterNotAcceptedAgreement.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterNotAcceptedAgreement.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterNotAcceptedAgreement.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterPasswordAndPasswordRepeatNotSame.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterPasswordAndPasswordRepeatNotSame.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterPasswordAndPasswordRepeatNotSame.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterPasswordAndPasswordRepeatNotSame.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterUsernameEmpty.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterUsernameEmpty.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterUsernameEmpty.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterUsernameEmpty.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterUsernameNotAvailable.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterUsernameNotAvailable.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterUsernameNotAvailable.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterUsernameNotAvailable.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterUsernameTooLong.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterUsernameTooLong.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterUsernameTooLong.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterUsernameTooLong.kt diff --git a/src/main/kotlin/com/panomc/platform/error/RegisterUsernameTooShort.kt b/Pano/src/main/kotlin/com/panomc/platform/error/RegisterUsernameTooShort.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/RegisterUsernameTooShort.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/RegisterUsernameTooShort.kt diff --git a/src/main/kotlin/com/panomc/platform/error/SomePermissionsArentExists.kt b/Pano/src/main/kotlin/com/panomc/platform/error/SomePermissionsArentExists.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/SomePermissionsArentExists.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/SomePermissionsArentExists.kt diff --git a/src/main/kotlin/com/panomc/platform/error/SomeTicketsArentExists.kt b/Pano/src/main/kotlin/com/panomc/platform/error/SomeTicketsArentExists.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/SomeTicketsArentExists.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/SomeTicketsArentExists.kt diff --git a/src/main/kotlin/com/panomc/platform/error/SomeUsersArentExists.kt b/Pano/src/main/kotlin/com/panomc/platform/error/SomeUsersArentExists.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/SomeUsersArentExists.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/SomeUsersArentExists.kt diff --git a/src/main/kotlin/com/panomc/platform/error/TicketIsClosed.kt b/Pano/src/main/kotlin/com/panomc/platform/error/TicketIsClosed.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/TicketIsClosed.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/TicketIsClosed.kt diff --git a/src/main/kotlin/com/panomc/platform/error/TitleCantBeEmpty.kt b/Pano/src/main/kotlin/com/panomc/platform/error/TitleCantBeEmpty.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/TitleCantBeEmpty.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/TitleCantBeEmpty.kt diff --git a/src/main/kotlin/com/panomc/platform/error/WebsiteLogoExceedsSize.kt b/Pano/src/main/kotlin/com/panomc/platform/error/WebsiteLogoExceedsSize.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/WebsiteLogoExceedsSize.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/WebsiteLogoExceedsSize.kt diff --git a/src/main/kotlin/com/panomc/platform/error/WebsiteLogoWrongContentType.kt b/Pano/src/main/kotlin/com/panomc/platform/error/WebsiteLogoWrongContentType.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/error/WebsiteLogoWrongContentType.kt rename to Pano/src/main/kotlin/com/panomc/platform/error/WebsiteLogoWrongContentType.kt diff --git a/src/main/kotlin/com/panomc/platform/mail/Mail.kt b/Pano/src/main/kotlin/com/panomc/platform/mail/Mail.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/mail/Mail.kt rename to Pano/src/main/kotlin/com/panomc/platform/mail/Mail.kt diff --git a/src/main/kotlin/com/panomc/platform/mail/MailClientProvider.kt b/Pano/src/main/kotlin/com/panomc/platform/mail/MailClientProvider.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/mail/MailClientProvider.kt rename to Pano/src/main/kotlin/com/panomc/platform/mail/MailClientProvider.kt diff --git a/src/main/kotlin/com/panomc/platform/mail/MailManager.kt b/Pano/src/main/kotlin/com/panomc/platform/mail/MailManager.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/mail/MailManager.kt rename to Pano/src/main/kotlin/com/panomc/platform/mail/MailManager.kt diff --git a/src/main/kotlin/com/panomc/platform/mail/NotificationMail.kt b/Pano/src/main/kotlin/com/panomc/platform/mail/NotificationMail.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/mail/NotificationMail.kt rename to Pano/src/main/kotlin/com/panomc/platform/mail/NotificationMail.kt diff --git a/src/main/kotlin/com/panomc/platform/mail/mails/ActivationMail.kt b/Pano/src/main/kotlin/com/panomc/platform/mail/mails/ActivationMail.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/mail/mails/ActivationMail.kt rename to Pano/src/main/kotlin/com/panomc/platform/mail/mails/ActivationMail.kt diff --git a/src/main/kotlin/com/panomc/platform/mail/mails/ChangeEmailMail.kt b/Pano/src/main/kotlin/com/panomc/platform/mail/mails/ChangeEmailMail.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/mail/mails/ChangeEmailMail.kt rename to Pano/src/main/kotlin/com/panomc/platform/mail/mails/ChangeEmailMail.kt diff --git a/src/main/kotlin/com/panomc/platform/mail/mails/ResetPasswordMail.kt b/Pano/src/main/kotlin/com/panomc/platform/mail/mails/ResetPasswordMail.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/mail/mails/ResetPasswordMail.kt rename to Pano/src/main/kotlin/com/panomc/platform/mail/mails/ResetPasswordMail.kt diff --git a/src/main/kotlin/com/panomc/platform/mail/notification/BannedMail.kt b/Pano/src/main/kotlin/com/panomc/platform/mail/notification/BannedMail.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/mail/notification/BannedMail.kt rename to Pano/src/main/kotlin/com/panomc/platform/mail/notification/BannedMail.kt diff --git a/src/main/kotlin/com/panomc/platform/mail/notification/PasswordUpdatedMail.kt b/Pano/src/main/kotlin/com/panomc/platform/mail/notification/PasswordUpdatedMail.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/mail/notification/PasswordUpdatedMail.kt rename to Pano/src/main/kotlin/com/panomc/platform/mail/notification/PasswordUpdatedMail.kt diff --git a/src/main/kotlin/com/panomc/platform/model/Api.kt b/Pano/src/main/kotlin/com/panomc/platform/model/Api.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/Api.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/Api.kt diff --git a/src/main/kotlin/com/panomc/platform/model/Error.kt b/Pano/src/main/kotlin/com/panomc/platform/model/Error.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/Error.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/Error.kt diff --git a/src/main/kotlin/com/panomc/platform/model/Errors.kt b/Pano/src/main/kotlin/com/panomc/platform/model/Errors.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/Errors.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/Errors.kt diff --git a/src/main/kotlin/com/panomc/platform/model/LoggedInApi.kt b/Pano/src/main/kotlin/com/panomc/platform/model/LoggedInApi.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/LoggedInApi.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/LoggedInApi.kt diff --git a/src/main/kotlin/com/panomc/platform/model/PanelApi.kt b/Pano/src/main/kotlin/com/panomc/platform/model/PanelApi.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/PanelApi.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/PanelApi.kt diff --git a/src/main/kotlin/com/panomc/platform/model/Path.kt b/Pano/src/main/kotlin/com/panomc/platform/model/Path.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/Path.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/Path.kt diff --git a/src/main/kotlin/com/panomc/platform/model/Result.kt b/Pano/src/main/kotlin/com/panomc/platform/model/Result.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/Result.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/Result.kt diff --git a/src/main/kotlin/com/panomc/platform/model/Route.kt b/Pano/src/main/kotlin/com/panomc/platform/model/Route.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/Route.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/Route.kt diff --git a/src/main/kotlin/com/panomc/platform/model/RouteType.kt b/Pano/src/main/kotlin/com/panomc/platform/model/RouteType.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/RouteType.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/RouteType.kt diff --git a/src/main/kotlin/com/panomc/platform/model/SetupApi.kt b/Pano/src/main/kotlin/com/panomc/platform/model/SetupApi.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/SetupApi.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/SetupApi.kt diff --git a/src/main/kotlin/com/panomc/platform/model/Successful.kt b/Pano/src/main/kotlin/com/panomc/platform/model/Successful.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/Successful.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/Successful.kt diff --git a/src/main/kotlin/com/panomc/platform/model/Template.kt b/Pano/src/main/kotlin/com/panomc/platform/model/Template.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/model/Template.kt rename to Pano/src/main/kotlin/com/panomc/platform/model/Template.kt diff --git a/src/main/kotlin/com/panomc/platform/notification/NotificationManager.kt b/Pano/src/main/kotlin/com/panomc/platform/notification/NotificationManager.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/notification/NotificationManager.kt rename to Pano/src/main/kotlin/com/panomc/platform/notification/NotificationManager.kt diff --git a/src/main/kotlin/com/panomc/platform/notification/NotificationStatus.kt b/Pano/src/main/kotlin/com/panomc/platform/notification/NotificationStatus.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/notification/NotificationStatus.kt rename to Pano/src/main/kotlin/com/panomc/platform/notification/NotificationStatus.kt diff --git a/src/main/kotlin/com/panomc/platform/notification/Notifications.kt b/Pano/src/main/kotlin/com/panomc/platform/notification/Notifications.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/notification/Notifications.kt rename to Pano/src/main/kotlin/com/panomc/platform/notification/Notifications.kt diff --git a/src/main/kotlin/com/panomc/platform/route/RouterProvider.kt b/Pano/src/main/kotlin/com/panomc/platform/route/RouterProvider.kt similarity index 78% rename from src/main/kotlin/com/panomc/platform/route/RouterProvider.kt rename to Pano/src/main/kotlin/com/panomc/platform/route/RouterProvider.kt index c5f7a532..a292560a 100755 --- a/src/main/kotlin/com/panomc/platform/route/RouterProvider.kt +++ b/Pano/src/main/kotlin/com/panomc/platform/route/RouterProvider.kt @@ -1,6 +1,8 @@ package com.panomc.platform.route +import com.panomc.platform.PluginManager import com.panomc.platform.annotation.Endpoint +import com.panomc.platform.api.PanoPlugin import com.panomc.platform.config.ConfigManager import com.panomc.platform.model.Route import com.panomc.platform.model.RouteType @@ -13,6 +15,7 @@ import io.vertx.ext.web.Router import io.vertx.ext.web.handler.BodyHandler import io.vertx.ext.web.handler.CorsHandler import io.vertx.json.schema.SchemaParser +import org.pf4j.PluginWrapper import org.springframework.context.annotation.AnnotationConfigApplicationContext class RouterProvider private constructor( @@ -21,7 +24,8 @@ class RouterProvider private constructor( schemaParser: SchemaParser, configManager: ConfigManager, httpClient: HttpClient, - setupManager: SetupManager + setupManager: SetupManager, + pluginManager: PluginManager ) { companion object { fun create( @@ -30,9 +34,18 @@ class RouterProvider private constructor( schemaParser: SchemaParser, configManager: ConfigManager, httpClient: HttpClient, - setupManager: SetupManager + setupManager: SetupManager, + pluginManager: PluginManager ) = - RouterProvider(vertx, applicationContext, schemaParser, configManager, httpClient, setupManager) + RouterProvider( + vertx, + applicationContext, + schemaParser, + configManager, + httpClient, + setupManager, + pluginManager + ) private var isInitialized = false @@ -63,9 +76,14 @@ class RouterProvider private constructor( ) init { - val beans = applicationContext.getBeansWithAnnotation(Endpoint::class.java) + val routeList = mutableListOf() - val routeList = beans.map { it.value as Route } + routeList.addAll(applicationContext.getBeansWithAnnotation(Endpoint::class.java).map { it.value as Route }) + routeList.addAll(pluginManager.plugins.map { + ((it as PluginWrapper).plugin as PanoPlugin).pluginBeanContext.getBeansWithAnnotation( + Endpoint::class.java + ) + }.flatMap { it.values }.map { it as Route }) router.route() .handler( diff --git a/src/main/kotlin/com/panomc/platform/server/PlatformCodeManager.kt b/Pano/src/main/kotlin/com/panomc/platform/server/PlatformCodeManager.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/PlatformCodeManager.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/PlatformCodeManager.kt diff --git a/src/main/kotlin/com/panomc/platform/server/ServerAuthProvider.kt b/Pano/src/main/kotlin/com/panomc/platform/server/ServerAuthProvider.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/ServerAuthProvider.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/ServerAuthProvider.kt diff --git a/src/main/kotlin/com/panomc/platform/server/ServerEvent.kt b/Pano/src/main/kotlin/com/panomc/platform/server/ServerEvent.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/ServerEvent.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/ServerEvent.kt diff --git a/src/main/kotlin/com/panomc/platform/server/ServerEventListener.kt b/Pano/src/main/kotlin/com/panomc/platform/server/ServerEventListener.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/ServerEventListener.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/ServerEventListener.kt diff --git a/src/main/kotlin/com/panomc/platform/server/ServerManager.kt b/Pano/src/main/kotlin/com/panomc/platform/server/ServerManager.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/ServerManager.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/ServerManager.kt diff --git a/src/main/kotlin/com/panomc/platform/server/ServerStatus.kt b/Pano/src/main/kotlin/com/panomc/platform/server/ServerStatus.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/ServerStatus.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/ServerStatus.kt diff --git a/src/main/kotlin/com/panomc/platform/server/ServerType.kt b/Pano/src/main/kotlin/com/panomc/platform/server/ServerType.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/ServerType.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/ServerType.kt diff --git a/src/main/kotlin/com/panomc/platform/server/event/OnPlayerDisconnect.kt b/Pano/src/main/kotlin/com/panomc/platform/server/event/OnPlayerDisconnect.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/event/OnPlayerDisconnect.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/event/OnPlayerDisconnect.kt diff --git a/src/main/kotlin/com/panomc/platform/server/event/OnPlayerJoin.kt b/Pano/src/main/kotlin/com/panomc/platform/server/event/OnPlayerJoin.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/event/OnPlayerJoin.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/event/OnPlayerJoin.kt diff --git a/src/main/kotlin/com/panomc/platform/server/event/OnServerConnect.kt b/Pano/src/main/kotlin/com/panomc/platform/server/event/OnServerConnect.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/server/event/OnServerConnect.kt rename to Pano/src/main/kotlin/com/panomc/platform/server/event/OnServerConnect.kt diff --git a/src/main/kotlin/com/panomc/platform/setup/SetupManager.kt b/Pano/src/main/kotlin/com/panomc/platform/setup/SetupManager.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/setup/SetupManager.kt rename to Pano/src/main/kotlin/com/panomc/platform/setup/SetupManager.kt diff --git a/src/main/kotlin/com/panomc/platform/token/TokenProvider.kt b/Pano/src/main/kotlin/com/panomc/platform/token/TokenProvider.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/token/TokenProvider.kt rename to Pano/src/main/kotlin/com/panomc/platform/token/TokenProvider.kt diff --git a/src/main/kotlin/com/panomc/platform/token/TokenType.kt b/Pano/src/main/kotlin/com/panomc/platform/token/TokenType.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/token/TokenType.kt rename to Pano/src/main/kotlin/com/panomc/platform/token/TokenType.kt diff --git a/src/main/kotlin/com/panomc/platform/util/CSRFTokenGenerator.kt b/Pano/src/main/kotlin/com/panomc/platform/util/CSRFTokenGenerator.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/CSRFTokenGenerator.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/CSRFTokenGenerator.kt diff --git a/src/main/kotlin/com/panomc/platform/util/DashboardPeriodType.kt b/Pano/src/main/kotlin/com/panomc/platform/util/DashboardPeriodType.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/DashboardPeriodType.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/DashboardPeriodType.kt diff --git a/src/main/kotlin/com/panomc/platform/util/DateUtil.kt b/Pano/src/main/kotlin/com/panomc/platform/util/DateUtil.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/DateUtil.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/DateUtil.kt diff --git a/src/main/kotlin/com/panomc/platform/util/FileUploadUtil.kt b/Pano/src/main/kotlin/com/panomc/platform/util/FileUploadUtil.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/FileUploadUtil.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/FileUploadUtil.kt diff --git a/src/main/kotlin/com/panomc/platform/util/KeyGeneratorUtil.kt b/Pano/src/main/kotlin/com/panomc/platform/util/KeyGeneratorUtil.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/KeyGeneratorUtil.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/KeyGeneratorUtil.kt diff --git a/src/main/kotlin/com/panomc/platform/util/PlayerStatus.kt b/Pano/src/main/kotlin/com/panomc/platform/util/PlayerStatus.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/PlayerStatus.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/PlayerStatus.kt diff --git a/src/main/kotlin/com/panomc/platform/util/PostStatus.kt b/Pano/src/main/kotlin/com/panomc/platform/util/PostStatus.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/PostStatus.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/PostStatus.kt diff --git a/src/main/kotlin/com/panomc/platform/util/Regexes.kt b/Pano/src/main/kotlin/com/panomc/platform/util/Regexes.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/Regexes.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/Regexes.kt diff --git a/src/main/kotlin/com/panomc/platform/util/RegisterUtil.kt b/Pano/src/main/kotlin/com/panomc/platform/util/RegisterUtil.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/RegisterUtil.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/RegisterUtil.kt diff --git a/src/main/kotlin/com/panomc/platform/util/TextUtil.kt b/Pano/src/main/kotlin/com/panomc/platform/util/TextUtil.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/TextUtil.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/TextUtil.kt diff --git a/src/main/kotlin/com/panomc/platform/util/TicketPageType.kt b/Pano/src/main/kotlin/com/panomc/platform/util/TicketPageType.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/TicketPageType.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/TicketPageType.kt diff --git a/src/main/kotlin/com/panomc/platform/util/TicketStatus.kt b/Pano/src/main/kotlin/com/panomc/platform/util/TicketStatus.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/TicketStatus.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/TicketStatus.kt diff --git a/src/main/kotlin/com/panomc/platform/util/TimeUtil.kt b/Pano/src/main/kotlin/com/panomc/platform/util/TimeUtil.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/TimeUtil.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/TimeUtil.kt diff --git a/src/main/kotlin/com/panomc/platform/util/UIHelper.kt b/Pano/src/main/kotlin/com/panomc/platform/util/UIHelper.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/UIHelper.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/UIHelper.kt diff --git a/src/main/kotlin/com/panomc/platform/util/UpdatePeriod.kt b/Pano/src/main/kotlin/com/panomc/platform/util/UpdatePeriod.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/UpdatePeriod.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/UpdatePeriod.kt diff --git a/src/main/kotlin/com/panomc/platform/util/deserializer/BooleanDeserializer.kt b/Pano/src/main/kotlin/com/panomc/platform/util/deserializer/BooleanDeserializer.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/deserializer/BooleanDeserializer.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/deserializer/BooleanDeserializer.kt diff --git a/src/main/kotlin/com/panomc/platform/util/deserializer/JsonObjectDeserializer.kt b/Pano/src/main/kotlin/com/panomc/platform/util/deserializer/JsonObjectDeserializer.kt similarity index 100% rename from src/main/kotlin/com/panomc/platform/util/deserializer/JsonObjectDeserializer.kt rename to Pano/src/main/kotlin/com/panomc/platform/util/deserializer/JsonObjectDeserializer.kt diff --git a/src/main/resources/assets/img/minecraft-icon.png b/Pano/src/main/resources/assets/img/minecraft-icon.png similarity index 100% rename from src/main/resources/assets/img/minecraft-icon.png rename to Pano/src/main/resources/assets/img/minecraft-icon.png diff --git a/src/main/resources/assets/img/minecraft-logo.png b/Pano/src/main/resources/assets/img/minecraft-logo.png similarity index 100% rename from src/main/resources/assets/img/minecraft-logo.png rename to Pano/src/main/resources/assets/img/minecraft-logo.png diff --git a/src/main/resources/log4j2.properties b/Pano/src/main/resources/log4j2.properties similarity index 94% rename from src/main/resources/log4j2.properties rename to Pano/src/main/resources/log4j2.properties index e35d7bc9..c2d2eed9 100644 --- a/src/main/resources/log4j2.properties +++ b/Pano/src/main/resources/log4j2.properties @@ -7,7 +7,7 @@ name=Pano appender.console.type=Console appender.console.name=consoleLogger appender.console.layout.type=PatternLayout -appender.console.layout.pattern=[%d %highlight{${LOG_LEVEL_PATTERN:-%p}}{ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue}]: %c{1} - %m%n +appender.console.layout.pattern=[%d %highlight{${LOG_LEVEL_PATTERN:-%p}}{ERROR=red, WARN=yellow bold, INFO=green, DEBUG=green bold, TRACE=blue}]: [%c{1}] - %m%n # Root logger level rootLogger.level=info # Root logger referring to console appender diff --git a/src/main/resources/mail/activation.hbs b/Pano/src/main/resources/mail/activation.hbs similarity index 100% rename from src/main/resources/mail/activation.hbs rename to Pano/src/main/resources/mail/activation.hbs diff --git a/src/main/resources/mail/change-email.hbs b/Pano/src/main/resources/mail/change-email.hbs similarity index 100% rename from src/main/resources/mail/change-email.hbs rename to Pano/src/main/resources/mail/change-email.hbs diff --git a/src/main/resources/mail/notification/banned.hbs b/Pano/src/main/resources/mail/notification/banned.hbs similarity index 100% rename from src/main/resources/mail/notification/banned.hbs rename to Pano/src/main/resources/mail/notification/banned.hbs diff --git a/src/main/resources/mail/notification/password-updated.hbs b/Pano/src/main/resources/mail/notification/password-updated.hbs similarity index 100% rename from src/main/resources/mail/notification/password-updated.hbs rename to Pano/src/main/resources/mail/notification/password-updated.hbs diff --git a/src/main/resources/mail/reset-password.hbs b/Pano/src/main/resources/mail/reset-password.hbs similarity index 100% rename from src/main/resources/mail/reset-password.hbs rename to Pano/src/main/resources/mail/reset-password.hbs diff --git a/src/test/java/.gitkeep b/Pano/src/test/java/.gitkeep similarity index 100% rename from src/test/java/.gitkeep rename to Pano/src/test/java/.gitkeep diff --git a/src/test/kotlin/.gitkeep b/Pano/src/test/kotlin/.gitkeep similarity index 100% rename from src/test/kotlin/.gitkeep rename to Pano/src/test/kotlin/.gitkeep diff --git a/src/test/resources/.gitkeep b/Pano/src/test/resources/.gitkeep similarity index 100% rename from src/test/resources/.gitkeep rename to Pano/src/test/resources/.gitkeep diff --git a/build.gradle.kts b/build.gradle.kts index b2dca07f..e9a6c452 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,151 +1,44 @@ -val vertxVersion = "4.5.3" -val log4jVersion = "2.21.1" +val pluginsDir by extra { file("${layout.buildDirectory.get()}/plugins") } + +buildscript { + repositories { + mavenCentral() + jcenter() + } +} plugins { kotlin("jvm") version "1.9.20" kotlin("kapt") version "1.9.20" - id("com.github.johnrengelman.shadow") version "8.1.1" application - `maven-publish` -} - -group = "com.panomc" -version = - (if (project.hasProperty("version") && project.findProperty("version") != "unspecified") project.findProperty("version") else "local-build")!! - -val buildType = project.findProperty("buildType") as String? ?: "alpha" -val timeStamp: String by project -val buildDir by extra { file("${rootProject.layout.buildDirectory.get()}/libs") } - -repositories { - mavenCentral() - maven("https://oss.sonatype.org/content/repositories/iovertx-3720/") - maven("https://jitpack.io") -} - -dependencies { - implementation(kotlin("stdlib-jdk8")) - implementation(kotlin("reflect")) - - testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0") - testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0") - testImplementation("io.vertx:vertx-unit:$vertxVersion") - - implementation("io.vertx:vertx-web:$vertxVersion") - implementation("io.vertx:vertx-web-client:$vertxVersion") - implementation("io.vertx:vertx-mysql-client:$vertxVersion") - implementation("io.vertx:vertx-mail-client:$vertxVersion") - implementation("io.vertx:vertx-lang-kotlin:$vertxVersion") - implementation("io.vertx:vertx-web-templ-handlebars:$vertxVersion") - implementation("io.vertx:vertx-config:$vertxVersion") - implementation("io.vertx:vertx-config-hocon:$vertxVersion") - implementation("io.vertx:vertx-lang-kotlin-coroutines:$vertxVersion") - implementation("io.vertx:vertx-web-validation:$vertxVersion") - implementation("io.vertx:vertx-json-schema:$vertxVersion") - implementation("io.vertx:vertx-web-proxy:$vertxVersion") - - // https://mvnrepository.com/artifact/com.auth0/java-jwt - implementation("com.auth0:java-jwt:4.4.0") - - - implementation(group = "org.apache.logging.log4j", name = "log4j-api", version = log4jVersion) - implementation(group = "org.apache.logging.log4j", name = "log4j-core", version = log4jVersion) - implementation(group = "org.apache.logging.log4j", name = "log4j-slf4j2-impl", version = log4jVersion) - - // recaptcha v2 1.0.4 - implementation("com.github.triologygmbh:reCAPTCHA-V2-java:1.0.4") - - // https://mvnrepository.com/artifact/commons-codec/commons-codec - implementation(group = "commons-codec", name = "commons-codec", version = "1.16.1") - - // https://mvnrepository.com/artifact/org.springframework/spring-context - implementation("org.springframework:spring-context:5.3.32") - - // https://mvnrepository.com/artifact/com.google.code.gson/gson - implementation("com.google.code.gson:gson:2.10.1") } -tasks.named("jar").configure { - enabled = false +allprojects { + repositories { + mavenCentral() + } } tasks { - register("copyJar") { - dependsOn(shadowJar) - + named("run") { + enabled = false + mustRunAfter(":plugins:build") doLast { - if (shadowJar.get().archiveFile.get().asFile.parentFile.absolutePath != buildDir.absolutePath) { - copy { - from(shadowJar.get().archiveFile.get().asFile.absolutePath) - into(buildDir) - } - } + dependsOn(":Pano:run") } } build { - dependsOn("copyJar") + dependsOn(":plugins:build") + dependsOn(":Pano:build") } - register("buildDev") { - dependsOn("build") + clean { + dependsOn(":Pano:clean") + dependsOn(":plugins:clean") } - shadowJar { - dependsOn(distTar, distZip) - - manifest { - val attrMap = mutableMapOf() - - if (project.gradle.startParameter.taskNames.contains("buildDev")) - attrMap["MODE"] = "DEVELOPMENT" - - attrMap["VERSION"] = version.toString() - attrMap["BUILD_TYPE"] = buildType - - attributes(attrMap) - } - - archiveFileName.set("${rootProject.name}-${version}.jar") - - if (project.gradle.startParameter.taskNames.contains("publish")) { - archiveFileName.set(archiveFileName.get().lowercase()) - } - } -} - -tasks.withType { - kotlinOptions.jvmTarget = "1.8" -} - -tasks.named("run") { - environment("EnvironmentType", "DEVELOPMENT") - environment("PanoVersion", version) - environment("PanoBuildType", buildType) -} - -application { - mainClass.set("com.panomc.platform.Main") -} - -publishing { - repositories { - maven { - name = "Pano" - url = uri("https://maven.pkg.github.com/panocms/pano") - credentials { - username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME_GITHUB") - password = project.findProperty("gpr.token") as String? ?: System.getenv("TOKEN_GITHUB") - } - } - } - - publications { - create("shadow") { - project.extensions.configure { - artifactId = "core" - component(this@create) - } - } + jar { + enabled = false } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 29e08e8c..58a8c327 100755 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1,7 @@ -kotlin.code.style=official \ No newline at end of file +kotlin.code.style=official +org.gradle.parallel=true +org.gradle.caching=true +pf4jVersion=3.10.0 +vertxVersion=4.5.4 +gsonVersion=2.10.1 +bootstrap=true \ No newline at end of file diff --git a/plugins/build.gradle.kts b/plugins/build.gradle.kts new file mode 100644 index 00000000..ce936800 --- /dev/null +++ b/plugins/build.gradle.kts @@ -0,0 +1,36 @@ +import org.jetbrains.kotlin.incremental.createDirectory + +plugins { + kotlin("jvm") +} + +val pluginsDir: File? by rootProject.extra + +tasks.register("copyJars") { + pluginsDir?.let { + doLast { + if (!it.exists()) { + it.createDirectory() + } + + file(System.getProperty("user.dir") + "/plugins") + .listFiles() + ?.filter { file -> file.isFile && file.extension.equals("jar", ignoreCase = true) } + ?.forEach { file -> + val destinationFile = File(it, file.name) + file.copyTo(destinationFile, overwrite = true) + } + } + } +} + +tasks { + build { + dependsOn("copyJars") + dependsOn(subprojects.map { it.tasks.build }) + } + + clean { + dependsOn(subprojects.map { it.tasks.named("clean") }) + } +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index 3293f3b4..db7b89b4 100755 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,2 +1,12 @@ rootProject.name = "Pano" + +include(":Pano") +include("plugins") + +// Include all subprojects under the plugins/ folder +File("plugins").listFiles()?.filter { + it.isDirectory && (File(it, "build.gradle.kts").exists() || File(it, "build.gradle").exists()) +}?.forEach { subproject -> + include("plugins:" + subproject.name) +} diff --git a/src/main/kotlin/com/panomc/platform/route/api/GetFaviconAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/GetFaviconAPI.kt deleted file mode 100644 index d9aace5f..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/GetFaviconAPI.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.panomc.platform.route.api - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.model.Api -import com.panomc.platform.model.Path -import com.panomc.platform.model.Result -import com.panomc.platform.model.RouteType -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser -import java.io.File - -@Endpoint -class GetFaviconAPI(private val configManager: ConfigManager) : Api() { - override val paths = listOf(Path("/api/favicon", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result? { - val faviconPath = configManager.getConfig().getJsonObject("file-paths").getString("favicon") - - if (faviconPath == null) { - sendDefault(context) - - return null - } - - val path = configManager.getConfig().getString("file-uploads-folder") + File.separator + - faviconPath - - val file = File(path) - - if (!file.exists()) { - sendDefault(context) - - return null - } - - context.response().sendFile(path) - - return null - } - - private fun sendDefault(context: RoutingContext) { - context.response().sendFile("assets/img/minecraft-icon.png") - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/GetPostThumbnailAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/GetPostThumbnailAPI.kt deleted file mode 100644 index 1fdf9e49..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/GetPostThumbnailAPI.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.panomc.platform.route.api - -import com.panomc.platform.AppConstants -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.model.Api -import com.panomc.platform.model.Path -import com.panomc.platform.model.Result -import com.panomc.platform.model.RouteType -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.stringSchema -import java.io.File - -@Endpoint -class GetPostThumbnailAPI(private val configManager: ConfigManager) : Api() { - override val paths = listOf(Path("/api/post/thumbnail/:filename", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("filename", stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result? { - val parameters = getParameters(context) - - val filename = parameters.pathParameter("filename").string - - val path = configManager.getConfig() - .getString("file-uploads-folder") + "/${AppConstants.DEFAULT_POST_THUMBNAIL_UPLOAD_PATH}/" + - filename - - val file = File(path) - - if (!file.exists()) { - context.response().setStatusCode(404).end() - - return null - } - - context.response().sendFile(path) - - return null - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt deleted file mode 100644 index 8dfe5c6d..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/GetSiteInfoAPI.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.panomc.platform.route.api - -import com.panomc.platform.Main.Companion.VERSION -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class GetSiteInfoAPI(private val configManager: ConfigManager) : Api() { - override val paths = listOf(Path("/api/siteInfo", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val response = mutableMapOf() - val config = configManager.getConfig() - - response["locale"] = config.getString("locale") - response["websiteName"] = config.getString("website-name") - response["websiteDescription"] = config.getString("website-description") - response["keywords"] = config.getJsonArray("keywords") - response["panoVersion"] = VERSION - - return Successful(response) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/GetWebsiteLogoAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/GetWebsiteLogoAPI.kt deleted file mode 100644 index 1a46695c..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/GetWebsiteLogoAPI.kt +++ /dev/null @@ -1,47 +0,0 @@ -package com.panomc.platform.route.api - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.model.Api -import com.panomc.platform.model.Path -import com.panomc.platform.model.Result -import com.panomc.platform.model.RouteType -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser -import java.io.File - -@Endpoint -class GetWebsiteLogoAPI(private val configManager: ConfigManager) : Api() { - override val paths = listOf(Path("/api/websiteLogo", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result? { - val websiteLogoPath = configManager.getConfig().getJsonObject("file-paths").getString("websiteLogo") - - if (websiteLogoPath == null) { - sendDefault(context) - - return null - } - - val path = configManager.getConfig().getString("file-uploads-folder") + File.separator + - websiteLogoPath - - val file = File(path) - - if (!file.exists()) { - sendDefault(context) - - return null - } - - context.response().sendFile(path) - - return null - } - - private fun sendDefault(context: RoutingContext) { - context.response().sendFile("assets/img/minecraft-logo.png") - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/TestAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/TestAPI.kt deleted file mode 100644 index db54ff88..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/TestAPI.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.panomc.platform.route.api - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class TestAPI : Api() { - override val paths = listOf(Path("/test", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result? { - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/VisitorVisitAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/VisitorVisitAPI.kt deleted file mode 100644 index 63528073..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/VisitorVisitAPI.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.panomc.platform.route.api - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.WebsiteView -import com.panomc.platform.error.InvalidIpAddress -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class VisitorVisitAPI(private val databaseManager: DatabaseManager) : Api() { - override val paths = listOf(Path("/api/visitorVisit", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val ipAddress = context.request().remoteAddress().host() - - validateIpAddress(ipAddress) - - val sqlClient = getSqlClient() - - val exists = databaseManager.websiteViewDao.isIpAddressExistsByToday(ipAddress, sqlClient) - - if (exists) { - databaseManager.websiteViewDao.increaseTimesByOne(ipAddress, sqlClient) - } else { - databaseManager.websiteViewDao.add(WebsiteView(ipAddress = ipAddress), sqlClient) - } - - return Successful() - } - - private fun validateIpAddress(ipAddress: String) { - if (!ipAddress.matches(Regex("^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\\.(?!\$)|\$)){4}\$"))) { - throw InvalidIpAddress() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/auth/GetCredentialsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/auth/GetCredentialsAPI.kt deleted file mode 100755 index 7a9db4e2..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/auth/GetCredentialsAPI.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.panomc.platform.route.api.auth - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class GetCredentialsAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/auth/credentials", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val user = databaseManager.userDao.getById(userId, sqlClient)!! - - return Successful( - mapOf( - "username" to user.username, - "email" to user.email, - "panelAccess" to (user.permissionGroupId != -1L) - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/auth/LoginAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/auth/LoginAPI.kt deleted file mode 100755 index 4e007ce2..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/auth/LoginAPI.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.panomc.platform.route.api.auth - -import com.panomc.platform.AppConstants -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import com.panomc.platform.util.CSRFTokenGenerator -import io.vertx.core.http.Cookie -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class LoginAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : Api() { - override val paths = listOf(Path("/api/auth/login", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.json( - Schemas.objectSchema() - .property("usernameOrEmail", Schemas.stringSchema()) - .property("password", Schemas.stringSchema()) - .property("rememberMe", Schemas.booleanSchema()) - .property("recaptcha", Schemas.stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val usernameOrEmail = data.getString("usernameOrEmail") - val password = data.getString("password") - val rememberMe = data.getBoolean("rememberMe") - val recaptcha = data.getString("recaptcha") - - authProvider.validateInput(usernameOrEmail, password, recaptcha) - - val sqlClient = getSqlClient() - - authProvider.authenticate(usernameOrEmail, password, sqlClient) - - val token = authProvider.login(usernameOrEmail, sqlClient) - - val userId = databaseManager.userDao.getUserIdFromUsernameOrEmail(usernameOrEmail, sqlClient)!! - - databaseManager.userDao.updateLastLoginDate(userId, sqlClient) - - val csrfToken = CSRFTokenGenerator.nextToken() - - val response = context.response() - - val jwtCookie = Cookie.cookie(AppConstants.COOKIE_PREFIX + AppConstants.JWT_COOKIE_NAME, token) - val csrfTokenCookie = Cookie.cookie(AppConstants.COOKIE_PREFIX + AppConstants.CSRF_TOKEN_COOKIE_NAME, csrfToken) - - jwtCookie.path = "/" - jwtCookie.isHttpOnly = true - - csrfTokenCookie.path = "/" - csrfTokenCookie.isHttpOnly = true - - response.addCookie(jwtCookie) - response.addCookie(csrfTokenCookie) - - return Successful( - mapOf( - "CSRFToken" to csrfToken - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/auth/LogoutAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/auth/LogoutAPI.kt deleted file mode 100755 index dffd192c..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/auth/LogoutAPI.kt +++ /dev/null @@ -1,36 +0,0 @@ -package com.panomc.platform.route.api.auth - -import com.panomc.platform.AppConstants -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class LogoutAPI( - private val authProvider: AuthProvider -) : LoggedInApi() { - override val paths = listOf(Path("/api/auth/logout", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val sqlClient = getSqlClient() - - authProvider.logout(context, sqlClient) - - val response = context.response() - - response.putHeader( - "Set-Cookie", - "${AppConstants.COOKIE_PREFIX + AppConstants.JWT_COOKIE_NAME}=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT" - ) - response.putHeader( - "Set-Cookie", - "${AppConstants.COOKIE_PREFIX + AppConstants.CSRF_TOKEN_COOKIE_NAME}=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT" - ) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/auth/RegisterAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/auth/RegisterAPI.kt deleted file mode 100755 index df6e61ae..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/auth/RegisterAPI.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.panomc.platform.route.api.auth - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.mail.MailManager -import com.panomc.platform.mail.mails.ActivationMail -import com.panomc.platform.model.* -import com.panomc.platform.util.RegisterUtil -import de.triology.recaptchav2java.ReCaptcha -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class RegisterAPI( - private val reCaptcha: ReCaptcha, - private val databaseManager: DatabaseManager, - private val mailManager: MailManager -) : Api() { - override val paths = listOf(Path("/api/auth/register", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.json( - Schemas.objectSchema() - .property("username", Schemas.stringSchema()) - .property("email", Schemas.stringSchema()) - .property("password", Schemas.stringSchema()) - .property("passwordRepeat", Schemas.stringSchema()) - .property("agreement", Schemas.booleanSchema()) - .property("recaptcha", Schemas.stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val username = data.getString("username") - val email = data.getString("email") - val password = data.getString("password") - val passwordRepeat = data.getString("passwordRepeat") - val agreement = data.getBoolean("agreement") - val recaptchaToken = data.getString("recaptcha") - - val remoteIP = context.request().remoteAddress().host() - - RegisterUtil.validateForm(username, email, password, passwordRepeat, agreement, recaptchaToken, null) - - val sqlClient = getSqlClient() - - val userId = RegisterUtil.register( - databaseManager, - sqlClient, - username, - email, - password, - remoteIP, - isAdmin = false, - isSetup = false - ) - - mailManager.sendMail(sqlClient, userId, ActivationMail()) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/auth/RenewPasswordAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/auth/RenewPasswordAPI.kt deleted file mode 100644 index 8a12f5d1..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/auth/RenewPasswordAPI.kt +++ /dev/null @@ -1,93 +0,0 @@ -package com.panomc.platform.route.api.auth - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.* -import com.panomc.platform.mail.MailManager -import com.panomc.platform.mail.notification.PasswordUpdatedMail -import com.panomc.platform.model.* -import com.panomc.platform.token.TokenProvider -import com.panomc.platform.token.TokenType -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class RenewPasswordAPI( - private val mailManager: MailManager, - private val databaseManager: DatabaseManager, - private val tokenProvider: TokenProvider, - private val authProvider: AuthProvider -) : Api() { - override val paths = listOf(Path("/api/auth/renewPassword", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.json( - Schemas.objectSchema() - .property("token", Schemas.stringSchema()) - .property("newPassword", Schemas.stringSchema()) - .property("newPasswordRepeat", Schemas.stringSchema()) -// TODO: Add recaptcha - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val token = data.getString("token") - val newPassword = data.getString("newPassword") - val newPasswordRepeat = data.getString("newPasswordRepeat") - - validateInput(token, newPassword, newPasswordRepeat) - - val sqlClient = getSqlClient() - - val isTokenValid = tokenProvider.isTokenValid(token, TokenType.RESET_PASSWORD, sqlClient) - - if (!isTokenValid) { - throw InvalidLink() - } - - val userId = authProvider.getUserIdFromToken(token) - - databaseManager.userDao.setPasswordById(userId, newPassword, sqlClient) - - tokenProvider.invalidateToken(token, sqlClient) - - mailManager.sendMail(sqlClient, userId, PasswordUpdatedMail()) - - return Successful() - } - - private fun validateInput(token: String, newPassword: String, newPasswordRepeat: String) { - if (token.isBlank()) { - throw InvalidLink() - } - - if (newPassword.isBlank()) { - throw NewPasswordEmpty() - } - - if (newPassword.length < 6) { - throw NewPasswordTooShort() - } - - if (newPassword.length > 128) { - throw NewPasswordTooLong() - } - - if (newPassword != newPasswordRepeat) { - throw NewPasswordRepeatDoesntMatch() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/auth/ResetPasswordAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/auth/ResetPasswordAPI.kt deleted file mode 100644 index 2fe2fe39..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/auth/ResetPasswordAPI.kt +++ /dev/null @@ -1,71 +0,0 @@ -package com.panomc.platform.route.api.auth - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.mail.MailManager -import com.panomc.platform.mail.mails.ResetPasswordMail -import com.panomc.platform.model.* -import com.panomc.platform.util.Regexes -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class ResetPasswordAPI( - private val mailManager: MailManager, - private val databaseManager: DatabaseManager -) : Api() { - override val paths = listOf(Path("/api/auth/resetPassword", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.json( - Schemas.objectSchema() - .property("usernameOrEmail", Schemas.stringSchema()) -// TODO: Add recaptcha - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val usernameOrEmail = data.getString("usernameOrEmail") - - validateInput(usernameOrEmail) - - val sqlClient = getSqlClient() - - val exists = databaseManager.userDao.existsByUsernameOrEmail(usernameOrEmail, sqlClient) - - if (!exists) { - throw NotExists() - } - - val userId = - databaseManager.userDao.getUserIdFromUsernameOrEmail(usernameOrEmail, sqlClient) ?: throw NotExists() - - mailManager.sendMail(sqlClient, userId, ResetPasswordMail()) - - return Successful() - } - - private fun validateInput(usernameOrEmail: String) { - if (usernameOrEmail.isBlank()) { - throw NotExists() - } - - if (!usernameOrEmail.matches(Regex(Regexes.USERNAME)) && !usernameOrEmail.matches(Regex(Regexes.EMAIL))) { - throw NotExists() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/auth/VerifyEmailAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/auth/VerifyEmailAPI.kt deleted file mode 100644 index 6a9fbca2..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/auth/VerifyEmailAPI.kt +++ /dev/null @@ -1,68 +0,0 @@ -package com.panomc.platform.route.api.auth - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.InvalidLink -import com.panomc.platform.model.* -import com.panomc.platform.token.TokenProvider -import com.panomc.platform.token.TokenType -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class VerifyEmailAPI( - private val databaseManager: DatabaseManager, - private val tokenProvider: TokenProvider, - private val authProvider: AuthProvider -) : Api() { - override val paths = listOf(Path("/api/auth/verifyEmail", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.json( - Schemas.objectSchema() - .property("token", Schemas.stringSchema()) -// TODO: Add recaptcha - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val token = data.getString("token") - - validateInput(token) - - val sqlClient = getSqlClient() - - val isValid = tokenProvider.isTokenValid(token, TokenType.ACTIVATION, sqlClient) - - if (!isValid) { - throw InvalidLink() - } - - val userId = authProvider.getUserIdFromToken(token) - - databaseManager.userDao.makeEmailVerifiedById(userId, sqlClient) - - tokenProvider.invalidateTokensBySubjectAndType(userId.toString(), TokenType.ACTIVATION, sqlClient) - - return Successful() - } - - private fun validateInput(token: String) { - if (token.isBlank()) { - throw InvalidLink() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/auth/VerifyNewEmailAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/auth/VerifyNewEmailAPI.kt deleted file mode 100644 index 90a1e4b8..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/auth/VerifyNewEmailAPI.kt +++ /dev/null @@ -1,78 +0,0 @@ -package com.panomc.platform.route.api.auth - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.InvalidLink -import com.panomc.platform.model.* -import com.panomc.platform.token.TokenProvider -import com.panomc.platform.token.TokenType -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class VerifyNewEmailAPI( - private val databaseManager: DatabaseManager, - private val tokenProvider: TokenProvider, - private val authProvider: AuthProvider -) : Api() { - override val paths = listOf(Path("/api/auth/verifyNewEmail", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.json( - Schemas.objectSchema() - .property("token", Schemas.stringSchema()) -// TODO: Add recaptcha - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val token = data.getString("token") - - validateInput(token) - - val sqlClient = getSqlClient() - - val isValid = tokenProvider.isTokenValid(token, TokenType.CHANGE_EMAIL, sqlClient) - - if (!isValid) { - throw InvalidLink() - } - - val userId = authProvider.getUserIdFromToken(token) - - tokenProvider.invalidateTokensBySubjectAndType(userId.toString(), TokenType.CHANGE_EMAIL, sqlClient) - - val pendingEmail = databaseManager.userDao.getPendingEmailById(userId, sqlClient) - - val emailExists = databaseManager.userDao.isEmailExists(pendingEmail, sqlClient) - - if (emailExists) { - throw InvalidLink() - } - - databaseManager.userDao.setEmailById(userId, pendingEmail, sqlClient) - - databaseManager.userDao.updatePendingEmailById(userId, "", sqlClient) - - return Successful() - } - - private fun validateInput(token: String) { - if (token.isBlank()) { - throw InvalidLink() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/notification/DeleteAllNotificationAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/notification/DeleteAllNotificationAPI.kt deleted file mode 100755 index 5cf27217..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/notification/DeleteAllNotificationAPI.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.panomc.platform.route.api.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class DeleteAllNotificationAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/notifications", RouteType.DELETE)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - databaseManager.notificationDao.deleteAllByUserId(userId, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/notification/DeleteNotificationAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/notification/DeleteNotificationAPI.kt deleted file mode 100755 index 93ac6e8f..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/notification/DeleteNotificationAPI.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.panomc.platform.route.api.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class DeleteNotificationAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/notifications/:id", RouteType.DELETE)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("id", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val id = parameters.pathParameter("id").long - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.notificationDao.existsById(id, sqlClient) - - if (!exists) { - return Successful() - } - - val notification = - databaseManager.notificationDao.getById(id, sqlClient)!! - - if (notification.userId != userId) { - return Successful() - } - - databaseManager.notificationDao.deleteById(notification.id, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/notification/GetMoreNotificationsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/notification/GetMoreNotificationsAPI.kt deleted file mode 100755 index 696eba35..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/notification/GetMoreNotificationsAPI.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.panomc.platform.route.api.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class GetMoreNotificationsAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/notifications/:id/more", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("id", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val lastNotificationId = parameters.pathParameter("id").long - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val notifications = - databaseManager.notificationDao.get10ByUserIdAndStartFromId(userId, lastNotificationId, sqlClient) - - databaseManager.notificationDao.markReadLast10StartFromId(userId, lastNotificationId, sqlClient) - - val notificationsDataList = mutableListOf>() - - notifications.forEach { notification -> - notificationsDataList.add( - mapOf( - "id" to notification.id, - "type" to notification.type, - "properties" to notification.properties, - "date" to notification.date, - "status" to notification.status, - "isPersonal" to (notification.userId == userId) - ) - ) - } - - return Successful( - mutableMapOf( - "notifications" to notificationsDataList, - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/notification/GetNotificationsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/notification/GetNotificationsAPI.kt deleted file mode 100755 index d45dd324..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/notification/GetNotificationsAPI.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.panomc.platform.route.api.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class GetNotificationsAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/notifications", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val count = databaseManager.notificationDao.getCountByUserId(userId, sqlClient) - - val notifications = databaseManager.notificationDao.getLast10ByUserId(userId, sqlClient) - - databaseManager.notificationDao.markReadLast10(userId, sqlClient) - - val notificationsDataList = mutableListOf>() - - notifications.forEach { notification -> - notificationsDataList.add( - mapOf( - "id" to notification.id, - "type" to notification.type, - "properties" to notification.properties, - "date" to notification.date, - "status" to notification.status, - "isPersonal" to (notification.userId == userId) - ) - ) - } - - return Successful( - mutableMapOf( - "notifications" to notificationsDataList, - "notificationCount" to count - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/notification/GetQuickNotificationsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/notification/GetQuickNotificationsAPI.kt deleted file mode 100755 index 137a3db4..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/notification/GetQuickNotificationsAPI.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.panomc.platform.route.api.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class GetQuickNotificationsAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/notifications/quick", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val notifications = databaseManager.notificationDao.getLast5ByUserId(userId, sqlClient) - - val count = databaseManager.notificationDao.getCountOfNotReadByUserId(userId, sqlClient) - - val notificationsDataList = mutableListOf>() - - notifications.forEach { notification -> - notificationsDataList.add( - mapOf( - "id" to notification.id, - "type" to notification.type, - "properties" to notification.properties, - "date" to notification.date, - "status" to notification.status, - "isPersonal" to (notification.userId == userId) - ) - ) - } - - return Successful( - mutableMapOf( - "notifications" to notificationsDataList, - "notificationCount" to count - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/notification/MarkNotificationAsReadAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/notification/MarkNotificationAsReadAPI.kt deleted file mode 100755 index b8564c97..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/notification/MarkNotificationAsReadAPI.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.panomc.platform.route.api.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class MarkNotificationAsReadAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager, -) : LoggedInApi() { - override val paths = listOf(Path("/api/notifications/:id/read", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("id", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val id = parameters.pathParameter("id").long - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.notificationDao.existsById(id, sqlClient) - - if (!exists) { - return Successful() - } - - val notification = - databaseManager.notificationDao.getById(id, sqlClient)!! - - if (notification.userId != userId) { - return Successful() - } - - databaseManager.notificationDao.markReadById(id, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/notification/MarkQuickNotificationsAsReadAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/notification/MarkQuickNotificationsAsReadAPI.kt deleted file mode 100755 index d1f37d55..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/notification/MarkQuickNotificationsAsReadAPI.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.panomc.platform.route.api.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class MarkQuickNotificationsAsReadAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/notifications/quick/markAsRead", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - databaseManager.notificationDao.markReadLast5ByUserId(userId, sqlClient) - - val count = databaseManager.notificationDao.getCountOfNotReadByUserId(userId, sqlClient) - - return Successful( - mutableMapOf( - "notificationCount" to count - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetBasicDataAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetBasicDataAPI.kt deleted file mode 100755 index fc3a3542..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetBasicDataAPI.kt +++ /dev/null @@ -1,90 +0,0 @@ -package com.panomc.platform.route.api.panel - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Permission -import com.panomc.platform.db.model.Server -import com.panomc.platform.model.* -import com.panomc.platform.server.PlatformCodeManager -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelGetBasicDataAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager, - private val platformCodeManager: PlatformCodeManager, - private val configManager: ConfigManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/basicData", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val user = databaseManager.userDao.getById( - userId, - sqlClient - )!! - - val count = databaseManager.panelNotificationDao.getCountOfNotReadByUserId(userId, sqlClient) - val connectedServerCount = databaseManager.serverDao.countOfPermissionGranted(sqlClient) - -// Since it's a panel API, it calls AuthProvider#hasAccessPanel method and these context fields are created - val isAdmin = context.get("isAdmin") ?: false - val permissions = context.get>("permissions") ?: listOf() - - val result = mutableMapOf( - "user" to mapOf( - "username" to user.username, - "email" to user.email, - "permissions" to permissions.map { it.name }, - "admin" to isAdmin - ), - "website" to mapOf( - "name" to configManager.getConfig().getString("website-name"), - "description" to configManager.getConfig().getString("website-description") - ), - "notificationCount" to count, - "locale" to configManager.getConfig().getString("locale"), - "connectedServerCount" to connectedServerCount - ) - - if (authProvider.hasPermission(userId, PanelPermission.MANAGE_SERVERS, context)) { - val mainServerId = databaseManager.systemPropertyDao.getByOption( - "main_server", - sqlClient - )?.value?.toLong() - var mainServer: Server? = null - - if (mainServerId != null && mainServerId != -1L) { - mainServer = databaseManager.serverDao.getById(mainServerId, sqlClient) - } - - val selectedServerPanelConfig = - databaseManager.panelConfigDao.byUserIdAndOption(userId, "selected_server", sqlClient) - var selectedServer: Server? = null - - if (selectedServerPanelConfig != null) { - val selectedServerId = selectedServerPanelConfig.value.toLong() - - selectedServer = databaseManager.serverDao.getById(selectedServerId, sqlClient) - } - - result["platformServerMatchKey"] = platformCodeManager.getPlatformKey() - result["platformServerMatchKeyTimeStarted"] = platformCodeManager.getTimeStarted() - result["platformHostAddress"] = context.request().host() - - result["mainServer"] = mainServer - result["selectedServer"] = selectedServer - } - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetDashboardAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetDashboardAPI.kt deleted file mode 100755 index ba45b71f..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetDashboardAPI.kt +++ /dev/null @@ -1,93 +0,0 @@ -package com.panomc.platform.route.api.panel - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission.MANAGE_TICKETS -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.TicketCategory -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelGetDashboardAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/dashboard", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val result = mutableMapOf( - "gettingStartedBlocks" to mapOf( - "welcomeBoard" to false - ), - ) - - val sqlClient = getSqlClient() - - val isUserInstalled = - databaseManager.systemPropertyDao.isUserInstalledSystemByUserId(userId, sqlClient) - - if (isUserInstalled) { - val systemProperty = databaseManager.systemPropertyDao.getByOption( - "show_getting_started", - sqlClient - )!! - - result["gettingStartedBlocks"] = mapOf( - "welcomeBoard" to systemProperty.value.toBoolean() - ) - } - - val ticketCount = databaseManager.ticketDao.count(sqlClient) - - if (authProvider.hasPermission(userId, MANAGE_TICKETS, context) && ticketCount != 0L) { - val tickets = databaseManager.ticketDao.getLast5Tickets(sqlClient) - - val userIdList = tickets.distinctBy { it.userId }.map { it.userId } - - val usernameList = databaseManager.userDao.getUsernameByListOfId(userIdList, sqlClient) - - val categoryIdList = - tickets.filter { it.categoryId != -1L }.distinctBy { it.categoryId }.map { it.categoryId } - var ticketCategoryList: Map = mapOf() - - if (categoryIdList.isNotEmpty()) { - ticketCategoryList = databaseManager.ticketCategoryDao.getByIdList(categoryIdList, sqlClient) - } - - val ticketDataList = mutableListOf>() - - tickets.forEach { ticket -> - ticketDataList.add( - mapOf( - "id" to ticket.id, - "title" to ticket.title, - "category" to - if (ticket.categoryId == -1L) - TicketCategory() - else - ticketCategoryList.getOrDefault( - ticket.categoryId, - TicketCategory() - ), - "writer" to mapOf( - "username" to usernameList[ticket.userId] - ), - "date" to ticket.date, - "lastUpdate" to ticket.lastUpdate, - "status" to ticket.status - ) - ) - } - - result["tickets"] = ticketDataList - } - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetStatisticsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetStatisticsAPI.kt deleted file mode 100755 index 660e6b54..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/PanelGetStatisticsAPI.kt +++ /dev/null @@ -1,143 +0,0 @@ -package com.panomc.platform.route.api.panel - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission.ACCESS_PANEL -import com.panomc.platform.auth.PanelPermission.MANAGE_TICKETS -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Permission -import com.panomc.platform.model.* -import com.panomc.platform.util.DashboardPeriodType -import com.panomc.platform.util.TimeUtil.toGroupGetCountAndDates -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.arraySchema -import io.vertx.json.schema.common.dsl.Schemas.enumSchema - -@Endpoint -class PanelGetStatisticsAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/statistics", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter( - param( - "period", - arraySchema() - .items(enumSchema(*DashboardPeriodType.values().map { it.period }.toTypedArray())) - ) - ) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val userId = authProvider.getUserIdFromRoutingContext(context) - - val period = DashboardPeriodType.valueOf( - period = parameters.queryParameter("period")?.jsonArray?.first() as String? ?: "week" - ) ?: DashboardPeriodType.WEEK - - val result = mutableMapOf( - "onlinePlayerCount" to 0, - "registeredPlayerCount" to 0, - "postCount" to 0, - "adminCount" to 0, - "connectedServerCount" to 0, - "newRegisterCount" to 0, - "period" to period.period, - "websiteActivityDataList" to mutableMapOf(), - "ticketCount" to 0 - ) - - val sqlClient = getSqlClient() - - result["registeredPlayerCount"] = databaseManager.userDao.count(sqlClient) - - result["onlinePlayerCount"] = databaseManager.userDao.countOfOnline(sqlClient) - - result["postCount"] = databaseManager.postDao.count(sqlClient) - - if (authProvider.hasPermission(userId, MANAGE_TICKETS, context)) { - val ticketCount = databaseManager.ticketDao.count(sqlClient) - - result["ticketCount"] = ticketCount - - if (ticketCount != 0L) { - val openTicketCount = databaseManager.ticketDao.countOfOpenTickets(sqlClient) - - result["openTicketCount"] = openTicketCount - } - } - - val permissionId = databaseManager.permissionDao.getPermissionId( - Permission(name = ACCESS_PANEL.toString(), iconName = ""), - sqlClient - ) - val permissionGroupsByPermissionId = - databaseManager.permissionGroupPermsDao.getPermissionGroupPermsByPermissionId(permissionId, sqlClient) - - var adminCount = 0L - - val permissionGroupList = permissionGroupsByPermissionId.toMutableList() - - val adminPermissionGroupId = - databaseManager.permissionGroupDao.getPermissionGroupIdByName("admin", sqlClient) - - val userCountOfAdminPermission = - databaseManager.userDao.getCountOfUsersByPermissionGroupId(adminPermissionGroupId!!, sqlClient) - - adminCount += userCountOfAdminPermission - - permissionGroupList.forEach { permissionGroupPerm -> - adminCount += databaseManager.userDao.getCountOfUsersByPermissionGroupId( - permissionGroupPerm.permissionGroupId, - sqlClient - ) - } - - result["adminCount"] = adminCount - - result["newRegisterCount"] = databaseManager.userDao.countOfRegisterByPeriod(period, sqlClient) - - val websiteActivityDataList = result["websiteActivityDataList"] as MutableMap - - val registerDateList = databaseManager.userDao.getRegisterDatesByPeriod(period, sqlClient) - websiteActivityDataList["newRegisterData"] = registerDateList.toGroupGetCountAndDates() - - val ticketsDateList = databaseManager.ticketDao.getDatesByPeriod(period, sqlClient) - websiteActivityDataList["ticketsData"] = ticketsDateList.toGroupGetCountAndDates() - - val websiteViewData = databaseManager.websiteViewDao.getWebsiteViewListByPeriod(period, sqlClient) - - val viewsDateMap = mutableMapOf() - val visitorDateMap = mutableMapOf() - - websiteViewData.forEach { viewData -> - if (viewsDateMap.containsKey(viewData.date)) { - viewsDateMap[viewData.date] = viewsDateMap[viewData.date]!!.plus(viewData.times) - } else { - viewsDateMap[viewData.date] = viewData.times - } - - if (visitorDateMap.containsKey(viewData.date)) { - visitorDateMap[viewData.date] = visitorDateMap[viewData.date]!!.plus(1) - } else { - visitorDateMap[viewData.date] = 1 - } - } - websiteActivityDataList["visitorData"] = visitorDateMap - websiteActivityDataList["viewData"] = viewsDateMap - - val connectedServerCount = databaseManager.serverDao.countOfPermissionGranted(sqlClient) - - result["connectedServerCount"] = connectedServerCount - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/PanelIsUserExistsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/PanelIsUserExistsAPI.kt deleted file mode 100644 index 594be91e..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/PanelIsUserExistsAPI.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.panomc.platform.route.api.panel - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class PanelIsUserExistsAPI( - private val databaseManager: DatabaseManager -) : - PanelApi() { - override val paths = listOf(Path("/api/panel/players/:username/exists", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("username", Schemas.stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val username = parameters.pathParameter("username").string - - val sqlClient = getSqlClient() - - val exists = databaseManager.userDao.existsByUsername(username, sqlClient) - - if (!exists) { - throw NotExists() - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/dashboard/PanelCloseConnectServerCardAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/dashboard/PanelCloseConnectServerCardAPI.kt deleted file mode 100755 index 7e1f1075..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/dashboard/PanelCloseConnectServerCardAPI.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.panomc.platform.route.api.panel.dashboard - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NoPermission -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelCloseConnectServerCardAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/dashboard/closeConnectServerCard", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val isUserInstalledSystem = - databaseManager.systemPropertyDao.isUserInstalledSystemByUserId(userId, sqlClient) - - if (!isUserInstalledSystem) { - throw NoPermission() - } - - databaseManager.systemPropertyDao.update( - "show_connect_server_info", - "false", - sqlClient - ) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/dashboard/PanelCloseGettingStartedCardAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/dashboard/PanelCloseGettingStartedCardAPI.kt deleted file mode 100755 index a1ce8c1d..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/dashboard/PanelCloseGettingStartedCardAPI.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.panomc.platform.route.api.panel.dashboard - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NoPermission -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelCloseGettingStartedCardAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/dashboard/closeGettingStartedCard", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val isUserInstalledSystem = - databaseManager.systemPropertyDao.isUserInstalledSystemByUserId(userId, sqlClient) - - if (!isUserInstalledSystem) { - throw NoPermission() - } - - databaseManager.systemPropertyDao.update( - "show_getting_started", - "false", - sqlClient - ) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelDeleteAllNotificationAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelDeleteAllNotificationAPI.kt deleted file mode 100755 index 9897197a..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelDeleteAllNotificationAPI.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.panomc.platform.route.api.panel.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelDeleteAllNotificationAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/notifications", RouteType.DELETE)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - databaseManager.panelNotificationDao.deleteAllByUserId(userId, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelDeleteNotificationAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelDeleteNotificationAPI.kt deleted file mode 100755 index 3dae6781..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelDeleteNotificationAPI.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.panomc.platform.route.api.panel.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class PanelDeleteNotificationAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/notifications/:id", RouteType.DELETE)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("id", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val id = parameters.pathParameter("id").long - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.panelNotificationDao.existsById(id, sqlClient) - - if (!exists) { - return Successful() - } - - val notification = - databaseManager.panelNotificationDao.getById(id, sqlClient)!! - - if (notification.userId != userId) { - return Successful() - } - - databaseManager.panelNotificationDao.deleteById(notification.id, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetMoreNotificationsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetMoreNotificationsAPI.kt deleted file mode 100755 index 1bbfb81a..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetMoreNotificationsAPI.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.panomc.platform.route.api.panel.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class PanelGetMoreNotificationsAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/notifications/:id/more", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("id", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val lastNotificationId = parameters.pathParameter("id").long - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val notifications = - databaseManager.panelNotificationDao.get10ByUserIdAndStartFromId(userId, lastNotificationId, sqlClient) - - databaseManager.panelNotificationDao.markReadLast10StartFromId(userId, lastNotificationId, sqlClient) - - val notificationsDataList = mutableListOf>() - - notifications.forEach { notification -> - notificationsDataList.add( - mapOf( - "id" to notification.id, - "type" to notification.type, - "properties" to notification.properties, - "date" to notification.date, - "status" to notification.status, - "isPersonal" to (notification.userId == userId) - ) - ) - } - - return Successful( - mutableMapOf( - "notifications" to notificationsDataList, - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetNotificationsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetNotificationsAPI.kt deleted file mode 100755 index f36a7ebb..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetNotificationsAPI.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.panomc.platform.route.api.panel.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelGetNotificationsAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/notifications", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val count = databaseManager.panelNotificationDao.getCountByUserId(userId, sqlClient) - - val notifications = databaseManager.panelNotificationDao.getLast10ByUserId(userId, sqlClient) - - databaseManager.panelNotificationDao.markReadLast10(userId, sqlClient) - - val notificationsDataList = mutableListOf>() - - notifications.forEach { notification -> - notificationsDataList.add( - mapOf( - "id" to notification.id, - "type" to notification.type, - "properties" to notification.properties, - "date" to notification.date, - "status" to notification.status, - "isPersonal" to (notification.userId == userId) - ) - ) - } - - return Successful( - mutableMapOf( - "notifications" to notificationsDataList, - "notificationCount" to count - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetQuickNotificationsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetQuickNotificationsAPI.kt deleted file mode 100755 index a399ba2e..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelGetQuickNotificationsAPI.kt +++ /dev/null @@ -1,50 +0,0 @@ -package com.panomc.platform.route.api.panel.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelGetQuickNotificationsAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/notifications/quick", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val notifications = databaseManager.panelNotificationDao.getLast5ByUserId(userId, sqlClient) - - val count = databaseManager.panelNotificationDao.getCountOfNotReadByUserId(userId, sqlClient) - - val notificationsDataList = mutableListOf>() - - notifications.forEach { notification -> - notificationsDataList.add( - mapOf( - "id" to notification.id, - "type" to notification.type, - "properties" to notification.properties, - "date" to notification.date, - "status" to notification.status, - "isPersonal" to (notification.userId == userId) - ) - ) - } - - return Successful( - mutableMapOf( - "notifications" to notificationsDataList, - "notificationCount" to count - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelMarkNotificationAsReadAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelMarkNotificationAsReadAPI.kt deleted file mode 100755 index b1b3b5b4..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelMarkNotificationAsReadAPI.kt +++ /dev/null @@ -1,52 +0,0 @@ -package com.panomc.platform.route.api.panel.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class PanelMarkNotificationAsReadAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/notifications/:id/read", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("id", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val id = parameters.pathParameter("id").long - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.panelNotificationDao.existsById(id, sqlClient) - - if (!exists) { - return Successful() - } - - val notification = - databaseManager.panelNotificationDao.getById(id, sqlClient)!! - - if (notification.userId != userId) { - return Successful() - } - - databaseManager.panelNotificationDao.markReadById(id, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelMarkQuickNotificationsAsReadAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelMarkQuickNotificationsAsReadAPI.kt deleted file mode 100755 index 82cd3b1a..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/notification/PanelMarkQuickNotificationsAsReadAPI.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.panomc.platform.route.api.panel.notification - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelMarkQuickNotificationsAsReadAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/notifications/quick/markAsRead", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - databaseManager.panelNotificationDao.markReadLast5ByUserId(userId, sqlClient) - - val count = databaseManager.panelNotificationDao.getCountOfNotReadByUserId(userId, sqlClient) - - return Successful( - mutableMapOf( - "notificationCount" to count - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelAddPermissionGroupAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelAddPermissionGroupAPI.kt deleted file mode 100755 index 569eed60..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelAddPermissionGroupAPI.kt +++ /dev/null @@ -1,180 +0,0 @@ -package com.panomc.platform.route.api.panel.permission - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Permission -import com.panomc.platform.db.model.PermissionGroup -import com.panomc.platform.error.CantUpdatePermGroupYourself -import com.panomc.platform.error.NoPermissionToUpdateAdminUser -import com.panomc.platform.error.SomePermissionsArentExists -import com.panomc.platform.error.SomeUsersArentExists -import com.panomc.platform.model.* -import io.vertx.core.json.JsonObject -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* -import io.vertx.sqlclient.SqlClient - -@Endpoint -class PanelAddPermissionGroupAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/permissionGroups", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - json( - objectSchema() - .property("name", stringSchema()) - .property("addedUsers", arraySchema().items(stringSchema())) - .property( - "permissions", - arraySchema() - .items( - objectSchema() - .requiredProperty("id", numberSchema()) - .requiredProperty("selected", booleanSchema()) - ) - ) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PERMISSION_GROUPS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - var name = data.getString("name") - - val addedUsers = data.getJsonArray("addedUsers").map { it.toString() } - val permissions = data.getJsonArray("permissions").map { it as JsonObject } - - val userId = authProvider.getUserIdFromRoutingContext(context) - - validateForm(name) - - name = getSystematicName(name) - - val sqlClient = getSqlClient() - - validateSelfUpdating(addedUsers, userId, sqlClient) - - validateIsPermissionGroupNameExists(name, sqlClient) - - val permissionsInDb = databaseManager.permissionDao.getPermissions(sqlClient) - - validatePermissions(permissions, permissionsInDb) - - val adminPermissionGroupId = - databaseManager.permissionGroupDao.getPermissionGroupIdByName("admin", sqlClient)!! - - validateAddedUsersContainAdminAndHasUserPerm(adminPermissionGroupId, addedUsers, sqlClient, context) - - validateAreAddedUsersExist(addedUsers, sqlClient) - - val id = databaseManager.permissionGroupDao.add(PermissionGroup(name = name), sqlClient) - - permissions.filter { it.getBoolean("selected") }.forEach { permission -> - val permissionId = permission.getLong("id") - - databaseManager.permissionGroupPermsDao.addPermission(id, permissionId, sqlClient) - } - - if (addedUsers.isNotEmpty()) { - databaseManager.userDao.setPermissionGroupByUsernames(id, addedUsers, sqlClient) - } - - return Successful(mapOf("id" to id)) - } - - private suspend fun validateAreAddedUsersExist(addedUsers: List, sqlClient: SqlClient) { - if (addedUsers.isNotEmpty()) { - val areAddedUsersExists = databaseManager.userDao.areUsernamesExists(addedUsers, sqlClient) - - if (!areAddedUsersExists) { - throw SomeUsersArentExists() - } - } - } - - private suspend fun validateAddedUsersContainAdminAndHasUserPerm( - adminPermissionGroupId: Long, - addedUsers: List, - sqlClient: SqlClient, - context: RoutingContext - ) { - val admins = databaseManager.userDao.getUsernamesByPermissionGroupId(adminPermissionGroupId, -1, sqlClient) - .map { it.lowercase() } - - val isAdmin = context.get("isAdmin") ?: false - - admins.forEach { admin -> - if (addedUsers.find { it.lowercase() == admin } != null && !isAdmin) { - throw NoPermissionToUpdateAdminUser() - } - } - } - - private fun validatePermissions( - permissions: List, - permissionsInDb: List - ) { - val notExistingPermissions = - permissionsInDb.filter { permissionInDb -> permissions.find { it.getLong("id") == permissionInDb.id } == null } - - if (notExistingPermissions.isNotEmpty()) { - throw SomePermissionsArentExists() - } - } - - private suspend fun validateIsPermissionGroupNameExists( - name: String, - sqlClient: SqlClient - ) { - val isTherePermissionGroup = - databaseManager.permissionGroupDao.isThereByName(name, sqlClient) - - if (isTherePermissionGroup) { - throw Errors(mapOf("name" to true)) - } - } - - private suspend fun validateSelfUpdating( - addedUsers: List, - userId: Long, - sqlClient: SqlClient - ) { - val username = databaseManager.userDao.getUsernameFromUserId(userId, sqlClient)!!.lowercase() - - if (addedUsers.any { it.lowercase() == username }) { - throw CantUpdatePermGroupYourself() - } - } - - private fun validateForm( - name: String - ) { - val errors = mutableMapOf() - - if (name.isEmpty() || name.length > 32) - errors["name"] = true - - if (errors.isNotEmpty()) { - throw Errors(errors) - } - } - - private fun getSystematicName(name: String) = name.lowercase().replace("\\s+".toRegex(), "-") -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelDeletePermissionGroupAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelDeletePermissionGroupAPI.kt deleted file mode 100755 index 1a977932..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelDeletePermissionGroupAPI.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.panomc.platform.route.api.panel.permission - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.CantDeleteAdminPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelDeletePermissionGroupAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/permissions/:id", RouteType.DELETE)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PERMISSION_GROUPS, context) - - val parameters = getParameters(context) - - val permissionGroupId = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val isTherePermissionGroup = - databaseManager.permissionGroupDao.isThereById(permissionGroupId, sqlClient) - - if (!isTherePermissionGroup) { - throw NotExists() - } - - val permissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(permissionGroupId, sqlClient)!! - - if (permissionGroup.name == "admin") { - throw CantDeleteAdminPermission() - } - - databaseManager.permissionGroupPermsDao.removePermissionGroup(permissionGroupId, sqlClient) - - databaseManager.userDao.removePermissionGroupByPermissionGroupId(permissionGroupId, sqlClient) - - databaseManager.permissionGroupDao.deleteById(permissionGroupId, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionGroupAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionGroupAPI.kt deleted file mode 100644 index b56d2d28..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionGroupAPI.kt +++ /dev/null @@ -1,65 +0,0 @@ -package com.panomc.platform.route.api.panel.permission - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class PanelGetPermissionGroupAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : - PanelApi() { - override val paths = listOf(Path("/api/panel/permissionGroups/:id", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("id", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PERMISSION_GROUPS, context) - - val parameters = getParameters(context) - - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val isTherePermissionGroupById = databaseManager.permissionGroupDao.isThereById(id, sqlClient) - - if (!isTherePermissionGroupById) { - throw NotExists() - } - - val result = mutableMapOf() - - val permissionGroup = databaseManager.permissionGroupDao.getPermissionGroupById(id, sqlClient)!! - - val userCount = databaseManager.userDao.getCountOfUsersByPermissionGroupId(id, sqlClient) - - val usernameList = - databaseManager.userDao.getUsernamesByPermissionGroupId(id, -1, sqlClient) - - val permissionGroupPerms = - databaseManager.permissionGroupPermsDao.getByPermissionGroupId(id, sqlClient).map { it.permissionId } - - result["id"] = id - result["name"] = permissionGroup.name - result["users"] = usernameList - result["userCount"] = userCount - result["permissionGroupPerms"] = permissionGroupPerms - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionGroupsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionGroupsAPI.kt deleted file mode 100755 index 63a5ff83..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionGroupsAPI.kt +++ /dev/null @@ -1,104 +0,0 @@ -package com.panomc.platform.route.api.panel.permission - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.PermissionGroup -import com.panomc.platform.error.PageNotFound -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema -import kotlin.math.ceil - -@Endpoint -class PanelGetPermissionGroupsAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/permissionGroups", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter(Parameters.optionalParam("page", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PERMISSION_GROUPS, context) - - val parameters = getParameters(context) - val page = parameters.queryParameter("page")?.long ?: 0L - - val result = mutableMapOf() - - val sqlClient = getSqlClient() - - val permissionGroupCount = databaseManager.permissionGroupDao.countPermissionGroups(sqlClient) - val permissions = databaseManager.permissionDao.getPermissions(sqlClient) - - var totalPage = ceil(permissionGroupCount.toDouble() / 10).toLong() - - if (totalPage < 1) - totalPage = 1 - - if (page != 0L && (page > totalPage || page < 1)) { - throw PageNotFound() - } - - val permissionGroups = if (page == 0L) - databaseManager.permissionGroupDao.getPermissionGroups(sqlClient) - else - databaseManager.permissionGroupDao.getPermissionGroupsByPage(page, sqlClient) - - val permissionGroupList: List> = permissionGroups.map { permissionGroup -> - mutableMapOf( - "id" to permissionGroup.id, - "name" to permissionGroup.name - ) - } - - val getPermissionGroupData: suspend (PermissionGroup) -> Unit = { permissionGroup -> - val foundPermissionGroup = permissionGroupList.find { it["id"] == permissionGroup.id }!! - - val userCount = - databaseManager.userDao.getCountOfUsersByPermissionGroupId(permissionGroup.id, sqlClient) - val usernameList = - databaseManager.userDao.getUsernamesByPermissionGroupId(permissionGroup.id, 3, sqlClient) - val permissionCount = databaseManager.permissionGroupPermsDao.countPermissionsByPermissionGroupId( - permissionGroup.id, - sqlClient - ) - - foundPermissionGroup["userCount"] = userCount - foundPermissionGroup["users"] = usernameList - foundPermissionGroup["permissionCount"] = permissionCount - } - - permissionGroups.forEach { - getPermissionGroupData(it) - } - - val permissionGroupPerms = databaseManager.permissionGroupPermsDao.getPermissionGroupPerms(sqlClient) - - val permissionGroupPermIdListMap = permissionGroupPerms - .distinctBy { it.permissionGroupId } - .associateBy({ it.permissionGroupId }, { mutableListOf() }) - - permissionGroupPerms.forEach { perm -> - permissionGroupPermIdListMap[perm.permissionGroupId]!!.add(perm.permissionId) - } - - result["permissionGroups"] = permissionGroupList - result["permissionGroupCount"] = permissionGroupCount - result["totalPage"] = totalPage - result["permissionGroupPerms"] = permissionGroupPermIdListMap - result["permissions"] = permissions - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionsAPI.kt deleted file mode 100755 index f5ff0ae4..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelGetPermissionsAPI.kt +++ /dev/null @@ -1,37 +0,0 @@ -package com.panomc.platform.route.api.panel.permission - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelGetPermissionsAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/permissions", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PERMISSION_GROUPS, context) - - val result = mutableMapOf() - - val sqlClient = getSqlClient() - - val permissions = databaseManager.permissionDao.getPermissions(sqlClient) - - result["permissions"] = permissions - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelSetPermissionGroupPermissionAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelSetPermissionGroupPermissionAPI.kt deleted file mode 100755 index 61f88650..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelSetPermissionGroupPermissionAPI.kt +++ /dev/null @@ -1,95 +0,0 @@ -package com.panomc.platform.route.api.panel.permission - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.CantUpdateAdminPermission -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class PanelSetPermissionGroupPermissionAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = - listOf(Path("/api/panel/permissionGroups/:permissionGroupId/permissions/:permissionId", RouteType.PUT)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("permissionGroupId", Schemas.numberSchema())) - .pathParameter(Parameters.param("permissionId", Schemas.numberSchema())) - .body( - Bodies.json( - Schemas.objectSchema() - .property("mode", Schemas.stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PERMISSION_GROUPS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val permissionGroupId = parameters.pathParameter("permissionGroupId").long - val permissionId = parameters.pathParameter("permissionId").long - val mode = data.getString("mode") - - if (mode != "ADD" && mode != "DELETE") { - throw NoPermission() - } - - val sqlClient = getSqlClient() - - val isTherePermissionGroup = - databaseManager.permissionGroupDao.isThereById(permissionGroupId, sqlClient) - - if (!isTherePermissionGroup) { - throw NotExists() - } - - val permissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(permissionGroupId, sqlClient)!! - - if (permissionGroup.name == "admin") { - throw CantUpdateAdminPermission() - } - - val isTherePermission = databaseManager.permissionDao.isTherePermissionById(permissionId, sqlClient) - - if (!isTherePermission) { - throw NotExists() - } - - val doesPermissionGroupHavePermission = - databaseManager.permissionGroupPermsDao.doesPermissionGroupHavePermission( - permissionGroupId, - permissionId, - sqlClient - ) - - if (mode == "ADD" && !doesPermissionGroupHavePermission) - databaseManager.permissionGroupPermsDao.addPermission(permissionGroupId, permissionId, sqlClient) - else if (doesPermissionGroupHavePermission) - databaseManager.permissionGroupPermsDao.removePermission(permissionGroupId, permissionId, sqlClient) - - val body = mutableMapOf() - - body["mode"] = if (mode == "ADD" && !doesPermissionGroupHavePermission) "ADD" else "DELETE" - - return Successful(body) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelUpdatePermissionGroupAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelUpdatePermissionGroupAPI.kt deleted file mode 100755 index ac6aaaed..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/permission/PanelUpdatePermissionGroupAPI.kt +++ /dev/null @@ -1,284 +0,0 @@ -package com.panomc.platform.route.api.panel.permission - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Permission -import com.panomc.platform.db.model.PermissionGroup -import com.panomc.platform.error.* -import com.panomc.platform.model.* -import io.vertx.core.json.JsonObject -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* -import io.vertx.sqlclient.SqlClient - -@Endpoint -class PanelUpdatePermissionGroupAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/permissionGroups/:id", RouteType.PUT)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .body( - json( - objectSchema() - .property("name", stringSchema()) - .property("addedUsers", arraySchema().items(stringSchema())) - .property("removedUsers", arraySchema().items(stringSchema())) - .property( - "permissions", - arraySchema() - .items( - objectSchema() - .requiredProperty("id", numberSchema()) - .requiredProperty("selected", booleanSchema()) - ) - ) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PERMISSION_GROUPS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val id = parameters.pathParameter("id").long - var name = data.getString("name") - - val addedUsers = data.getJsonArray("addedUsers").map { it.toString() } - val removedUsers = data.getJsonArray("removedUsers").map { it.toString() } - val permissions = data.getJsonArray("permissions").map { it as JsonObject } - - val userId = authProvider.getUserIdFromRoutingContext(context) - - validateForm(name) - - name = getSystematicName(name) - - val sqlClient = getSqlClient() - - validateSelfUpdating(addedUsers, removedUsers, userId, sqlClient) - - validatePermissionGroupExists(id, sqlClient) - - val adminPermissionGroupId = - databaseManager.permissionGroupDao.getPermissionGroupIdByName("admin", sqlClient)!! - - validateHavePermissionToUpdateAdminPermGroup(id, adminPermissionGroupId, userId, sqlClient) - - validateHavePermissionToUpdateAdminUser( - addedUsers, - removedUsers, - adminPermissionGroupId, - sqlClient, - context - ) - - val permissionGroup = databaseManager.permissionGroupDao.getPermissionGroupById(id, sqlClient)!! - - val permissionsInDb = databaseManager.permissionDao.getPermissions(sqlClient) - - validatePermissions(permissions, permissionsInDb) - - validateIsAdminPermGroup(permissions, permissionsInDb, permissionGroup, name, adminPermissionGroupId) - - validateAreAddedUsersExist(addedUsers, sqlClient) - validateAreRemovedUsersExist(removedUsers, sqlClient) - - validateIsPermissionGroupNameExists(name, permissionGroup, sqlClient) - - permissions.forEach { permission -> - val permissionId = permission.getLong("id") - val isPermissionSelected = permission.getBoolean("selected") - - val permissionExists = databaseManager.permissionGroupPermsDao.doesPermissionGroupHavePermission( - id, - permissionId, - sqlClient - ) - - if (isPermissionSelected && !permissionExists) { - databaseManager.permissionGroupPermsDao.addPermission(id, permissionId, sqlClient) - } - - if (!isPermissionSelected && permissionExists) { - databaseManager.permissionGroupPermsDao.removePermission(id, permissionId, sqlClient) - } - } - - if (permissionGroup.name != name) { - databaseManager.permissionGroupDao.update( - PermissionGroup(id, name), - sqlClient - ) - } - - if (addedUsers.isNotEmpty()) { - databaseManager.userDao.setPermissionGroupByUsernames(id, addedUsers, sqlClient) - } - - if (removedUsers.isNotEmpty()) { - databaseManager.userDao.setPermissionGroupByUsernames(-1, removedUsers, sqlClient) - } - - return Successful() - } - - private fun validatePermissions( - permissions: List, - permissionsInDb: List - ) { - val notExistingPermissions = - permissionsInDb.filter { permissionInDb -> permissions.find { it.getLong("id") == permissionInDb.id } == null } - - if (notExistingPermissions.isNotEmpty()) { - throw SomePermissionsArentExists() - } - } - - private suspend fun validateIsPermissionGroupNameExists( - name: String, - permissionGroup: PermissionGroup, - sqlClient: SqlClient - ) { - if (permissionGroup.name != name) { - val isTherePermissionGroupByName = - databaseManager.permissionGroupDao.isThereByName(name, sqlClient) - - if (isTherePermissionGroupByName) { - throw Errors(mapOf("name" to true)) - } - } - } - - private suspend fun validateAreRemovedUsersExist(removedUsers: List, sqlClient: SqlClient) { - if (removedUsers.isNotEmpty()) { - val areRemovedUsersExists = databaseManager.userDao.areUsernamesExists(removedUsers, sqlClient) - - if (!areRemovedUsersExists) { - throw SomeUsersArentExists() - } - } - } - - private suspend fun validateAreAddedUsersExist(addedUsers: List, sqlClient: SqlClient) { - if (addedUsers.isNotEmpty()) { - val areAddedUsersExists = databaseManager.userDao.areUsernamesExists(addedUsers, sqlClient) - - if (!areAddedUsersExists) { - throw SomeUsersArentExists() - } - } - } - - private fun validateIsAdminPermGroup( - permissions: List, - permissionsInDb: List, - permissionGroup: PermissionGroup, - name: String, - adminPermissionGroupId: Long - ) { - var throwError = false - - if (permissionGroup.id == adminPermissionGroupId) { - val selectedPermissionCount = permissions.count { it.getBoolean("selected") } - - if (selectedPermissionCount != permissionsInDb.size) { - throwError = true - } - } - - if (permissionGroup.name != name && permissionGroup.id == adminPermissionGroupId) { - throwError = true - } - - if (throwError) { - throw CantUpdateAdminPermission() - } - } - - private suspend fun validateHavePermissionToUpdateAdminPermGroup( - permissionGroupId: Long, - adminPermissionGroupId: Long, - userId: Long, - sqlClient: SqlClient - ) { - if (permissionGroupId == adminPermissionGroupId) { - val user = databaseManager.userDao.getById(userId, sqlClient) - - if (user!!.permissionGroupId != adminPermissionGroupId) { - throw NoPermissionToUpdateAdminPermGroup() - } - } - } - - private suspend fun validateHavePermissionToUpdateAdminUser( - addedUsers: List, - removedUsers: List, - adminPermissionGroupId: Long, - sqlClient: SqlClient, - context: RoutingContext - ) { - val admins = databaseManager.userDao.getUsernamesByPermissionGroupId(adminPermissionGroupId, -1, sqlClient) - .map { it.lowercase() } - - val isAdmin = context.get("isAdmin") ?: false - - admins.forEach { admin -> - if ((addedUsers.find { it.lowercase() == admin } != null || removedUsers.find { it.lowercase() == admin } != null) && !isAdmin) { - throw NoPermissionToUpdateAdminUser() - } - } - } - - private suspend fun validateSelfUpdating( - addedUsers: List, - removedUsers: List, - userId: Long, - sqlClient: SqlClient - ) { - val username = databaseManager.userDao.getUsernameFromUserId(userId, sqlClient)!!.lowercase() - - if (addedUsers.any { it.lowercase() == username } || removedUsers.any { it.lowercase() == username }) { - throw CantUpdatePermGroupYourself() - } - } - - private suspend fun validatePermissionGroupExists(permissionGroupId: Long, sqlClient: SqlClient) { - val isTherePermissionGroupById = - databaseManager.permissionGroupDao.isThereById(permissionGroupId, sqlClient) - - if (!isTherePermissionGroupById) { - throw PermGroupNotExists() - } - } - - private fun validateForm( - name: String - ) { - val errors = mutableMapOf() - - if (name.isEmpty() || name.length > 32) - errors["name"] = true - - if (errors.isNotEmpty()) { - throw Errors(errors) - } - } - - private fun getSystematicName(name: String) = name.lowercase().replace("\\s+".toRegex(), "-") -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/platformAuth/PanelGetRefreshKeyAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/platformAuth/PanelGetRefreshKeyAPI.kt deleted file mode 100755 index 0dad7d08..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/platformAuth/PanelGetRefreshKeyAPI.kt +++ /dev/null @@ -1,30 +0,0 @@ -package com.panomc.platform.route.api.panel.platformAuth - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.model.* -import com.panomc.platform.server.PlatformCodeManager -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelGetRefreshKeyAPI( - private val platformCodeManager: PlatformCodeManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/platformAuth/refreshKey", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_SERVERS, context) - - return Successful( - mapOf( - "key" to platformCodeManager.getPlatformKey(), - "timeStarted" to platformCodeManager.getTimeStarted() - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelBanPlayerAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelBanPlayerAPI.kt deleted file mode 100644 index 662f4b96..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelBanPlayerAPI.kt +++ /dev/null @@ -1,110 +0,0 @@ -package com.panomc.platform.route.api.panel.player - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.* -import com.panomc.platform.mail.MailManager -import com.panomc.platform.mail.notification.BannedMail -import com.panomc.platform.model.* -import com.panomc.platform.token.TokenProvider -import com.panomc.platform.token.TokenType -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class PanelBanPlayerAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager, - private val mailManager: MailManager, - private val tokenProvider: TokenProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/players/:username/ban", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("username", stringSchema())) - .body( - json( - objectSchema() - .optionalProperty("sendNotification", booleanSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PLAYERS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val username = parameters.pathParameter("username").string - - val sendNotification = data.getBoolean("sendNotification") ?: false - - val sqlClient = getSqlClient() - - val exists = databaseManager.userDao.existsByUsername(username, sqlClient) - - if (!exists) { - throw NotExists() - } - - val userId = - databaseManager.userDao.getUserIdFromUsername(username, sqlClient) ?: throw NotExists() - val authUserId = authProvider.getUserIdFromRoutingContext(context) - - if (userId == authUserId) { - throw CantBanYourself() - } - - val isBanned = databaseManager.userDao.isBanned(userId, sqlClient) - - if (isBanned) { - throw AlreadyBanned() - } - - val userPermissionGroupId = databaseManager.userDao.getPermissionGroupIdFromUserId(userId, sqlClient)!! - - if (userPermissionGroupId != -1L) { - val userPermissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(userPermissionGroupId, sqlClient)!! - - if (userPermissionGroup.name == "admin") { - val isAdmin = context.get("isAdmin") ?: false - - if (!isAdmin) { - throw NoPermission() - } - - val count = databaseManager.userDao.getCountOfUsersByPermissionGroupId( - userPermissionGroupId, - sqlClient - ) - - if (count == 1L) { - throw LastAdmin() - } - } - } - - databaseManager.userDao.banPlayer(userId, sqlClient) - - tokenProvider.invalidateTokensBySubjectAndType(userId.toString(), TokenType.AUTHENTICATION, sqlClient) - - if (sendNotification) { - mailManager.sendMail(sqlClient, userId, BannedMail()) - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelDeletePlayerAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelDeletePlayerAPI.kt deleted file mode 100644 index 7071e5a5..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelDeletePlayerAPI.kt +++ /dev/null @@ -1,117 +0,0 @@ -package com.panomc.platform.route.api.panel.player - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.* -import com.panomc.platform.model.* -import com.panomc.platform.token.TokenProvider -import com.panomc.platform.token.TokenType -import io.vertx.core.json.JsonArray -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas -import io.vertx.json.schema.common.dsl.Schemas.stringSchema -import org.apache.commons.codec.digest.DigestUtils - -@Endpoint -class PanelDeletePlayerAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager, - private val tokenProvider: TokenProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/players/:username/delete", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("username", stringSchema())) - .body( - Bodies.json( - Schemas.objectSchema() - .property("currentPassword", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PLAYERS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val username = parameters.pathParameter("username").string - val currentPassword = data.getString("currentPassword") - - val sqlClient = getSqlClient() - - val userId = - databaseManager.userDao.getUserIdFromUsername(username, sqlClient) ?: throw NotExists() - val authUserId = authProvider.getUserIdFromRoutingContext(context) - - if (userId == authUserId) { - throw CantDeleteYourself() - } - - val isCurrentPasswordCorrect = - databaseManager.userDao.isPasswordCorrectWithId(userId, DigestUtils.md5Hex(currentPassword), sqlClient) - - if (!isCurrentPasswordCorrect) { - throw CurrentPasswordNotCorrect() - } - - val userPermissionGroupId = databaseManager.userDao.getPermissionGroupIdFromUserId(userId, sqlClient)!! - - if (userPermissionGroupId != -1L) { - val userPermissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(userPermissionGroupId, sqlClient)!! - - if (userPermissionGroup.name == "admin") { - val isAdmin = context.get("isAdmin") ?: false - - if (!isAdmin) { - throw NoPermission() - } - - val count = databaseManager.userDao.getCountOfUsersByPermissionGroupId( - userPermissionGroupId, - sqlClient - ) - - if (count == 1L) { - throw LastAdmin() - } - } - } - - databaseManager.notificationDao.deleteAllByUserId(userId, sqlClient) - databaseManager.panelConfigDao.deleteByUserId(userId, sqlClient) - databaseManager.panelNotificationDao.deleteAllByUserId(userId, sqlClient) - databaseManager.postDao.updateUserIdByUserId(userId, -1, sqlClient) - - val tickets = databaseManager.ticketDao.getByUserId(userId, sqlClient) - - val ticketIdList = JsonArray(tickets.map { it.id }) - - if (ticketIdList.size() != 0) { - databaseManager.ticketMessageDao.deleteByTicketIdList(ticketIdList, sqlClient) - } - - databaseManager.ticketMessageDao.updateUserIdByUserId(userId, -1, sqlClient) - - TokenType.values().forEach { tokenType -> - tokenProvider.invalidateTokensBySubjectAndType(userId.toString(), tokenType, sqlClient) - } - - databaseManager.userDao.deleteById(userId, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelGetPlayerAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelGetPlayerAPI.kt deleted file mode 100755 index dd8e4c36..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelGetPlayerAPI.kt +++ /dev/null @@ -1,151 +0,0 @@ -package com.panomc.platform.route.api.panel.player - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Ticket -import com.panomc.platform.db.model.TicketCategory -import com.panomc.platform.error.NotExists -import com.panomc.platform.error.PageNotFound -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.optionalParam -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema -import io.vertx.json.schema.common.dsl.Schemas.stringSchema -import kotlin.math.ceil - -@Endpoint -class PanelGetPlayerAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/players/:username", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("username", stringSchema())) - .queryParameter(optionalParam("page", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val username = parameters.pathParameter("username").string - val page = parameters.queryParameter("page")?.long ?: 1L - - val sqlClient = getSqlClient() - - val exists = databaseManager.userDao.existsByUsername(username, sqlClient) - - if (!exists) { - throw NotExists() - } - - val user = databaseManager.userDao.getByUsername( - username, - sqlClient - )!! - - val result = mutableMapOf() - - result["player"] = mutableMapOf( - "id" to user.id, - "username" to user.username, - "email" to user.email, - "registerDate" to user.registerDate, - "lastLoginDate" to user.lastLoginDate, - "isBanned" to user.banned, - "canCreateTicket" to user.canCreateTicket, - "isEmailVerified" to user.emailVerified, - "permissionGroup" to "-", - "lastActivityTime" to user.lastActivityTime, - "inGame" to databaseManager.serverPlayerDao.existsByUsername(user.username, sqlClient) - ) - - if (user.permissionGroupId != -1L) { - val permissionGroup = databaseManager.permissionGroupDao.getPermissionGroupById( - user.permissionGroupId, - sqlClient - )!! - - @Suppress("UNCHECKED_CAST") - (result["player"] as MutableMap)["permissionGroup"] = permissionGroup.name - } - - if (!authProvider.hasPermission(user.id, PanelPermission.MANAGE_TICKETS, context)) { - return Successful(result) - } - - val count = databaseManager.ticketDao.countByUserId(user.id, sqlClient) - - var totalPage = ceil(count.toDouble() / 10).toLong() - - if (totalPage < 1) - totalPage = 1 - - if (page > totalPage || page < 1) { - throw PageNotFound() - } - - result["ticketCount"] = count - result["ticketTotalPage"] = totalPage - - if (count == 0L) { - return getTickets(result, listOf(), mapOf(), user.username) - } - - val tickets = databaseManager.ticketDao.getAllByUserIdAndPage(user.id, page, sqlClient) - - val categoryIdList = tickets.filter { it.categoryId != -1L }.distinctBy { it.categoryId }.map { it.categoryId } - - if (categoryIdList.isEmpty()) { - return getTickets(result, tickets, mapOf(), username) - } - - val ticketCategoryList = databaseManager.ticketCategoryDao.getByIdList(categoryIdList, sqlClient) - - return getTickets(result, tickets, ticketCategoryList, username) - } - - private fun getTickets( - result: MutableMap, - tickets: List, - ticketCategoryList: Map, - username: String - ): Result { - val ticketDataList = mutableListOf>() - - tickets.forEach { ticket -> - ticketDataList.add( - mapOf( - "id" to ticket.id, - "title" to ticket.title, - "category" to - if (ticket.categoryId == -1L) - mapOf("id" to -1, "title" to "-") - else - ticketCategoryList.getOrDefault( - ticket.categoryId, - mapOf("id" to -1, "title" to "-") - ), - "writer" to mapOf( - "username" to username - ), - "date" to ticket.date, - "lastUpdate" to ticket.lastUpdate, - "status" to ticket.status - ) - ) - } - - result["tickets"] = ticketDataList - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelGetPlayersAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelGetPlayersAPI.kt deleted file mode 100755 index 1022f23d..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelGetPlayersAPI.kt +++ /dev/null @@ -1,164 +0,0 @@ -package com.panomc.platform.route.api.panel.player - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.PermissionGroup -import com.panomc.platform.db.model.User -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.error.PageNotFound -import com.panomc.platform.model.* -import com.panomc.platform.util.PlayerStatus -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.optionalParam -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* -import kotlin.math.ceil - -@Endpoint -class PanelGetPlayersAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/players", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter( - optionalParam( - "status", - arraySchema() - .items(enumSchema(*PlayerStatus.values().map { it.type }.toTypedArray())) - ) - ) - .queryParameter(optionalParam("permissionGroup", stringSchema())) - .queryParameter(optionalParam("page", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PLAYERS, context) - - val parameters = getParameters(context) - - val playerStatus = - PlayerStatus.valueOf(type = parameters.queryParameter("status")?.jsonArray?.first() as String? ?: "all") - ?: PlayerStatus.ALL - val page = parameters.queryParameter("page")?.long ?: 1L - val permissionGroupName = parameters.queryParameter("permissionGroup")?.string - - val sqlClient = getSqlClient() - - var permissionGroup: PermissionGroup? = null - - if (permissionGroupName != null && permissionGroupName != "-") { - val isTherePermission = - databaseManager.permissionGroupDao.isThereByName(permissionGroupName, sqlClient) - - if (!isTherePermission) { - throw NotExists() - } - - val permissionGroupId = - databaseManager.permissionGroupDao.getPermissionGroupIdByName(permissionGroupName, sqlClient)!! - - permissionGroup = PermissionGroup(permissionGroupId, permissionGroupName) - } - - if (permissionGroupName != null && permissionGroupName == "-") { - permissionGroup = PermissionGroup(name = "-") - } - - val count = - if (permissionGroup != null) - databaseManager.userDao.getCountOfUsersByPermissionGroupId(permissionGroup.id, sqlClient) - else - databaseManager.userDao.countByStatus(playerStatus, sqlClient) - - var totalPage = ceil(count.toDouble() / 10).toLong() - - if (totalPage < 1) - totalPage = 1 - - if (page > totalPage || page < 1) { - throw PageNotFound() - } - - val userList = - if (permissionGroup != null) - databaseManager.userDao.getAllByPageAndPermissionGroup(page, permissionGroup.id, sqlClient) - else - databaseManager.userDao.getAllByPageAndStatus(page, playerStatus, sqlClient) - - val playerList = mutableListOf>() - - val result = mutableMapOf( - "players" to playerList, - "playerCount" to count, - "totalPage" to totalPage - ) - - if (permissionGroup != null) { - result["permissionGroup"] = permissionGroup - } - - if (userList.isEmpty()) { - return Successful(result) - } - - val addPlayerToList: suspend (user: User, mutablePlayerList: MutableList>, ticketCount: Long, permissionGroup: PermissionGroup?) -> Unit = - { user, mutablePlayerList, ticketCount: Long, userPermissionGroup -> - mutablePlayerList.add( - mapOf( - "id" to user.id, - "username" to user.username, - "email" to user.email, - "permissionGroupId" to user.permissionGroupId, - "permissionGroup" to (userPermissionGroup?.name ?: "-"), - "ticketCount" to ticketCount, - "registerDate" to user.registerDate, - "lastLoginDate" to user.lastLoginDate, - "isBanned" to user.banned, - "canCreateTicket" to user.canCreateTicket, - "isEmailVerified" to user.emailVerified, - "lastActivityTime" to user.lastActivityTime, - "inGame" to databaseManager.serverPlayerDao.existsByUsername(user.username, sqlClient) - ) - ) - } - - val getPlayerData: suspend (User) -> Unit = getPlayerData@{ user -> - val count = databaseManager.ticketDao.countByUserId( - user.id, - sqlClient - ) - - if (user.permissionGroupId == -1L) { - addPlayerToList(user, playerList, count, null) - - return@getPlayerData - } - - val permissionGroup = databaseManager.permissionGroupDao.getPermissionGroupById( - user.permissionGroupId, - sqlClient - ) - - if (permissionGroup == null) { - throw NoPermission() - } - - addPlayerToList(user, playerList, count, permissionGroup) - } - - userList.forEach { - getPlayerData(it) - } - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelSendValidationEmailAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelSendValidationEmailAPI.kt deleted file mode 100644 index 00f8d622..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelSendValidationEmailAPI.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.panomc.platform.route.api.panel.player - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.EmailAlreadyVerified -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.mail.MailManager -import com.panomc.platform.mail.mails.ActivationMail -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.stringSchema - -@Endpoint -class PanelSendValidationEmailAPI( - private val databaseManager: DatabaseManager, - private val mailManager: MailManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/players/:username/verificationMail", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("username", stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PLAYERS, context) - - val parameters = getParameters(context) - - val username = parameters.pathParameter("username").string - - val sqlClient = getSqlClient() - - val exists = databaseManager.userDao.existsByUsername(username, sqlClient) - - if (!exists) { - throw NotExists() - } - - val userId = - databaseManager.userDao.getUserIdFromUsername(username, sqlClient) ?: throw NotExists() - - val userPermissionGroupId = databaseManager.userDao.getPermissionGroupIdFromUserId(userId, sqlClient)!! - - val userPermissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(userPermissionGroupId, sqlClient)!! - - val isAdmin = context.get("isAdmin") ?: false - - if (userPermissionGroup.name == "admin" && !isAdmin) { - throw NoPermission() - } - - val isEmailVerified = databaseManager.userDao.isEmailVerifiedById(userId, sqlClient) - - if (isEmailVerified) { - throw EmailAlreadyVerified() - } - - mailManager.sendMail(sqlClient, userId, ActivationMail()) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUnbanPlayerAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUnbanPlayerAPI.kt deleted file mode 100644 index 9f11babf..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUnbanPlayerAPI.kt +++ /dev/null @@ -1,69 +0,0 @@ -package com.panomc.platform.route.api.panel.player - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotBanned -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.stringSchema - -@Endpoint -class PanelUnbanPlayerAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/players/:username/unban", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("username", stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PLAYERS, context) - - val parameters = getParameters(context) - - val username = parameters.pathParameter("username").string - - val sqlClient = getSqlClient() - - val exists = databaseManager.userDao.existsByUsername(username, sqlClient) - - if (!exists) { - throw NotExists() - } - - val userId = - databaseManager.userDao.getUserIdFromUsername(username, sqlClient) ?: throw NotExists() - - val isBanned = databaseManager.userDao.isBanned(userId, sqlClient) - - if (!isBanned) { - throw NotBanned() - } - - val userPermissionGroupId = databaseManager.userDao.getPermissionGroupIdFromUserId(userId, sqlClient)!! - - val userPermissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(userPermissionGroupId, sqlClient)!! - - val isAdmin = context.get("isAdmin") ?: false - - if (userPermissionGroup.name == "admin" && !isAdmin) { - throw NoPermission() - } - - databaseManager.userDao.unbanPlayer(userId, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUpdatePlayerAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUpdatePlayerAPI.kt deleted file mode 100755 index b822754f..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUpdatePlayerAPI.kt +++ /dev/null @@ -1,143 +0,0 @@ -package com.panomc.platform.route.api.panel.player - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class PanelUpdatePlayerAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/players/:id", RouteType.PUT)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .body( - json( - objectSchema() - .property("username", stringSchema()) - .property("email", stringSchema()) - .property("newPassword", stringSchema()) - .property("newPasswordRepeat", stringSchema()) - .property("isEmailVerified", booleanSchema()) - .property("canCreateTicket", booleanSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val id = parameters.pathParameter("id").long - val username = data.getString("username") - val email = data.getString("email") - val newPassword = data.getString("newPassword") - val newPasswordRepeat = data.getString("newPasswordRepeat") - val isEmailVerified = data.getBoolean("isEmailVerified") - val canCreateTicket = data.getBoolean("canCreateTicket") - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val hasManagePlayerPermission = authProvider.hasPermission(userId, PanelPermission.MANAGE_PLAYERS, context) - - if (!hasManagePlayerPermission && id != userId) { - throw NoPermission() - } - - validateForm(username, email, newPassword, newPasswordRepeat) - - val sqlClient = getSqlClient() - - val exists = databaseManager.userDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - val userPermissionGroupId = databaseManager.userDao.getPermissionGroupIdFromUserId(id, sqlClient)!! - - val userPermissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(userPermissionGroupId, sqlClient)!! - - val isAdmin = context.get("isAdmin") ?: false - - if (userPermissionGroup.name == "admin" && !isAdmin) { - throw NoPermission() - } - - val user = databaseManager.userDao.getById(id, sqlClient)!! - - if (username != user.username) { - val usernameExists = databaseManager.userDao.existsByUsername(username, sqlClient) - - if (usernameExists) { - throw Errors(mapOf("username" to "EXISTS")) - } - - databaseManager.userDao.setUsernameById(user.id, username, sqlClient) - } - - if (email != user.email) { - val emailExists = databaseManager.userDao.isEmailExists(email, sqlClient) - - if (emailExists) { - throw Errors(mapOf("username" to "EXISTS")) - } - - databaseManager.userDao.setEmailById(user.id, username, sqlClient) - } - - if (newPassword.isNotEmpty()) { - databaseManager.userDao.setPasswordById(user.id, newPassword, sqlClient) - } - - if (id != userId) { - databaseManager.userDao.updateEmailVerifyStatusById(id, isEmailVerified, sqlClient) - databaseManager.userDao.updateCanCreateTicketStatusById(id, canCreateTicket, sqlClient) - } - - return Successful() - } - - private fun validateForm( - username: String, - email: String, - newPassword: String, - newPasswordRepeat: String - ) { - val errors = mutableMapOf() - - if (username.isEmpty() || username.length > 16 || username.length < 3 || !username.matches(Regex("^[a-zA-Z0-9_]+\$"))) - errors["username"] = "INVALID" - - if (email.isEmpty() || !email.matches(Regex("^[\\w-.]+@([\\w-]+\\.)+[\\w-]{2,4}\$"))) - errors["email"] = "INVALID" - - if (newPassword.isNotEmpty() && (newPassword.length < 6 || newPassword.length > 128)) - errors["newPassword"] = "INVALID" - - if (newPasswordRepeat != newPassword) - errors["newPasswordRepeat"] = "NOT_MATCH" - - if (errors.isNotEmpty()) { - throw Errors(errors) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUpdatePlayerPermissionGroupAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUpdatePlayerPermissionGroupAPI.kt deleted file mode 100755 index 3902b0ae..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/player/PanelUpdatePlayerPermissionGroupAPI.kt +++ /dev/null @@ -1,125 +0,0 @@ -package com.panomc.platform.route.api.panel.player - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.CantUpdatePermGroupYourself -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.objectSchema -import io.vertx.json.schema.common.dsl.Schemas.stringSchema - -@Endpoint -class PanelUpdatePlayerPermissionGroupAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/players/:username/permissionGroup", RouteType.PUT)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("username", stringSchema())) - .body( - json( - objectSchema() - .property("permissionGroup", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PERMISSION_GROUPS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val username = parameters.pathParameter("username").string - val permissionGroup = data.getString("permissionGroup") - - val sqlClient = getSqlClient() - - val exists = databaseManager.userDao.existsByUsername(username, sqlClient) - - if (!exists) { - throw NotExists() - } - - val userId = databaseManager.userDao.getUserIdFromUsername(username, sqlClient) - - val authUserId = authProvider.getUserIdFromRoutingContext(context) - - if (userId == authUserId) { - throw CantUpdatePermGroupYourself() - } - - var permissionGroupId = -1L - - if (permissionGroup != "-") { - val isTherePermissionGroup = databaseManager.permissionGroupDao.isThereByName( - permissionGroup, - sqlClient - ) - - if (!isTherePermissionGroup) { - throw NotExists() - } - - permissionGroupId = databaseManager.permissionGroupDao.getPermissionGroupIdByName( - permissionGroup, - sqlClient - )!! - } - - val userPermissionGroupId = - databaseManager.userDao.getPermissionGroupIdFromUsername(username, sqlClient)!! - - if (userPermissionGroupId == -1L) { - databaseManager.userDao.setPermissionGroupByUsername( - permissionGroupId, - username, - sqlClient - ) - - return Successful() - } - - val userPermissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(userPermissionGroupId, sqlClient)!! - - if (userPermissionGroup.name == "admin") { - val count = databaseManager.userDao.getCountOfUsersByPermissionGroupId( - userPermissionGroupId, - sqlClient - ) - - val isAdmin = context.get("isAdmin") ?: false - - if (!isAdmin) { - throw NoPermission() - } - - if (count == 1L) { - throw Errors(mapOf("LAST_ADMIN" to true)) - } - } - - databaseManager.userDao.setPermissionGroupByUsername( - permissionGroupId, - username, - sqlClient - ) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelCreateOrUpdatePostAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelCreateOrUpdatePostAPI.kt deleted file mode 100644 index 9aa6231e..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelCreateOrUpdatePostAPI.kt +++ /dev/null @@ -1,137 +0,0 @@ -package com.panomc.platform.route.api.panel.post - -import com.panomc.platform.AppConstants - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Post -import com.panomc.platform.db.model.Post.Companion.deleteThumbnailFile -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import com.panomc.platform.util.FileUploadUtil -import com.panomc.platform.util.PostStatus -import com.panomc.platform.util.TextUtil -import io.vertx.ext.web.FileUpload -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.multipartFormData -import io.vertx.ext.web.validation.builder.Parameters.optionalParam -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* -import java.io.File - -@Endpoint -class PanelCreateOrUpdatePostAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider, - private val configManager: ConfigManager -) : PanelApi() { - override val paths = listOf( - Path("/api/panel/posts/:id", RouteType.PUT), - Path("/api/panel/post", RouteType.POST) - ) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(optionalParam("id", numberSchema())) - .body( - multipartFormData( - objectSchema() - .property("title", stringSchema()) - .property("category", numberSchema()) - .property("text", stringSchema()) - .optionalProperty("publish", booleanSchema()) - .optionalProperty("removeThumbnail", booleanSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_POSTS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val fileUploads = context.fileUploads() - - val id = parameters.pathParameter("id")?.long - val title = data.getString("title") - val categoryId = data.getLong("category") - val text = data.getString("text") - val removeThumbnail = data.getBoolean("removeThumbnail") ?: false - val publish = data.getBoolean("publish") ?: true - val url = TextUtil.convertStringToUrl(title, 32) - - var thumbnailUrl = "" - val body = mutableMapOf() - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - var postInDb: Post? = null - - if (id == null) { - thumbnailUrl = saveUploadedFileAndGetThumbnailUrl(fileUploads, null) - } else { - postInDb = databaseManager.postDao.getById(id, sqlClient) ?: throw NotExists() - - if (removeThumbnail) { - postInDb.deleteThumbnailFile(configManager) - } else { - thumbnailUrl = saveUploadedFileAndGetThumbnailUrl(fileUploads, postInDb) - } - } - - val post = Post( - id = id ?: -1, - title = title, - categoryId = categoryId, - writerUserId = userId, - text = text, - thumbnailUrl = thumbnailUrl, - status = if (postInDb == null) // when creating post first time - if (publish) - PostStatus.PUBLISHED - else // for save button - PostStatus.DRAFT - else // when the post is already exists - if (publish) - PostStatus.PUBLISHED - else // for save button - postInDb.status, - url = if (id == null) url else "$url-$id" - ) - - if (id == null) { - val postId = databaseManager.postDao.insert(post, sqlClient) - - databaseManager.postDao.updatePostUrlByUrl(url, "$url-$postId", sqlClient) - - body["id"] = postId - } else { - databaseManager.postDao.update(userId, post, sqlClient) - } - - return Successful(body) - } - - private fun saveUploadedFileAndGetThumbnailUrl(fileUploads: List, postInDb: Post?): String { - var thumbnailUrl = postInDb?.thumbnailUrl ?: "" - val savedFiles = FileUploadUtil.saveFiles(fileUploads, Post.acceptedFileFields, configManager) - - if (savedFiles.isNotEmpty()) { - postInDb?.deleteThumbnailFile(configManager) - - thumbnailUrl = AppConstants.POST_THUMBNAIL_URL_PREFIX + savedFiles[0].path.split(File.separator).last() - } - - return thumbnailUrl - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelDeletePostAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelDeletePostAPI.kt deleted file mode 100755 index 39dc0efa..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelDeletePostAPI.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.panomc.platform.route.api.panel.post - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Post.Companion.deleteThumbnailFile -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelDeletePostAPI( - private val databaseManager: DatabaseManager, - private val configManager: ConfigManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/posts/:id", RouteType.DELETE)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_POSTS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val exists = databaseManager.postDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - val post = databaseManager.postDao.getById(id, sqlClient)!! - - post.deleteThumbnailFile(configManager) - - databaseManager.postDao.delete(id, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostAPI.kt deleted file mode 100755 index 59243926..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostAPI.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.panomc.platform.route.api.panel.post - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.PostNotFound -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelGetPostAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/posts/:id", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_POSTS, context) - - val parameters = getParameters(context) - - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val exists = databaseManager.postDao.existsById(id, sqlClient) - - if (!exists) { - throw PostNotFound() - } - - val post = databaseManager.postDao.getById(id, sqlClient)!! - - return Successful( - mapOf( - "post" to mapOf( - "id" to post.id, - "title" to post.title, - "category" to post.categoryId, - "writerUserId" to post.writerUserId, - "text" to post.text, - "date" to post.date, - "status" to post.status, - "thumbnailUrl" to post.thumbnailUrl, - "views" to post.views - ) - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostCategoriesAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostCategoriesAPI.kt deleted file mode 100755 index 9bb3adac..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostCategoriesAPI.kt +++ /dev/null @@ -1,112 +0,0 @@ -package com.panomc.platform.route.api.panel.post - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Post -import com.panomc.platform.db.model.PostCategory -import com.panomc.platform.error.PageNotFound -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.optionalParam -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema -import kotlin.math.ceil - -@Endpoint -class PanelGetPostCategoriesAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/post/categories", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter(optionalParam("page", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_POSTS, context) - - val parameters = getParameters(context) - - val page = parameters.queryParameter("page")?.long ?: 1L - - val sqlClient = getSqlClient() - - val count = databaseManager.postCategoryDao.getCount(sqlClient) - - var totalPage = ceil(count.toDouble() / 10).toLong() - - if (totalPage < 1) - totalPage = 1 - - if (page > totalPage || page < 1) { - throw PageNotFound() - } - - val categories = databaseManager.postCategoryDao.getCategories(page, sqlClient) - - val categoryDataList = mutableListOf>() - - if (categories.isEmpty()) { - return getResult(categoryDataList, count, totalPage) - } - - val addCategoryToList = - { category: PostCategory, count: Long, categoryDataList: MutableList>, posts: List -> - val postsDataList = mutableListOf>() - - posts.forEach { post -> - postsDataList.add( - mapOf( - "id" to post.id, - "title" to post.title - ) - ) - } - - categoryDataList.add( - mapOf( - "id" to category.id, - "title" to category.title, - "description" to category.description, - "url" to category.url, - "color" to category.color, - "postCount" to count, - "posts" to postsDataList - ) - ) - } - - val getCategoryData: suspend (PostCategory) -> Unit = { category -> - val count = databaseManager.postDao.countByCategory(category.id, sqlClient) - val posts = databaseManager.postDao.getByCategory(category.id, sqlClient) - - addCategoryToList(category, count, categoryDataList, posts) - } - - categories.forEach { - getCategoryData(it) - } - - return getResult(categoryDataList, count, totalPage) - } - - private fun getResult( - categoryDataList: MutableList>, - count: Long, - totalPage: Long - ) = Successful( - mutableMapOf( - "categories" to categoryDataList, - "categoryCount" to count, - "totalPage" to totalPage, - "host" to "http://" - ) - ) -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostsAPI.kt deleted file mode 100755 index edbb0c04..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelGetPostsAPI.kt +++ /dev/null @@ -1,160 +0,0 @@ -package com.panomc.platform.route.api.panel.post - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Post -import com.panomc.platform.db.model.PostCategory -import com.panomc.platform.error.CategoryNotExists -import com.panomc.platform.error.PageNotFound -import com.panomc.platform.model.* -import com.panomc.platform.util.PostStatus -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.optionalParam -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* -import kotlin.math.ceil - -@Endpoint -class PanelGetPostsAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/posts", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter( - optionalParam( - "pageType", - arraySchema() - .items(enumSchema(*PostStatus.entries.map { it.name }.toTypedArray())) - ) - ) - .queryParameter(optionalParam("page", numberSchema())) - .queryParameter(optionalParam("categoryUrl", stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_POSTS, context) - - val parameters = getParameters(context) - - val pageType = - PostStatus.valueOf( - parameters.queryParameter("pageType")?.jsonArray?.first() as String? ?: PostStatus.PUBLISHED.name - ) - val page = parameters.queryParameter("page")?.long ?: 1L - val categoryUrl = parameters.queryParameter("categoryUrl")?.string - - var postCategory: PostCategory? = null - - val sqlClient = getSqlClient() - - if (categoryUrl != null && categoryUrl != "-") { - val isPostCategoryExists = databaseManager.postCategoryDao.existsByUrl(categoryUrl, sqlClient) - - if (!isPostCategoryExists) { - throw CategoryNotExists() - } - - postCategory = databaseManager.postCategoryDao.getByUrl(categoryUrl, sqlClient)!! - } - - if (categoryUrl != null && categoryUrl == "-") { - postCategory = PostCategory() - } - - val count = if (postCategory != null) - databaseManager.postDao.countByPageTypeAndCategoryId(pageType, postCategory.id, sqlClient) - else - databaseManager.postDao.countByPageType(pageType, sqlClient) - - var totalPage = ceil(count.toDouble() / 10).toLong() - - if (totalPage < 1) - totalPage = 1 - - if (page > totalPage || page < 1) { - throw PageNotFound() - } - - val posts = if (postCategory != null) - databaseManager.postDao.getByPagePageTypeAndCategoryId(page, pageType, postCategory.id, sqlClient) - else - databaseManager.postDao.getByPageAndPageType(page, pageType, sqlClient) - - if (posts.isEmpty()) { - return getResults(postCategory, posts, mapOf(), mapOf(), count, totalPage) - } - - val userIdList = posts.distinctBy { it.writerUserId }.map { it.writerUserId }.filter { it != -1L } - - val usernameList = databaseManager.userDao.getUsernameByListOfId(userIdList, sqlClient) - - if (postCategory != null) { - return getResults(postCategory, posts, usernameList, mapOf(), count, totalPage) - } - - val categoryIdList = posts.filter { it.categoryId != -1L }.distinctBy { it.categoryId }.map { it.categoryId } - - if (categoryIdList.isEmpty()) { - return getResults(null, posts, usernameList, mapOf(), count, totalPage) - } - - val categories = databaseManager.postCategoryDao.getByIdList(categoryIdList, sqlClient) - - return getResults(null, posts, usernameList, categories, count, totalPage) - } - - private fun getResults( - postCategory: PostCategory?, - posts: List, - usernameList: Map, - categories: Map, - count: Long, - totalPage: Long - ): Result { - val postsDataList = mutableListOf>() - - posts.forEach { post -> - postsDataList.add( - mapOf( - "id" to post.id, - "title" to post.title, - "category" to - (postCategory - ?: if (post.categoryId == -1L) - mapOf("id" to -1, "title" to "-", "url" to "-") - else - categories.getOrDefault( - post.categoryId, - mapOf("id" to -1, "title" to "-", "url" to "-") - )), - "writer" to mapOf( - "username" to (usernameList[post.writerUserId] ?: "-") - ), - "date" to post.date, - "views" to post.views, - "status" to post.status - ) - ) - } - - val result = mutableMapOf( - "posts" to postsDataList, - "postCount" to count, - "totalPage" to totalPage - ) - - if (postCategory != null) { - result["category"] = postCategory - } - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelUpdatePostStatusAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelUpdatePostStatusAPI.kt deleted file mode 100755 index 39ebaf67..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/post/PanelUpdatePostStatusAPI.kt +++ /dev/null @@ -1,72 +0,0 @@ -package com.panomc.platform.route.api.panel.post - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import com.panomc.platform.util.TicketStatus -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class PanelUpdatePostStatusAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/posts/:id/status", RouteType.PUT)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("id", numberSchema())) - .body( - json( - objectSchema() - .property("to", enumSchema(*TicketStatus.entries.map { it.name }.toTypedArray())) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_POSTS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val id = parameters.pathParameter("id").long - val moveTo = data.getString("to") - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.postDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - if (moveTo == "trash") { - databaseManager.postDao.moveTrashById(id, sqlClient) - } - - if (moveTo == "draft") { - databaseManager.postDao.moveDraftById(id, sqlClient) - } - - if (moveTo == "publish") { - databaseManager.postDao.publishById(id, userId, sqlClient) - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelAddPostCategoryAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelAddPostCategoryAPI.kt deleted file mode 100755 index 34b2ed56..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelAddPostCategoryAPI.kt +++ /dev/null @@ -1,101 +0,0 @@ -package com.panomc.platform.route.api.panel.post.category - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.PostCategory -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.objectSchema -import io.vertx.json.schema.common.dsl.Schemas.stringSchema - -@Endpoint -class PanelAddPostCategoryAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/post/category", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - json( - objectSchema() - .property("title", stringSchema()) - .property("description", stringSchema()) - .property("url", stringSchema()) - .optionalProperty("color", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_POSTS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val title = data.getString("title") - val description = data.getString("description") - val url = data.getString("url") - val color = data.getString("color") ?: "#1976d2" - - validateForm(title, url, color) - - val sqlClient = getSqlClient() - - val exists = databaseManager.postCategoryDao.existsByUrl(url, sqlClient) - - if (exists) { - val errors = mutableMapOf() - - errors["url"] = true - - throw Errors(errors) - } - - val id = databaseManager.postCategoryDao.add( - PostCategory(title = title, description = description, url = url, color = color), - sqlClient - ) - - return Successful( - mapOf( - "id" to id - ) - ) - } - - private fun validateForm( - title: String, -// description: String, - url: String, - color: String - ) { -// if (color.length != 7) { -// throw Error(ErrorCode.UNKNOWN) -// } - - val errors = mutableMapOf() - - if (title.isEmpty() || title.length > 32) - errors["title"] = true - -// if (description.isEmpty()) -// errors["description"] = true - - if (url.isEmpty() || url.length < 3 || url.length > 32 || !url.matches(Regex("^[a-zA-Z0-9-]+\$"))) - errors["url"] = true - - if (errors.isNotEmpty()) { - throw Errors(errors) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelDeletePostCategoryAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelDeletePostCategoryAPI.kt deleted file mode 100755 index 5537b94a..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelDeletePostCategoryAPI.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.panomc.platform.route.api.panel.post.category - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelDeletePostCategoryAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/post/categories/:id", RouteType.DELETE)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_POSTS, context) - - val parameters = getParameters(context) - - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val exists = databaseManager.postCategoryDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - databaseManager.postDao.removePostCategoriesByCategoryId(id, sqlClient) - - databaseManager.postCategoryDao.deleteById(id, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelUpdatePostCategoryAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelUpdatePostCategoryAPI.kt deleted file mode 100755 index 46357eee..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/post/category/PanelUpdatePostCategoryAPI.kt +++ /dev/null @@ -1,101 +0,0 @@ -package com.panomc.platform.route.api.panel.post.category - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.PostCategory -import com.panomc.platform.error.NoPermission -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class PanelUpdatePostCategoryAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/post/categories/:id", RouteType.PUT)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .body( - json( - objectSchema() - .property("title", stringSchema()) - .property("description", stringSchema()) - .property("url", stringSchema()) - .property("color", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_POSTS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val id = parameters.pathParameter("id").long - val title = data.getString("title") - val description = data.getString("description") - val url = data.getString("url") - val color = data.getString("color") - - validateForm(title, url, color) - - val sqlClient = getSqlClient() - - val exists = databaseManager.postCategoryDao.existsByUrlNotById(url, id, sqlClient) - - if (exists) { - val errors = mutableMapOf() - - errors["url"] = true - - throw Errors(errors) - } - - databaseManager.postCategoryDao.update( - PostCategory(id, title, description, url, color), - sqlClient - ) - - return Successful() - } - - private fun validateForm( - title: String, -// description: String, - url: String, - color: String - ) { - if (color.length != 7) { - throw NoPermission() - } - - val errors = mutableMapOf() - - if (title.isEmpty() || title.length > 32) - errors["title"] = true - -// if (description.isEmpty()) -// errors["description"] = true - - if (url.isEmpty() || url.length < 3 || url.length > 32 || !url.matches(Regex("^[a-zA-Z0-9-]+\$"))) - errors["url"] = true - - if (errors.isNotEmpty()) { - throw Errors(errors) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelAcceptServerConnectRequestAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelAcceptServerConnectRequestAPI.kt deleted file mode 100755 index 72d79f43..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelAcceptServerConnectRequestAPI.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.panomc.platform.route.api.panel.server - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelAcceptServerConnectRequestAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/servers/:id/accept", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_SERVERS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val exists = databaseManager.serverDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - databaseManager.serverDao.updatePermissionGrantedById(id, true, sqlClient) - databaseManager.serverDao.updateAcceptedTimeById(id, System.currentTimeMillis(), sqlClient) - - val mainServerId = databaseManager.systemPropertyDao.getByOption( - "main_server", - sqlClient - )!!.value.toLong() - - if (mainServerId == -1L) { - databaseManager.systemPropertyDao.update( - "main_server", - id.toString(), - sqlClient - ) - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelDeleteServerAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelDeleteServerAPI.kt deleted file mode 100755 index bad1315c..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelDeleteServerAPI.kt +++ /dev/null @@ -1,92 +0,0 @@ -package com.panomc.platform.route.api.panel.server - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.CurrentPasswordNotCorrect -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import com.panomc.platform.server.ServerManager -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas -import io.vertx.json.schema.common.dsl.Schemas.numberSchema -import org.apache.commons.codec.digest.DigestUtils - -@Endpoint -class PanelDeleteServerAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider, - private val serverManager: ServerManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/servers/:id/delete", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .body( - Bodies.json( - Schemas.objectSchema() - .property("currentPassword", Schemas.stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_SERVERS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val id = parameters.pathParameter("id").long - val currentPassword = data.getString("currentPassword") - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.serverDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - val isCurrentPasswordCorrect = - databaseManager.userDao.isPasswordCorrectWithId(userId, DigestUtils.md5Hex(currentPassword), sqlClient) - - if (!isCurrentPasswordCorrect) { - throw CurrentPasswordNotCorrect() - } - - serverManager.getConnectedServers() - .filter { it.key.id == id } - .forEach { - it.value.close() - } - - val mainServerId = databaseManager.systemPropertyDao.getByOption( - "main_server", - sqlClient - )!!.value.toLong() - - if (mainServerId == id) { - databaseManager.systemPropertyDao.update( - "main_server", - "-1", - sqlClient - ) - } - - databaseManager.serverPlayerDao.deleteByServerId(id, sqlClient) - - databaseManager.serverDao.deleteById(id, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetConnectedServersAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetConnectedServersAPI.kt deleted file mode 100755 index 3f68c67c..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetConnectedServersAPI.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.panomc.platform.route.api.panel.server - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelGetConnectedServersAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/servers", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_SERVERS, context) - - val sqlClient = getSqlClient() - - val servers = databaseManager.serverDao.getAllByPermissionGranted(sqlClient) - - return Successful( - mapOf( - "servers" to servers - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetServerAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetServerAPI.kt deleted file mode 100755 index 595d26d8..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetServerAPI.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.panomc.platform.route.api.panel.server - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelGetServerAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/servers/:id", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_SERVERS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val server = databaseManager.serverDao.getById(id, sqlClient) ?: throw NotExists() - - return Successful( - mapOf( - "server" to server - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetServerDashboardAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetServerDashboardAPI.kt deleted file mode 100755 index a340b546..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelGetServerDashboardAPI.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.panomc.platform.route.api.panel.server - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class PanelGetServerDashboardAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/servers/:id/dashboard", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_SERVERS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - - val result = mutableMapOf( - "server" to null, - "connectedServerCount" to 0 - ) - - val sqlClient = getSqlClient() - - result["server"] = databaseManager.serverDao.getById(id, sqlClient) ?: throw NotExists() - - result["connectedServerCount"] = databaseManager.serverDao.countOfPermissionGranted(sqlClient) - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelMakeMainServerAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelMakeMainServerAPI.kt deleted file mode 100755 index bded3bca..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelMakeMainServerAPI.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.panomc.platform.route.api.panel.server - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelMakeMainServerAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/servers/:id/main", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_SERVERS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val exists = databaseManager.serverDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - databaseManager.systemPropertyDao.update( - "main_server", - id.toString(), - sqlClient - ) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelRejectServerConnectRequestAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelRejectServerConnectRequestAPI.kt deleted file mode 100755 index a4ba1bef..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelRejectServerConnectRequestAPI.kt +++ /dev/null @@ -1,53 +0,0 @@ -package com.panomc.platform.route.api.panel.server - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import com.panomc.platform.server.ServerManager -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelRejectServerConnectRequestAPI( - private val databaseManager: DatabaseManager, - private val serverManager: ServerManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/servers/:id/reject", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_SERVERS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val exists = databaseManager.serverDao.existsById(id, sqlClient) - - if (!exists) { - return NotExists() - } - - if (serverManager.isConnected(id)) { - serverManager.closeConnection(id) - } - - databaseManager.serverDao.deleteById(id, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelSelectServerAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelSelectServerAPI.kt deleted file mode 100755 index 27cc9d4d..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/server/PanelSelectServerAPI.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.panomc.platform.route.api.panel.server - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.PanelConfig -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelSelectServerAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/servers/:id/select", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_SERVERS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.serverDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - val panelConfig = databaseManager.panelConfigDao.byUserIdAndOption(userId, "selected_server", sqlClient) - - if (panelConfig == null) { - databaseManager.panelConfigDao.add( - PanelConfig( - userId = userId, - option = "selected_server", - value = "$id" - ), - sqlClient - ) - } else { - databaseManager.panelConfigDao.updateValueById(panelConfig.id, "$id", sqlClient) - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelGetAboutAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelGetAboutAPI.kt deleted file mode 100755 index 88b5e092..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelGetAboutAPI.kt +++ /dev/null @@ -1,31 +0,0 @@ -package com.panomc.platform.route.api.panel.settings - -import com.panomc.platform.Main -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser - -@Endpoint -class PanelGetAboutAPI(private val authProvider: AuthProvider) : PanelApi() { - override val paths = listOf(Path("/api/panel/settings/about", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PLATFORM_SETTINGS, context) - - val result = mutableMapOf() - - result["platformVersion"] = Main.VERSION - result["platformStage"] = Main.STAGE.toString() - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelGetSettingsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelGetSettingsAPI.kt deleted file mode 100755 index cc1877b6..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelGetSettingsAPI.kt +++ /dev/null @@ -1,70 +0,0 @@ -package com.panomc.platform.route.api.panel.settings - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.arraySchema -import io.vertx.json.schema.common.dsl.Schemas.enumSchema - -@Endpoint -class PanelGetSettingsAPI( - private val configManager: ConfigManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/settings", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter( - param("type", arraySchema().items(enumSchema(*SettingType.values().map { it.type }.toTypedArray()))) - ) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PLATFORM_SETTINGS, context) - - val parameters = getParameters(context) - - val settingType = - SettingType.valueOf(type = parameters.queryParameter("type")?.jsonArray?.first() as String?) - - val result = mutableMapOf() - - if (settingType == SettingType.GENERAL) { - result["updatePeriod"] = configManager.getConfig().getString("update-period") - result["locale"] = configManager.getConfig().getString("locale") - } - - if (settingType == SettingType.WEBSITE) { - result["websiteName"] = configManager.getConfig().getString("website-name") - result["websiteDescription"] = configManager.getConfig().getString("website-description") - result["supportEmail"] = configManager.getConfig().getString("support-email") - result["serverIpAddress"] = configManager.getConfig().getString("server-ip-address") - result["serverGameVersion"] = configManager.getConfig().getString("server-game-version") - result["keywords"] = configManager.getConfig().getJsonArray("keywords") - } - - return Successful(result) - } - - enum class SettingType(val type: String, val value: Int) { - GENERAL("general", 0), - WEBSITE("website", 1); - - override fun toString(): String { - return type - } - - companion object { - fun valueOf(type: String?) = values().find { it.type == type } - fun valueOf(value: Int) = values().find { it.value == value } - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelUpdateSettingAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelUpdateSettingAPI.kt deleted file mode 100755 index a025a392..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/settings/PanelUpdateSettingAPI.kt +++ /dev/null @@ -1,168 +0,0 @@ -package com.panomc.platform.route.api.panel.settings - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.error.FaviconExceedsSize -import com.panomc.platform.error.FaviconWrongContentType -import com.panomc.platform.error.WebsiteLogoExceedsSize -import com.panomc.platform.error.WebsiteLogoWrongContentType -import com.panomc.platform.model.* -import com.panomc.platform.util.FileUploadUtil -import com.panomc.platform.util.UpdatePeriod -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* -import java.io.File - -@Endpoint -class PanelUpdateSettingAPI( - private val configManager: ConfigManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/settings", RouteType.PUT)) - - private val defaultWebsiteUploadPath = "website" - - private val acceptedFileFields = listOf( - FileUploadUtil.Field( - name = "favicon", - fieldConfig = FileUploadUtil.FieldConfig( - path = "$defaultWebsiteUploadPath/favicon", - acceptedContentTypes = listOf( - "image/x-icon", - "image/vnd.microsoft.icon", - "image/svg+xml", - "image/png", - "image/gif", - "image/jpeg" - ), - contentTypeError = FaviconWrongContentType(), - fileSizeError = FaviconExceedsSize(), - withTempName = false, - size = 1024 * 1024 // 1 MB - ) - ), - FileUploadUtil.Field( - name = "websiteLogo", - fieldConfig = FileUploadUtil.FieldConfig( - path = "$defaultWebsiteUploadPath/website-logo", - acceptedContentTypes = listOf( - "image/png", - "image/jpeg", - "image/gif", - "image/svg+xml", - ), - contentTypeError = WebsiteLogoWrongContentType(), - fileSizeError = WebsiteLogoExceedsSize(), - withTempName = false, - size = 2 * 1024 * 1024 // 2 MB - ) - ) - ) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.multipartFormData( - objectSchema() - .optionalProperty( - "updatePeriod", - enumSchema(*UpdatePeriod.values().map { it.period }.toTypedArray()) - ) - .optionalProperty("locale", stringSchema()) - .optionalProperty("websiteName", stringSchema()) - .optionalProperty("websiteDescription", stringSchema()) - .optionalProperty("supportEmail", stringSchema()) - .optionalProperty("serverIpAddress", stringSchema()) - .optionalProperty("serverGameVersion", stringSchema()) - .optionalProperty("keywords", arraySchema().items(stringSchema())) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_PLATFORM_SETTINGS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val fileUploads = context.fileUploads() - - val updatePeriod = UpdatePeriod.valueOf(period = data.getString("updatePeriod")) - val locale = data.getString("locale") - val websiteName = data.getString("websiteName") - val websiteDescription = data.getString("websiteDescription") - val supportEmail = data.getString("supportEmail") - val serverIpAddress = data.getString("serverIpAddress") - val serverGameVersion = data.getString("serverGameVersion") - val keywords = data.getJsonArray("keywords") - - if (fileUploads.size > 0) { - val savedFiles = FileUploadUtil.saveFiles(fileUploads, acceptedFileFields, configManager) - - savedFiles.forEach { savedFile -> - val filePathsInConfig = configManager.getConfig().getJsonObject("file-paths") - - if (filePathsInConfig.getString(savedFile.field.name) != savedFile.path) { - val oldFile = File( - configManager.getConfig() - .getString("file-uploads-folder") + File.separator + filePathsInConfig.getString( - savedFile.field.name - ) - ) - - if (oldFile.exists()) { - oldFile.delete() - } - } - - filePathsInConfig.put(savedFile.field.name, savedFile.path) - } - } - - if (updatePeriod != null) { - configManager.getConfig().put("update-period", updatePeriod.period) - } - - if (locale != null) { - configManager.getConfig().put("locale", locale) - } - - if (websiteName != null) { - configManager.getConfig().put("website-name", websiteName) - } - - if (websiteDescription != null) { - configManager.getConfig().put("website-description", websiteDescription) - } - - if (supportEmail != null) { - configManager.getConfig().put("support-email", supportEmail) - } - - if (serverIpAddress != null) { - configManager.getConfig().put("server-ip-address", serverIpAddress) - } - - if (serverGameVersion != null) { - configManager.getConfig().put("server-game-version", serverGameVersion) - } - - if (keywords != null) { - configManager.getConfig().put("keywords", keywords) - } - - if (updatePeriod != null || websiteName != null || websiteDescription != null || keywords != null) { - configManager.saveConfig() - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelDeleteTicketsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelDeleteTicketsAPI.kt deleted file mode 100755 index 82c77231..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelDeleteTicketsAPI.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.optionalParam -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.arraySchema -import io.vertx.json.schema.common.dsl.Schemas.intSchema - -@Endpoint -class PanelDeleteTicketsAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/tickets", RouteType.DELETE)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter( - optionalParam("ids", arraySchema().items(intSchema())) - ) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - val selectedTickets = parameters.queryParameter("ids").jsonArray - - if (selectedTickets.isEmpty) { - return Successful() - } - - val sqlClient = getSqlClient() - - databaseManager.ticketDao.delete(selectedTickets, sqlClient) - - databaseManager.ticketMessageDao.deleteByTicketIdList(selectedTickets, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketAPI.kt deleted file mode 100755 index bce6e53c..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketAPI.kt +++ /dev/null @@ -1,114 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Ticket -import com.panomc.platform.db.model.TicketCategory -import com.panomc.platform.db.model.TicketMessage -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelGetTicketAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/tickets/:id", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val exists = databaseManager.ticketDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - val ticket = databaseManager.ticketDao.getById(id, sqlClient)!! - - val username = databaseManager.userDao.getUsernameFromUserId(ticket.userId, sqlClient)!! - - val messages = databaseManager.ticketMessageDao.getByTicketId(id, sqlClient) - - val userIdList = mutableListOf() - - messages - .filter { ticketMessage -> ticketMessage.userId != -1L } - .forEach { message -> - if (userIdList.indexOf(message.userId) == -1) - userIdList.add(message.userId) - } - - val usernameList = databaseManager.userDao.getUsernameByListOfId(userIdList, sqlClient) - - val count = databaseManager.ticketMessageDao.getCountByTicketId(ticket.id, sqlClient) - - if (ticket.categoryId == -1L) { - return getResult(ticket, usernameList, null, username, messages, count) - } - - val ticketCategory = databaseManager.ticketCategoryDao.getById(ticket.categoryId, sqlClient) - - return getResult(ticket, usernameList, ticketCategory, username, messages, count) - } - - private fun getResult( - ticket: Ticket, - usernameList: Map, - ticketCategory: TicketCategory?, - username: String, - ticketMessages: List, - messageCount: Long - ): Result { - val messages = mutableListOf>() - - ticketMessages.forEach { ticketMessage -> - messages.add( - 0, - mapOf( - "id" to ticketMessage.id, - "userId" to ticketMessage.userId, - "ticketId" to ticketMessage.ticketId, - "username" to (usernameList[ticketMessage.userId] ?: "-"), - "message" to ticketMessage.message, - "date" to ticketMessage.date, - "panel" to ticketMessage.panel - ) - ) - } - - return Successful( - mapOf( - "ticket" to mapOf( - "username" to username, - "title" to ticket.title, - "category" to - (ticketCategory ?: TicketCategory()), - "messages" to messages, - "status" to ticket.status, - "date" to ticket.date, - "count" to messageCount - ) - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketMessagesAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketMessagesAPI.kt deleted file mode 100755 index ab242d0f..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketMessagesAPI.kt +++ /dev/null @@ -1,88 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelGetTicketMessagesAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/tickets/:id/messages", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .queryParameter(param("lastMessageId", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - val lastMessageId = parameters.queryParameter("lastMessageId").long - - val sqlClient = getSqlClient() - - val exists = databaseManager.ticketDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - val isTicketMessageIdExists = databaseManager.ticketMessageDao.existsById(lastMessageId, sqlClient) - - if (!isTicketMessageIdExists) { - throw NotExists() - } - - val ticketMessages = - databaseManager.ticketMessageDao.getByTicketIdAndStartFromId(lastMessageId, id, sqlClient) - - val userIdList = mutableListOf() - - ticketMessages - .filter { ticketMessage -> ticketMessage.userId != -1L } - .forEach { message -> - if (userIdList.indexOf(message.userId) == -1) - userIdList.add(message.userId) - } - - val usernameList = databaseManager.userDao.getUsernameByListOfId(userIdList, sqlClient) - - val messages = mutableListOf>() - - ticketMessages.forEach { ticketMessage -> - messages.add( - 0, - mapOf( - "id" to ticketMessage.id, - "userId" to ticketMessage.userId, - "ticketId" to ticketMessage.ticketId, - "username" to (usernameList[ticketMessage.userId] ?: "-"), - "message" to ticketMessage.message, - "date" to ticketMessage.date, - "panel" to ticketMessage.panel - ) - ) - } - - return Successful( - mapOf( - "messages" to messages - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketsAPI.kt deleted file mode 100755 index c2f2deec..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelGetTicketsAPI.kt +++ /dev/null @@ -1,159 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Ticket -import com.panomc.platform.db.model.TicketCategory -import com.panomc.platform.error.NotExists -import com.panomc.platform.error.PageNotFound -import com.panomc.platform.model.* -import com.panomc.platform.util.TicketPageType -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.optionalParam -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* -import kotlin.math.ceil - -@Endpoint -class PanelGetTicketsAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/tickets", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter( - optionalParam( - "pageType", arraySchema().items(enumSchema(*TicketPageType.entries.map { it.name }.toTypedArray())) - ) - ) - .queryParameter(optionalParam("page", numberSchema())) - .queryParameter(optionalParam("categoryUrl", stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - - val pageType = - TicketPageType.valueOf( - parameters.queryParameter("pageType")?.jsonArray?.first() as String? ?: TicketPageType.ALL.name - ) - val page = parameters.queryParameter("page")?.long ?: 1L - val categoryUrl = parameters.queryParameter("categoryUrl")?.string - - var ticketCategory: TicketCategory? = null - - val sqlClient = getSqlClient() - - if (categoryUrl != null && categoryUrl != "-") { - val exists = databaseManager.ticketCategoryDao.existsByUrl( - categoryUrl, - sqlClient - ) - - if (!exists) { - throw NotExists() - } - - ticketCategory = databaseManager.ticketCategoryDao.getByUrl(categoryUrl, sqlClient)!! - } - - if (categoryUrl != null && categoryUrl == "-") { - ticketCategory = TicketCategory() - } - - val count = if (ticketCategory != null) - databaseManager.ticketDao.countByCategory(ticketCategory.id, sqlClient) - else - databaseManager.ticketDao.getCountByPageType(pageType, sqlClient) - - var totalPage = ceil(count.toDouble() / 10).toLong() - - if (totalPage < 1) - totalPage = 1 - - if (page > totalPage || page < 1) { - throw PageNotFound() - } - - val tickets = if (ticketCategory != null) - databaseManager.ticketDao.getAllByPageAndCategoryId(page, ticketCategory.id, sqlClient) - else - databaseManager.ticketDao.getAllByPageAndPageType(page, pageType, sqlClient) - - if (tickets.isEmpty()) { - return getResults(ticketCategory, tickets, mapOf(), mapOf(), count, totalPage) - } - - val userIdList = tickets.distinctBy { it.userId }.map { it.userId } - - val usernameList = databaseManager.userDao.getUsernameByListOfId(userIdList, sqlClient) - - if (ticketCategory != null) { - return getResults(ticketCategory, tickets, mapOf(), usernameList, count, totalPage) - } - - val categoryIdList = - tickets.filter { it.categoryId != -1L }.distinctBy { it.categoryId }.map { it.categoryId } - - if (categoryIdList.isEmpty()) { - return getResults(null, tickets, mapOf(), usernameList, count, totalPage) - } - - val ticketCategoryList = databaseManager.ticketCategoryDao.getByIdList(categoryIdList, sqlClient) - - return getResults(null, tickets, ticketCategoryList, usernameList, count, totalPage) - } - - private fun getResults( - ticketCategory: TicketCategory?, - tickets: List, - ticketCategoryList: Map, - usernameList: Map, - count: Long, - totalPage: Long - ): Result { - val ticketDataList = mutableListOf>() - - tickets.forEach { ticket -> - ticketDataList.add( - mapOf( - "id" to ticket.id, - "title" to ticket.title, - "category" to (ticketCategory ?: if (ticket.categoryId == -1L) - mapOf("id" to -1, "title" to "-", "url" to "-") - else - ticketCategoryList.getOrDefault( - ticket.categoryId, - mapOf("id" to -1, "title" to "-", "url" to "-") - )), - "writer" to mapOf( - "username" to usernameList[ticket.userId] - ), - "date" to ticket.date, - "lastUpdate" to ticket.lastUpdate, - "status" to ticket.status - ) - ) - } - - val result = mutableMapOf( - "tickets" to ticketDataList, - "ticketCount" to count, - "totalPage" to totalPage - ) - - if (ticketCategory != null) { - result["category"] = ticketCategory - } - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelSendTicketMessageAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelSendTicketMessageAPI.kt deleted file mode 100755 index ad1c2753..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelSendTicketMessageAPI.kt +++ /dev/null @@ -1,104 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.TicketMessage -import com.panomc.platform.error.NotExists -import com.panomc.platform.error.TicketIsClosed -import com.panomc.platform.model.* -import com.panomc.platform.notification.NotificationManager -import com.panomc.platform.notification.Notifications -import com.panomc.platform.util.TicketStatus -import io.vertx.core.json.JsonObject -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class PanelSendTicketMessageAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager, - private val notificationManager: NotificationManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/tickets/:id/message", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .body( - json( - objectSchema() - .property("message", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val ticketId = parameters.pathParameter("id").long - val message = data.getString("message") - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val ticket = databaseManager.ticketDao.getById(ticketId, sqlClient) ?: throw NotExists() - - val isTicketClosed = databaseManager.ticketDao.getStatusById(ticketId, sqlClient) == TicketStatus.CLOSED - - if (isTicketClosed) { - throw TicketIsClosed() - } - - val username = databaseManager.userDao.getUsernameFromUserId(userId, sqlClient) - - val ticketMessage = TicketMessage(userId = userId, ticketId = ticketId, message = message, panel = 1) - - val messageId = databaseManager.ticketMessageDao.addMessage(ticketMessage, sqlClient) - - databaseManager.ticketDao.makeStatus(ticketId, TicketStatus.REPLIED, sqlClient) - - val notificationProperties = JsonObject() - .put("id", ticketId) - .put("whoReplied", username) - - notificationManager.sendNotification( - ticket.userId, - Notifications.UserNotificationType.AN_ADMIN_REPLIED_TICKET, - notificationProperties, - sqlClient - ) - - databaseManager.ticketDao.updateLastUpdateDate( - ticketMessage.ticketId, - System.currentTimeMillis(), - sqlClient - ) - - return Successful( - mapOf( - "message" to mapOf( - "id" to messageId, - "userId" to ticketMessage.userId, - "ticketId" to ticketMessage.ticketId, - "username" to username, - "message" to ticketMessage.message, - "date" to ticketMessage.date, - "panel" to ticketMessage.panel - ) - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelUpdateTicketsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelUpdateTicketsAPI.kt deleted file mode 100755 index d92660e2..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/PanelUpdateTicketsAPI.kt +++ /dev/null @@ -1,88 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.SomeTicketsArentExists -import com.panomc.platform.model.* -import com.panomc.platform.notification.NotificationManager -import com.panomc.platform.notification.Notifications -import com.panomc.platform.util.TicketStatus -import io.vertx.core.json.JsonObject -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class PanelUpdateTicketsAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider, - private val notificationManager: NotificationManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/tickets", RouteType.PUT)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - json( - objectSchema() - .property("tickets", arraySchema().items(numberSchema())) - .optionalProperty("status", enumSchema(*TicketStatus.entries.map { it.name }.toTypedArray())) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - val selectedTickets = data.getJsonArray("tickets") - val ticketStatus = - if (data.getString("status") == null) null else TicketStatus.valueOf(data.getString("status")) - - val userId = authProvider.getUserIdFromRoutingContext(context) - - if (selectedTickets.isEmpty) { - return Successful() - } - - if (ticketStatus != null && ticketStatus == TicketStatus.CLOSED) { - val sqlClient = getSqlClient() - - val areIdListExist = - databaseManager.ticketDao.areIdListExist(selectedTickets.map { it.toString().toLong() }, sqlClient) - - if (!areIdListExist) { - throw SomeTicketsArentExists() - } - - databaseManager.ticketDao.closeTickets(selectedTickets, sqlClient) - - val username = databaseManager.userDao.getUsernameFromUserId(userId, sqlClient) - - selectedTickets.map { it.toString().toLong() }.forEach { - val ticket = databaseManager.ticketDao.getById(it, sqlClient)!! - - val notificationProperties = JsonObject() - .put("id", it) - .put("whoClosed", username) - - notificationManager.sendNotification( - ticket.userId, - Notifications.UserNotificationType.AN_ADMIN_CLOSED_TICKET, - notificationProperties, - sqlClient - ) - } - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelAddTicketCategoryAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelAddTicketCategoryAPI.kt deleted file mode 100755 index c77cc477..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelAddTicketCategoryAPI.kt +++ /dev/null @@ -1,79 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket.category - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.TicketCategory -import com.panomc.platform.model.* -import com.panomc.platform.util.TextUtil -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.objectSchema -import io.vertx.json.schema.common.dsl.Schemas.stringSchema - -@Endpoint -class PanelAddTicketCategoryAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/ticket/category", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - json( - objectSchema() - .property("title", stringSchema()) - .property("description", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val title = data.getString("title") - val description = data.getString("description") - - validateForm(title) - - val sqlClient = getSqlClient() - - val categoryId = databaseManager.ticketCategoryDao.add( - TicketCategory(title = title, description = description), - sqlClient - ) - - val url = TextUtil.convertStringToUrl(title, 32) - - databaseManager.ticketCategoryDao.updateUrlById(categoryId, "$url-$categoryId", sqlClient) - - return Successful() - } - - private fun validateForm( - title: String, -// description: String, - ) { - val errors = mutableMapOf() - - if (title.isEmpty() || title.length > 32) - errors["title"] = true - -// if (description.isEmpty()) -// errors["description"] = true - - if (errors.isNotEmpty()) { - throw Errors(errors) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelDeleteTicketCategoryAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelDeleteTicketCategoryAPI.kt deleted file mode 100755 index 8011510f..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelDeleteTicketCategoryAPI.kt +++ /dev/null @@ -1,49 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket.category - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class PanelDeleteTicketCategoryAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/ticket/categories/:id", RouteType.DELETE)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val exists = databaseManager.ticketCategoryDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - databaseManager.ticketDao.removeTicketCategoriesByCategoryId(id, sqlClient) - - databaseManager.ticketCategoryDao.deleteById(id, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelGetTicketCategoriesAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelGetTicketCategoriesAPI.kt deleted file mode 100755 index fa1138c4..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelGetTicketCategoriesAPI.kt +++ /dev/null @@ -1,112 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket.category - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Ticket -import com.panomc.platform.db.model.TicketCategory -import com.panomc.platform.error.PageNotFound -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas -import kotlin.math.ceil - -@Endpoint -class PanelGetTicketCategoriesAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/ticket/categories", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter(Parameters.optionalParam("page", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - val page = parameters.queryParameter("page")?.long ?: 1 - - val sqlClient = getSqlClient() - - val count = databaseManager.ticketCategoryDao.count(sqlClient) - - var totalPage = ceil(count.toDouble() / 10).toLong() - - if (totalPage < 1) - totalPage = 1 - - if (page > totalPage || page < 1) { - return PageNotFound() - } - - val categories = databaseManager.ticketCategoryDao.getByPage(page, sqlClient) - - val categoriesDataList = mutableListOf>() - - if (categories.isEmpty()) { - return getResult(categoriesDataList, count, totalPage) - } - - val addCategoryToList = - { category: TicketCategory, count: Long, categoryDataList: MutableList>, tickets: List -> - val ticketDataList = mutableListOf>() - - tickets.forEach { ticket -> - ticketDataList.add( - mapOf( - "id" to ticket.id, - "title" to ticket.title - ) - ) - } - - categoryDataList.add( - mapOf( - "id" to category.id, - "title" to category.title, - "description" to category.description, - "ticketCount" to count, - "tickets" to ticketDataList - ) - ) - } - - val getCategoryData: suspend (TicketCategory) -> Unit = { category -> - val count = databaseManager.ticketDao.countByCategory(category.id, sqlClient) - - val tickets = databaseManager.ticketDao.getByCategory(category.id, sqlClient) - - addCategoryToList(category, count, categoriesDataList, tickets) - } - - categories.forEach { - getCategoryData(it) - } - - return getResult(categoriesDataList, count, totalPage) - } - - private fun getResult( - categoryDataList: MutableList>, - count: Long, - totalPage: Long - ): Result { - return Successful( - mutableMapOf( - "categories" to categoryDataList, - "categoryCount" to count, - "totalPage" to totalPage, - "host" to "http://" - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelUpdateTicketCategoryAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelUpdateTicketCategoryAPI.kt deleted file mode 100755 index d91a8e5c..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/panel/ticket/category/PanelUpdateTicketCategoryAPI.kt +++ /dev/null @@ -1,86 +0,0 @@ -package com.panomc.platform.route.api.panel.ticket.category - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.TicketCategory -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import com.panomc.platform.util.TextUtil -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class PanelUpdateTicketCategoryAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : PanelApi() { - override val paths = listOf(Path("/api/panel/ticket/categories/:id", RouteType.PUT)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .body( - json( - objectSchema() - .property("title", stringSchema()) - .property("description", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - authProvider.requirePermission(PanelPermission.MANAGE_TICKETS, context) - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val id = parameters.pathParameter("id").long - val title = data.getString("title") - val description = data.getString("description") - - validateForm(title) - - val sqlClient = getSqlClient() - - val exists = databaseManager.ticketCategoryDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - databaseManager.ticketCategoryDao.update(TicketCategory(id, title, description), sqlClient) - - val url = TextUtil.convertStringToUrl(title, 32) - - databaseManager.ticketCategoryDao.updateUrlById(id, "$url-$id", sqlClient) - - return Successful() - } - - private fun validateForm( - title: String, -// description: String, - ) { - val errors = mutableMapOf() - - if (title.isEmpty() || title.length > 32) - errors["title"] = true - -// if (description.isEmpty()) -// errors["description"] = true - - if (errors.isNotEmpty()) { - throw Errors(errors) - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostDetailAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostDetailAPI.kt deleted file mode 100755 index 6bdf01ac..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostDetailAPI.kt +++ /dev/null @@ -1,114 +0,0 @@ -package com.panomc.platform.route.api.posts - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Post -import com.panomc.platform.db.model.PostCategory -import com.panomc.platform.error.PostNotFound -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.stringSchema - -@Endpoint -class GetPostDetailAPI( - private val databaseManager: DatabaseManager -) : Api() { - override val paths = listOf(Path("/api/posts/:url", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("url", stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val url = parameters.pathParameter("url").string - - val sqlClient = getSqlClient() - - val isPostExists = databaseManager.postDao.existsByUrl(url, sqlClient) - - if (!isPostExists) { - throw PostNotFound() - } - - databaseManager.postDao.increaseViewByOne(url, sqlClient) - - val post = databaseManager.postDao.getByUrl(url, sqlClient)!! - var postCategory: PostCategory? = null - - if (post.categoryId != -1L) { - postCategory = databaseManager.postCategoryDao.getById(post.categoryId, sqlClient) - } - - val username = if (post.writerUserId == -1L) - "-" - else - databaseManager.userDao.getUsernameFromUserId(post.writerUserId, sqlClient) - - var previousPost: Post? = null - var nextPost: Post? = null - - val isPreviousPostExists = databaseManager.postDao.isPreviousPostExistsByDate(post.date, sqlClient) - - if (isPreviousPostExists) { - previousPost = databaseManager.postDao.getPreviousPostByDate(post.date, sqlClient) - } - - val isNextPostExists = databaseManager.postDao.isNextPostExistsByDate(post.date, sqlClient) - - if (isNextPostExists) { - nextPost = databaseManager.postDao.getNextPostByDate(post.date, sqlClient) - } - - return Successful( - mapOf( - "post" to mapOf( - "id" to post.id, - "title" to post.title, - "category" to - if (postCategory == null) - mapOf("id" to -1, "title" to "-") - else - mapOf( - "title" to postCategory.title, - "url" to postCategory.url - ), - "writer" to mapOf( - "username" to username - ), - "text" to post.text, - "date" to post.date, - "status" to post.status, - "thumbnailUrl" to post.thumbnailUrl, - "views" to post.views, - "url" to post.url - ), - "previousPost" to - if (previousPost == null) - "-" - else - mapOf( - "id" to previousPost.id, - "title" to previousPost.title, - "url" to previousPost.url - ), - "nextPost" to - if (nextPost == null) - "-" - else - mapOf( - "id" to nextPost.id, - "title" to nextPost.title, - "url" to nextPost.url - ) - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostPreviewAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostPreviewAPI.kt deleted file mode 100755 index 0d309855..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostPreviewAPI.kt +++ /dev/null @@ -1,75 +0,0 @@ -package com.panomc.platform.route.api.posts - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.PostCategory -import com.panomc.platform.error.PostNotFound -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class GetPostPreviewAPI( - private val databaseManager: DatabaseManager -) : PanelApi() { - override val paths = listOf(Path("/api/panel/posts/:id/preview", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val id = parameters.pathParameter("id").long - - val sqlClient = getSqlClient() - - val isPostExistsById = databaseManager.postDao.existsById(id, sqlClient) - - if (!isPostExistsById) { - throw PostNotFound() - } - - val post = databaseManager.postDao.getById(id, sqlClient)!! - var postCategory: PostCategory? = null - - if (post.categoryId != -1L) { - postCategory = databaseManager.postCategoryDao.getById(post.categoryId, sqlClient)!! - } - - val username = if (post.writerUserId == -1L) - "-" - else - databaseManager.userDao.getUsernameFromUserId(post.writerUserId, sqlClient)!! - - return Successful( - mapOf( - "id" to post.id, - "title" to post.title, - "category" to - if (postCategory == null) - mapOf("id" to -1, "title" to "-") - else - mapOf( - "title" to postCategory.title, - "url" to postCategory.url - ), - "writer" to mapOf( - "username" to username - ), - "text" to post.text, - "date" to post.date, - "status" to post.status, - "thumbnailUrl" to post.thumbnailUrl, - "views" to post.views - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostsAPI.kt deleted file mode 100755 index ac471623..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostsAPI.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.panomc.platform.route.api.posts - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.model.Api -import com.panomc.platform.model.Path -import com.panomc.platform.model.Result -import com.panomc.platform.model.RouteType -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class GetPostsAPI( - private val getPostsService: GetPostsService -) : Api() { - override val paths = listOf(Path("/api/posts", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter(Parameters.optionalParam("page", Schemas.numberSchema())) - .queryParameter(Parameters.optionalParam("categoryUrl", Schemas.stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val sqlClient = getSqlClient() - - return getPostsService.handle(parameters, sqlClient) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostsService.kt b/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostsService.kt deleted file mode 100644 index 5cfe5510..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/posts/GetPostsService.kt +++ /dev/null @@ -1,128 +0,0 @@ -package com.panomc.platform.route.api.posts - - -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Post -import com.panomc.platform.db.model.PostCategory -import com.panomc.platform.error.CategoryNotExists -import com.panomc.platform.error.PageNotFound -import com.panomc.platform.model.Result -import com.panomc.platform.model.Successful -import io.vertx.ext.web.validation.RequestParameters -import io.vertx.sqlclient.SqlClient -import org.springframework.stereotype.Service -import util.StringUtil - -@Service -class GetPostsService(private val databaseManager: DatabaseManager) { - suspend fun handle(parameters: RequestParameters, sqlClient: SqlClient): Result { - val page = parameters.queryParameter("page")?.long ?: 1 - val categoryUrl = parameters.queryParameter("categoryUrl")?.string - - var postCategory: PostCategory? = null - - if (categoryUrl != null && categoryUrl != "-") { - val isPostCategoryExists = databaseManager.postCategoryDao.existsByUrl(categoryUrl, sqlClient) - - if (!isPostCategoryExists) { - throw CategoryNotExists() - } - - postCategory = databaseManager.postCategoryDao.getByUrl(categoryUrl, sqlClient)!! - } - - if (categoryUrl != null && categoryUrl == "-") { - postCategory = PostCategory() - } - - val count = if (postCategory != null) - databaseManager.postDao.countOfPublishedByCategoryId(postCategory.id, sqlClient) - else - databaseManager.postDao.countOfPublished(sqlClient) - - var totalPage = kotlin.math.ceil(count.toDouble() / 5).toLong() - - if (totalPage < 1) - totalPage = 1 - - if (page > totalPage || page < 1) { - throw PageNotFound() - } - - val posts = if (postCategory != null) - databaseManager.postDao.getPublishedListByPageAndCategoryId(postCategory.id, page, sqlClient) - else - databaseManager.postDao.getPublishedListByPage(page, sqlClient) - - if (posts.isEmpty()) { - return prepareResult(postCategory, posts, mapOf(), mapOf(), count, totalPage) - } - - val userIdList = posts.distinctBy { it.writerUserId }.map { it.writerUserId }.filter { it != -1L } - - val usernameList = databaseManager.userDao.getUsernameByListOfId(userIdList, sqlClient) - - if (postCategory != null) { - return prepareResult(postCategory, posts, usernameList, mapOf(), count, totalPage) - } - - val categoryIdList = - posts.filter { it.categoryId != -1L }.distinctBy { it.categoryId }.map { it.categoryId } - - if (categoryIdList.isEmpty()) { - return prepareResult(null, posts, usernameList, mapOf(), count, totalPage) - } - - val categories = databaseManager.postCategoryDao.getByIdList(categoryIdList, sqlClient) - - return prepareResult(null, posts, usernameList, categories, count, totalPage) - } - - private val prepareResult: ( - PostCategory?, - List, - Map, - Map, - Long, - Long - ) -> Successful = { postCategory, posts, usernameList, categories, count, totalPage -> - val postsDataList = mutableListOf>() - - posts.forEach { post -> - postsDataList.add( - mapOf( - "id" to post.id, - "title" to post.title, - "category" to - if (post.categoryId == -1L) - mapOf("id" to -1, "title" to "-") - else - categories.getOrDefault( - post.categoryId, - mapOf("id" to -1, "title" to "-") - ), - "text" to StringUtil.truncateHTML(post.text, 500, "…"), - "writer" to mapOf( - "username" to (usernameList[post.writerUserId] ?: "-") - ), - "date" to post.date, - "thumbnailUrl" to post.thumbnailUrl, - "views" to post.views, - "url" to post.url - ) - ) - } - - val data = mutableMapOf( - "posts" to postsDataList, - "postCount" to count, - "totalPage" to totalPage - ) - - if (postCategory != null) { - data["category"] = postCategory - } - - Successful(data) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/profile/ChangeEmailAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/profile/ChangeEmailAPI.kt deleted file mode 100644 index 9ed493be..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/profile/ChangeEmailAPI.kt +++ /dev/null @@ -1,90 +0,0 @@ -package com.panomc.platform.route.api.profile - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.CantChangeEmailWait15Minutes -import com.panomc.platform.error.CurrentPasswordNotCorrect -import com.panomc.platform.error.InvalidEmail -import com.panomc.platform.error.NewEmailExists -import com.panomc.platform.mail.MailManager -import com.panomc.platform.mail.mails.ChangeEmailMail -import com.panomc.platform.model.* -import com.panomc.platform.token.TokenType -import com.panomc.platform.util.Regexes -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.objectSchema -import io.vertx.json.schema.common.dsl.Schemas.stringSchema -import org.apache.commons.codec.digest.DigestUtils - -@Endpoint -class ChangeEmailAPI( - private val databaseManager: DatabaseManager, - private val mailManager: MailManager, - private val authProvider: AuthProvider -) : LoggedInApi() { - override val paths = listOf(Path("/api/profile/changeEmail", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - json( - objectSchema() - .property("currentPassword", stringSchema()) - .property("newEmail", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val currentPassword = data.getString("currentPassword") - val newEmail = data.getString("newEmail") - - if (!newEmail.matches(Regex(Regexes.EMAIL))) { - throw InvalidEmail() - } - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val lastToken = - databaseManager.tokenDao.getLastBySubjectAndType(userId.toString(), TokenType.CHANGE_EMAIL, sqlClient) - - if (lastToken != null) { - val fifteenMinutesLaterInMillis = lastToken.startDate + 15 * 60 * 1000 - - if (System.currentTimeMillis() < fifteenMinutesLaterInMillis) { - throw CantChangeEmailWait15Minutes() - } - } - - val isCurrentPasswordCorrect = - databaseManager.userDao.isPasswordCorrectWithId(userId, DigestUtils.md5Hex(currentPassword), sqlClient) - - if (!isCurrentPasswordCorrect) { - throw CurrentPasswordNotCorrect() - } - - val emailExists = databaseManager.userDao.isEmailExists(newEmail, sqlClient) - - if (emailExists) { - throw NewEmailExists() - } - - databaseManager.userDao.updatePendingEmailById(userId, newEmail, sqlClient) - - mailManager.sendMail(sqlClient, userId, ChangeEmailMail(), newEmail) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/profile/GetPlayerProfileAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/profile/GetPlayerProfileAPI.kt deleted file mode 100644 index 5577aa52..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/profile/GetPlayerProfileAPI.kt +++ /dev/null @@ -1,41 +0,0 @@ -package com.panomc.platform.route.api.profile - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class GetPlayerProfileAPI( - private val databaseManager: DatabaseManager -) : Api() { - override val paths = listOf(Path("/api/profile/:username", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("username", Schemas.stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val username = parameters.pathParameter("username").string - - val sqlClient = getSqlClient() - - val user = databaseManager.userDao.getByUsername(username, sqlClient) ?: throw NotExists() - - val response = mutableMapOf() - - response["registerDate"] = user.registerDate - - return Successful(response) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/profile/GetProfileAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/profile/GetProfileAPI.kt deleted file mode 100644 index b5024af7..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/profile/GetProfileAPI.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.panomc.platform.route.api.profile - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class GetProfileAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/profile", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val response = mutableMapOf() - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val user = databaseManager.userDao.getById(userId, sqlClient)!! - - response["registerDate"] = user.registerDate - response["lastLoginDate"] = user.lastLoginDate - - return Successful(response) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/profile/SendResetPasswordEmailAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/profile/SendResetPasswordEmailAPI.kt deleted file mode 100644 index 1e25e6b6..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/profile/SendResetPasswordEmailAPI.kt +++ /dev/null @@ -1,44 +0,0 @@ -package com.panomc.platform.route.api.profile - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.CantResetPasswordWait15Minutes -import com.panomc.platform.mail.MailManager -import com.panomc.platform.mail.mails.ResetPasswordMail -import com.panomc.platform.model.* -import com.panomc.platform.token.TokenType -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class SendResetPasswordEmailAPI( - private val databaseManager: DatabaseManager, - private val mailManager: MailManager, - private val authProvider: AuthProvider -) : LoggedInApi() { - override val paths = listOf(Path("/api/profile/resetPassword", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val lastToken = - databaseManager.tokenDao.getLastBySubjectAndType(userId.toString(), TokenType.RESET_PASSWORD, sqlClient) - - if (lastToken != null) { - val fifteenMinutesLaterInMillis = lastToken.startDate + 15 * 60 * 1000 - - if (System.currentTimeMillis() < fifteenMinutesLaterInMillis) { - throw CantResetPasswordWait15Minutes() - } - } - - mailManager.sendMail(sqlClient, userId, ResetPasswordMail()) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/server/ServerConnectAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/server/ServerConnectAPI.kt deleted file mode 100755 index 9e0a14a3..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/server/ServerConnectAPI.kt +++ /dev/null @@ -1,113 +0,0 @@ -package com.panomc.platform.route.api.server - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Server -import com.panomc.platform.error.InstallationRequired -import com.panomc.platform.error.InvalidToken -import com.panomc.platform.error.NeedPermission -import com.panomc.platform.model.Api -import com.panomc.platform.model.Path -import com.panomc.platform.model.Result -import com.panomc.platform.model.RouteType -import com.panomc.platform.server.ServerAuthProvider -import com.panomc.platform.server.ServerManager -import com.panomc.platform.server.ServerStatus -import com.panomc.platform.setup.SetupManager -import io.vertx.core.http.ServerWebSocket -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser -import io.vertx.kotlin.coroutines.dispatcher -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.launch - -@Endpoint -class ServerConnectAPI( - private val databaseManager: DatabaseManager, - private val setupManager: SetupManager, - private val serverAuthProvider: ServerAuthProvider, - private val serverManager: ServerManager -) : Api() { - override val paths = listOf(Path("/api/server/connection", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result? { - val request = context.request() - - request.pause() - - if (!setupManager.isSetupDone()) { - return InstallationRequired() - } - - if (!serverAuthProvider.isAuthenticated(context)) { - return InvalidToken() - } - - val serverId = serverAuthProvider.getServerIdFromRoutingContext(context) - - val sqlClient = databaseManager.getSqlClient() - - val server = databaseManager.serverDao.getById(serverId, sqlClient) ?: return InvalidToken() - - if (!server.permissionGranted) { - return NeedPermission() - } - - request.resume() - - val webSocket = request.toWebSocket() - - webSocket.onSuccess { - CoroutineScope(context.vertx().dispatcher()).launch { - onConnectionEstablished(context, it) - } - } - - webSocket.onFailure { - if (!context.response().ended()) { - context.response().end() - } - } - - return null - } - - private suspend fun onConnectionEstablished(context: RoutingContext, serverWebSocket: ServerWebSocket) { - val serverId = serverAuthProvider.getServerIdFromRoutingContext(context) - - val sqlClient = databaseManager.getSqlClient() - - val server = databaseManager.serverDao.getById(serverId, sqlClient)!! - - databaseManager.serverDao.updateStatusById(serverId, ServerStatus.ONLINE, sqlClient) - - serverManager.onServerConnect(server, serverWebSocket) - - serverWebSocket.textMessageHandler { - CoroutineScope(context.vertx().dispatcher()).launch { - serverManager.onServerWrite(it, server) - } - } - - serverWebSocket.closeHandler { - CoroutineScope(context.vertx().dispatcher()).launch { - onConnectionClosed(server) - } - } - } - - private suspend fun onConnectionClosed(server: Server) { - val sqlClient = databaseManager.getSqlClient() - - val serverExists = databaseManager.serverDao.existsById(server.id, sqlClient) - - if (serverExists) { - databaseManager.serverDao.updateStopTimeById(server.id, System.currentTimeMillis(), sqlClient) - databaseManager.serverDao.updateServerForOfflineById(server.id, sqlClient) - } - - serverManager.onServerDisconnect(server) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/server/ServerConnectNewAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/server/ServerConnectNewAPI.kt deleted file mode 100755 index da5f2e13..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/server/ServerConnectNewAPI.kt +++ /dev/null @@ -1,107 +0,0 @@ -package com.panomc.platform.route.api.server - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Server -import com.panomc.platform.error.InstallationRequired -import com.panomc.platform.error.InvalidPlatformCode -import com.panomc.platform.model.* -import com.panomc.platform.notification.NotificationManager -import com.panomc.platform.notification.Notifications -import com.panomc.platform.server.PlatformCodeManager -import com.panomc.platform.server.ServerStatus -import com.panomc.platform.server.ServerType -import com.panomc.platform.setup.SetupManager -import com.panomc.platform.token.TokenProvider -import com.panomc.platform.token.TokenType -import io.vertx.core.json.JsonObject -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class ServerConnectNewAPI( - private val platformCodeManager: PlatformCodeManager, - private val databaseManager: DatabaseManager, - private val tokenProvider: TokenProvider, - private val setupManager: SetupManager, - private val notificationManager: NotificationManager -) : Api() { - override val paths = listOf(Path("/api/server/connect", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - json( - objectSchema() - .property("platformCode", stringSchema()) - .optionalProperty("favicon", stringSchema()) - .property("serverName", stringSchema()) - .optionalProperty("motd", stringSchema()) - .property("host", stringSchema()) - .property("port", intSchema()) - .property("playerCount", numberSchema()) - .property("maxPlayerCount", numberSchema()) - .property("serverType", enumSchema(*ServerType.values().map { it.toString() }.toTypedArray())) - .property("serverVersion", stringSchema()) - .property("startTime", numberSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - if (!setupManager.isSetupDone()) { - throw InstallationRequired() - } - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - if (data.getString("platformCode", "") != platformCodeManager.getPlatformKey().toString()) { - throw InvalidPlatformCode() - } - - val server = Server( - name = data.getString("serverName"), - motd = data.getString("motd") ?: "", - host = data.getString("host"), - port = data.getInteger("port"), - playerCount = data.getLong("playerCount"), - maxPlayerCount = data.getLong("maxPlayerCount"), - type = ServerType.valueOf(data.getString("serverType")), - version = data.getString("serverVersion"), - favicon = data.getString("favicon") ?: "", - status = ServerStatus.OFFLINE, - startTime = data.getLong("startTime") - ) - - val sqlClient = getSqlClient() - - val serverId = databaseManager.serverDao.add(server, sqlClient) - - val (token, expireDate) = tokenProvider.generateToken(serverId.toString(), TokenType.SERVER_AUTHENTICATION) - - tokenProvider.saveToken(token, serverId.toString(), TokenType.SERVER_AUTHENTICATION, expireDate, sqlClient) - - val notificationProperties = JsonObject().put("id", serverId) - - notificationManager.sendNotificationToAllWithPermission( - Notifications.PanelNotificationType.SERVER_CONNECT_REQUEST, - notificationProperties, - PanelPermission.MANAGE_SERVERS, - sqlClient - ) - - return Successful( - mapOf( - "token" to token - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/server/ServerDisconnectAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/server/ServerDisconnectAPI.kt deleted file mode 100755 index 2141464e..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/server/ServerDisconnectAPI.kt +++ /dev/null @@ -1,61 +0,0 @@ -package com.panomc.platform.route.api.server - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.InstallationRequired -import com.panomc.platform.error.InvalidToken -import com.panomc.platform.model.* -import com.panomc.platform.server.ServerAuthProvider -import com.panomc.platform.setup.SetupManager -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class ServerDisconnectAPI( - private val databaseManager: DatabaseManager, - private val setupManager: SetupManager, - private val serverAuthProvider: ServerAuthProvider -) : Api() { - override val paths = listOf(Path("/api/server/disconnect", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - if (!setupManager.isSetupDone()) { - return InstallationRequired() - } - - if (!serverAuthProvider.isAuthenticated(context)) { - return InvalidToken() - } - - val serverId = serverAuthProvider.getServerIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.serverDao.existsById(serverId, sqlClient) - - if (!exists) { - return InvalidToken() - } - - val mainServerId = databaseManager.systemPropertyDao.getByOption( - "main_server", - sqlClient - )!!.value.toLong() - - if (mainServerId == serverId) { - databaseManager.systemPropertyDao.update( - "main_server", - "-1", - sqlClient - ) - } - - databaseManager.serverPlayerDao.deleteByServerId(serverId, sqlClient) - - databaseManager.serverDao.deleteById(serverId, sqlClient) - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/setup/CheckAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/setup/CheckAPI.kt deleted file mode 100755 index 7df25fac..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/setup/CheckAPI.kt +++ /dev/null @@ -1,20 +0,0 @@ -package com.panomc.platform.route.api.setup - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.model.* -import com.panomc.platform.setup.SetupManager -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class CheckAPI( - private val setupManager: SetupManager -) : SetupApi(setupManager) { - override val paths = listOf(Path("/api/setup/step/check", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - return Successful(setupManager.getCurrentStepData().map) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/setup/DBConnectionTestAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/setup/DBConnectionTestAPI.kt deleted file mode 100755 index 6596123f..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/setup/DBConnectionTestAPI.kt +++ /dev/null @@ -1,81 +0,0 @@ -package com.panomc.platform.route.api.setup - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.error.InvalidData -import com.panomc.platform.model.* -import com.panomc.platform.setup.SetupManager -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas -import io.vertx.kotlin.coroutines.await -import io.vertx.mysqlclient.MySQLConnectOptions -import io.vertx.mysqlclient.MySQLPool -import io.vertx.sqlclient.PoolOptions -import org.slf4j.Logger - -@Endpoint -class DBConnectionTestAPI(private val logger: Logger, setupManager: SetupManager) : SetupApi(setupManager) { - override val paths = listOf(Path("/api/setup/dbConnectionTest", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.json( - Schemas.objectSchema() - .property("host", Schemas.stringSchema()) - .property("dbName", Schemas.stringSchema()) - .property("username", Schemas.stringSchema()) - .optionalProperty("password", Schemas.stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - var port = 3306 - var host = data.getString("host") - - if (host.contains(":")) { - val splitHost = host.split(":") - - host = splitHost[0] - - port = splitHost[1].toInt() - } - - val connectOptions = MySQLConnectOptions() - .setPort(port) - .setHost(host) - .setDatabase(data.getString("dbName")) - .setUser(data.getString("username")) - - if (!data.getString("password").isNullOrEmpty()) - connectOptions.password = data.getString("password") - - val poolOptions = PoolOptions() - .setMaxSize(1) - - val mySQLPool = MySQLPool.pool(context.vertx(), connectOptions, poolOptions) - - try { - val connection = mySQLPool.connection.await() - - connection.close().await() - - mySQLPool.close().await() - } catch (e: java.lang.Exception) { - logger.error(e.toString()) - - throw InvalidData() - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/setup/FinishAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/setup/FinishAPI.kt deleted file mode 100755 index 1cf1e484..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/setup/FinishAPI.kt +++ /dev/null @@ -1,126 +0,0 @@ -package com.panomc.platform.route.api.setup - -import com.panomc.platform.AppConstants -import com.panomc.platform.AppConstants.AVAILABLE_LOCALES -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import com.panomc.platform.setup.SetupManager -import com.panomc.platform.util.CSRFTokenGenerator -import com.panomc.platform.util.RegisterUtil -import com.panomc.platform.util.UIHelper -import io.vertx.core.http.Cookie -import io.vertx.core.http.HttpClient -import io.vertx.ext.web.Router -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* -import org.springframework.context.annotation.Lazy - -@Endpoint -class FinishAPI( - private val setupManager: SetupManager, - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider, - private val configManager: ConfigManager, - private val httpClient: HttpClient, - @Lazy private val router: Router -) : SetupApi(setupManager) { - override val paths = listOf(Path("/api/setup/finish", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.json( - objectSchema() - .property("username", stringSchema()) - .property("email", stringSchema()) - .property("password", stringSchema()) - .property( - "setupLocale", - enumSchema(*AVAILABLE_LOCALES.toTypedArray()) - ) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - if (setupManager.getStep() != 4) { - return Successful(setupManager.getCurrentStepData().map) - } - - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val username = data.getString("username") - val email = data.getString("email") - val password = data.getString("password") - val setupLocale = data.getString("setupLocale") - - val remoteIP = context.request().remoteAddress().host() - - RegisterUtil.validateForm( - username, - email, - password, - password, - true, - "", - null - ) - - val sqlClient = getSqlClient() - - databaseManager.initDatabase(sqlClient) - - RegisterUtil.register( - databaseManager, - sqlClient, - username, - email, - password, - remoteIP, - isAdmin = true, - isSetup = true - ) - - val token = authProvider.login(username, sqlClient) - - configManager.getConfig().put("locale", setupLocale) - - configManager.saveConfig() - - setupManager.finishSetup() - - UIHelper.prepareUI(setupManager, httpClient, router) - - val response = context.response() - - val csrfToken = CSRFTokenGenerator.nextToken() - - val jwtCookie = Cookie.cookie(AppConstants.COOKIE_PREFIX + AppConstants.JWT_COOKIE_NAME, token) - val csrfTokenCookie = Cookie.cookie(AppConstants.COOKIE_PREFIX + AppConstants.CSRF_TOKEN_COOKIE_NAME, csrfToken) - - jwtCookie.path = "/" - jwtCookie.isHttpOnly = true - - csrfTokenCookie.path = "/" - csrfTokenCookie.isHttpOnly = true - - response.addCookie(jwtCookie) - response.addCookie(csrfTokenCookie) - - return Successful( - mapOf( - "jwt" to token - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/setup/VerifyMailConfigurationAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/setup/VerifyMailConfigurationAPI.kt deleted file mode 100755 index aa370c59..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/setup/VerifyMailConfigurationAPI.kt +++ /dev/null @@ -1,99 +0,0 @@ -package com.panomc.platform.route.api.setup - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.error.InvalidData -import com.panomc.platform.model.* -import com.panomc.platform.setup.SetupManager -import io.vertx.ext.mail.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* -import io.vertx.kotlin.coroutines.await -import org.slf4j.Logger - -@Endpoint -class VerifyMailConfigurationAPI(private val logger: Logger, setupManager: SetupManager) : SetupApi(setupManager) { - override val paths = listOf(Path("/api/setup/verifyMailConfiguration", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - json( - objectSchema() - .property("useSSL", booleanSchema()) - .property("useTLS", booleanSchema()) - .property("address", stringSchema()) - .property("host", stringSchema()) - .property("username", stringSchema()) - .property("password", stringSchema()) - .property("port", intSchema()) - .optionalProperty("authMethod", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val address = data.getString("address") - val host = data.getString("host") - val port = data.getInteger("port") - val useSSL = data.getBoolean("useSSL") - val useTLS = data.getBoolean("useTLS") - val authMethod = data.getString("authMethod") - val username = data.getString("username") - val password = data.getString("password") - - try { - val mailConfig = MailConfig() - - mailConfig.hostname = host - mailConfig.port = port - - if (useSSL) { - mailConfig.isSsl = true - } - - if (useTLS) { - mailConfig.starttls = StartTLSOptions.REQUIRED - } - - mailConfig.username = username - mailConfig.password = password - - if (authMethod != null) { - mailConfig.authMethods = authMethod - } - - val mailClient: MailClient - mailClient = MailClient.create(context.vertx(), mailConfig) - - val message = MailMessage() - - message.from = address - message.subject = "Pano Platform E-mail test" - message.setTo("no-reply@duruer.dev") - message.html = "Hello world!" - - mailClient.sendMail(message).await() - - mailClient.close() - } catch (e: Exception) { - logger.error(e.toString()) - - throw InvalidData(extras = mapOf("mailError" to e.message)) - } catch (e: SMTPException) { - logger.error(e.toString()) - - throw InvalidData(extras = mapOf("mailError" to e.message)) - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/setup/step/BackStepAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/setup/step/BackStepAPI.kt deleted file mode 100755 index 386faad2..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/setup/step/BackStepAPI.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.panomc.platform.route.api.setup.step - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.model.* -import com.panomc.platform.setup.SetupManager -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class BackStepAPI( - private val setupManager: SetupManager -) : SetupApi(setupManager) { - override val paths = listOf(Path("/api/setup/step/backStep", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - setupManager.backStep() - - return Successful(setupManager.getCurrentStepData().map) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/setup/step/GoAnyBackStepAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/setup/step/GoAnyBackStepAPI.kt deleted file mode 100755 index 3fcf88b1..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/setup/step/GoAnyBackStepAPI.kt +++ /dev/null @@ -1,42 +0,0 @@ -package com.panomc.platform.route.api.setup.step - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.model.* -import com.panomc.platform.setup.SetupManager -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.intSchema -import io.vertx.json.schema.common.dsl.Schemas.objectSchema - -@Endpoint -class GoAnyBackStepAPI( - private val setupManager: SetupManager -) : SetupApi(setupManager) { - override val paths = listOf(Path("/api/setup/step/goAnyBackStep", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - json( - objectSchema() - .property("step", intSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val step = data.getInteger("step") - - setupManager.goAnyBackStep(step) - - return Successful(setupManager.getCurrentStepData().map) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/setup/step/NextStepAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/setup/step/NextStepAPI.kt deleted file mode 100755 index 9854ae74..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/setup/step/NextStepAPI.kt +++ /dev/null @@ -1,121 +0,0 @@ -package com.panomc.platform.route.api.setup.step - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.model.* -import com.panomc.platform.setup.SetupManager -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class NextStepAPI( - private val configManager: ConfigManager, - private val setupManager: SetupManager -) : SetupApi(setupManager) { - override val paths = listOf(Path("/api/setup/step/nextStep", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - json( - objectSchema() - .property("step", intSchema()) - .optionalProperty("websiteName", stringSchema()) - .optionalProperty("websiteDescription", stringSchema()) - .optionalProperty("host", stringSchema()) - .optionalProperty("port", intSchema()) - .optionalProperty("address", stringSchema()) - .optionalProperty("dbName", stringSchema()) - .optionalProperty("username", stringSchema()) - .optionalProperty("password", stringSchema()) - .optionalProperty("prefix", stringSchema()) - .optionalProperty("useSSL", booleanSchema()) - .optionalProperty("useTLS", booleanSchema()) - .optionalProperty("authMethod", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val clientStep = data.getInteger("step") - val websiteName = data.getString("websiteName") - val websiteDescription = data.getString("websiteDescription") - val host = data.getString("host") - val port = data.getInteger("port") - val address = data.getString("address") - val dbName = data.getString("dbName") - val username = data.getString("username") - val password = data.getString("password") - val prefix = data.getString("prefix") - val useSSL = data.getBoolean("useSSL") - val useTLS = data.getBoolean("useTLS") - val authMethod = data.getString("authMethod") - - if (clientStep == setupManager.getStep()) { - var passStep = false - - if (clientStep == 0) - passStep = true - else if (clientStep == 1 && - !websiteName.isNullOrEmpty() && - !websiteDescription.isNullOrEmpty() - ) { - configManager.getConfig().put("website-name", websiteName) - configManager.getConfig().put("website-description", websiteDescription) - - passStep = true - } else if ( - clientStep == 2 && - !host.isNullOrEmpty() && - !dbName.isNullOrEmpty() && - !username.isNullOrEmpty() - ) { - val databaseOptions = configManager.getConfig().getJsonObject("database") - - databaseOptions.put("host", host) - databaseOptions.put("name", dbName) - databaseOptions.put("username", username) - databaseOptions.put("password", if (password.isNullOrEmpty()) "" else password) - databaseOptions.put("prefix", if (prefix.isNullOrEmpty()) "" else prefix) - - passStep = true - } else if (clientStep == 3 && - !host.isNullOrEmpty() && - port != null && - !address.isNullOrEmpty() && - !username.isNullOrEmpty() && - !password.isNullOrEmpty() && - useSSL != null && - useTLS != null && - authMethod != null - ) { - val mailConfiguration = configManager.getConfig().getJsonObject("email") - - mailConfiguration.put("address", address) - mailConfiguration.put("host", host) - mailConfiguration.put("port", port) - mailConfiguration.put("username", username) - mailConfiguration.put("password", password) - mailConfiguration.put("SSL", useSSL) - mailConfiguration.put("TLS", useTLS) - mailConfiguration.put("auth-method", authMethod) - - passStep = true - } - - if (passStep) - setupManager.nextStep() - } - - return Successful(setupManager.getCurrentStepData().map) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/sidebar/HomeSidebarAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/sidebar/HomeSidebarAPI.kt deleted file mode 100644 index 87504b3b..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/sidebar/HomeSidebarAPI.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.panomc.platform.route.api.sidebar - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.config.ConfigManager -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Server -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class HomeSidebarAPI(private val configManager: ConfigManager, private val databaseManager: DatabaseManager) : Api() { - override val paths = listOf(Path("/api/sidebar/home", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - - override suspend fun handle(context: RoutingContext): Result { - val response = mutableMapOf() - - response["ipAddress"] = configManager.getConfig().getString("server-ip-address") - response["serverGameVersion"] = configManager.getConfig().getString("server-game-version") - - val sqlClient = getSqlClient() - - val mainServerId = databaseManager.systemPropertyDao.getByOption( - "main_server", - sqlClient - )?.value?.toLong() - var mainServer: Server? = null - - if (mainServerId != null && mainServerId != -1L) { - mainServer = databaseManager.serverDao.getById(mainServerId, sqlClient) - } - - response["mainServer"] = if (mainServer == null) null else mapOf( - "playerCount" to mainServer.playerCount, - "maxPlayerCount" to mainServer.maxPlayerCount, - "status" to mainServer.status - ) - response["lastRegisteredUsers"] = databaseManager.userDao.getLastUsernames(12, sqlClient) - - return Successful(response) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/sidebar/PlayerProfileSidebarAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/sidebar/PlayerProfileSidebarAPI.kt deleted file mode 100644 index 9f216f62..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/sidebar/PlayerProfileSidebarAPI.kt +++ /dev/null @@ -1,54 +0,0 @@ -package com.panomc.platform.route.api.sidebar - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class PlayerProfileSidebarAPI(private val databaseManager: DatabaseManager) : Api() { - override val paths = listOf(Path("/api/sidebar/profile/:username", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("username", Schemas.stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val username = parameters.pathParameter("username").string - - val sqlClient = getSqlClient() - - val user = databaseManager.userDao.getByUsername(username, sqlClient) ?: throw NotExists() - - val userPermissionGroupId = databaseManager.userDao.getPermissionGroupIdFromUserId(user.id, sqlClient)!! - - var name = "" - - if (userPermissionGroupId != -1L) { - val userPermissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(userPermissionGroupId, sqlClient)!! - - name = userPermissionGroup.name - } - - val response = mutableMapOf() - - response["lastActivityTime"] = user.lastActivityTime - - response["inGame"] = databaseManager.serverPlayerDao.existsByUsername(user.username, sqlClient) - - response["permissionGroupName"] = name - - return Successful(response) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/sidebar/ProfileSidebarAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/sidebar/ProfileSidebarAPI.kt deleted file mode 100644 index 61e906c1..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/sidebar/ProfileSidebarAPI.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.panomc.platform.route.api.sidebar - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class ProfileSidebarAPI(private val databaseManager: DatabaseManager, private val authProvider: AuthProvider) : - LoggedInApi() { - override val paths = listOf(Path("/api/sidebar/profile", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val response = mutableMapOf() - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val userPermissionGroupId = databaseManager.userDao.getPermissionGroupIdFromUserId(userId, sqlClient)!! - - var name = "" - - if (userPermissionGroupId != -1L) { - val userPermissionGroup = - databaseManager.permissionGroupDao.getPermissionGroupById(userPermissionGroupId, sqlClient)!! - - name = userPermissionGroup.name - } - - val user = databaseManager.userDao.getById(userId, sqlClient)!! - - response["lastActivityTime"] = user.lastActivityTime - - response["inGame"] = databaseManager.serverPlayerDao.existsByUsername(user.username, sqlClient) - - response["permissionGroupName"] = name - - return Successful(response) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/sidebar/SupportSidebarAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/sidebar/SupportSidebarAPI.kt deleted file mode 100644 index 9f5f10f1..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/sidebar/SupportSidebarAPI.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.panomc.platform.route.api.sidebar - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.json.schema.SchemaParser - -@Endpoint -class SupportSidebarAPI(private val databaseManager: DatabaseManager) : Api() { - override val paths = listOf(Path("/api/sidebar/support", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser) = null - - override suspend fun handle(context: RoutingContext): Result { - val response = mutableMapOf() - - val sqlClient = getSqlClient() - - response["onlineAdmins"] = databaseManager.userDao.getOnlineAdmins(-1, sqlClient).map { it.username } - - return Successful(response) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/ticket/CreateTicketAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/ticket/CreateTicketAPI.kt deleted file mode 100755 index a624e2a9..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/ticket/CreateTicketAPI.kt +++ /dev/null @@ -1,104 +0,0 @@ -package com.panomc.platform.route.api.ticket - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Ticket -import com.panomc.platform.db.model.TicketMessage -import com.panomc.platform.error.CategoryNotExists -import com.panomc.platform.error.MessageCantBeEmpty -import com.panomc.platform.error.TitleCantBeEmpty -import com.panomc.platform.model.* -import com.panomc.platform.notification.NotificationManager -import com.panomc.platform.notification.Notifications -import io.vertx.core.json.JsonObject -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class CreateTicketAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider, - private val notificationManager: NotificationManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/tickets", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .body( - Bodies.json( - objectSchema() - .property("title", stringSchema()) - .property("message", stringSchema()) - .property("categoryId", numberSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val title = data.getString("title") - val message = data.getString("message") - val categoryId = data.getLong("categoryId") - - validateInput(title, message) - - val userId = authProvider.getUserIdFromRoutingContext(context) - val sqlClient = getSqlClient() - - if (categoryId != -1L) { - val isCategoryExists = databaseManager.ticketCategoryDao.existsById(categoryId, sqlClient) - - if (!isCategoryExists) { - throw CategoryNotExists() - } - } - - val id = databaseManager.ticketDao.add( - Ticket( - title = title, - categoryId = categoryId, - userId = userId - ), sqlClient - ) - - databaseManager.ticketMessageDao.addMessage( - TicketMessage(userId = userId, ticketId = id, message = message), - sqlClient - ) - - val notificationProperties = JsonObject().put("id", id) - - notificationManager.sendNotificationToAllWithPermission( - Notifications.PanelNotificationType.NEW_TICKET, - notificationProperties, - PanelPermission.MANAGE_TICKETS, - sqlClient - ) - - return Successful( - mapOf( - "id" to id - ) - ) - } - - private fun validateInput(title: String, message: String) { - if (title.isBlank()) { - throw TitleCantBeEmpty() - } - - if (message.isBlank()) { - throw MessageCantBeEmpty() - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketAPI.kt deleted file mode 100755 index 0fe93ba1..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketAPI.kt +++ /dev/null @@ -1,122 +0,0 @@ -package com.panomc.platform.route.api.ticket - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Ticket -import com.panomc.platform.db.model.TicketCategory -import com.panomc.platform.db.model.TicketMessage -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class GetTicketAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : LoggedInApi() { - override val paths = listOf(Path("/api/tickets/:id", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.ticketDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - val isBelong = databaseManager.ticketDao.isIdBelongToUserId(id, userId, sqlClient) - - if (!isBelong) { - throw NoPermission() - } - - val ticket = databaseManager.ticketDao.getById(id, sqlClient)!! - - val username = databaseManager.userDao.getUsernameFromUserId(ticket.userId, sqlClient)!! - - val messages = databaseManager.ticketMessageDao.getByTicketId(id, sqlClient) - - val userIdList = mutableListOf() - - messages - .filter { ticketMessage -> ticketMessage.userId != -1L } - .forEach { message -> - if (userIdList.indexOf(message.userId) == -1) - userIdList.add(message.userId) - } - - val usernameList = databaseManager.userDao.getUsernameByListOfId(userIdList, sqlClient) - - val count = databaseManager.ticketMessageDao.getCountByTicketId(ticket.id, sqlClient) - - if (ticket.categoryId == -1L) { - return getResult(ticket, usernameList, null, username, messages, count) - } - - val ticketCategory = databaseManager.ticketCategoryDao.getById(ticket.categoryId, sqlClient) - - return getResult(ticket, usernameList, ticketCategory, username, messages, count) - } - - private fun getResult( - ticket: Ticket, - usernameList: Map, - ticketCategory: TicketCategory?, - username: String, - ticketMessages: List, - messageCount: Long - ): Result { - val messages = mutableListOf>() - - ticketMessages.forEach { ticketMessage -> - messages.add( - 0, - mapOf( - "id" to ticketMessage.id, - "userId" to ticketMessage.userId, - "ticketId" to ticketMessage.ticketId, - "username" to (usernameList[ticketMessage.userId] ?: "-"), - "message" to ticketMessage.message, - "date" to ticketMessage.date, - "panel" to ticketMessage.panel - ) - ) - } - - return Successful( - mapOf( - "ticket" to mapOf( - "id" to ticket.id, - "username" to username, - "title" to ticket.title, - "category" to - if (ticketCategory == null) - mapOf("title" to "-", "url" to "-") - else - mapOf("title" to ticketCategory.title, "url" to ticketCategory.url), - "messages" to messages, - "status" to ticket.status, - "date" to ticket.date, - "messageCount" to messageCount - ) - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketCategoriesAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketCategoriesAPI.kt deleted file mode 100644 index 9b57a7f6..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketCategoriesAPI.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.panomc.platform.route.api.ticket - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.optionalParam -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas - -@Endpoint -class GetTicketCategoriesAPI( - val databaseManager: DatabaseManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/ticket/categories", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter(optionalParam("page", Schemas.numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - - val page = parameters.queryParameter("page")?.long ?: 0 - - val sqlClient = getSqlClient() - - val categories = databaseManager.ticketCategoryDao.getByPage(page, sqlClient) - - return Successful( - mapOf( - "categories" to categories - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketMessagesAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketMessagesAPI.kt deleted file mode 100755 index 260cf8b0..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketMessagesAPI.kt +++ /dev/null @@ -1,93 +0,0 @@ -package com.panomc.platform.route.api.ticket - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.numberSchema - -@Endpoint -class GetTicketMessagesAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider -) : LoggedInApi() { - override val paths = listOf(Path("/api/tickets/:id/messages", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .queryParameter(param("lastMessageId", numberSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val id = parameters.pathParameter("id").long - val lastMessageId = parameters.queryParameter("lastMessageId").long - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.ticketDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - val isBelong = databaseManager.ticketDao.isIdBelongToUserId(id, userId, sqlClient) - - if (!isBelong) { - throw NoPermission() - } - - val isTicketMessageIdExists = databaseManager.ticketMessageDao.existsById(lastMessageId, sqlClient) - - if (!isTicketMessageIdExists) { - throw NotExists() - } - - val ticketMessages = - databaseManager.ticketMessageDao.getByTicketIdAndStartFromId(lastMessageId, id, sqlClient) - - val userIdList = mutableListOf() - - ticketMessages - .filter { ticketMessage -> ticketMessage.userId != -1L } - .forEach { message -> - if (userIdList.indexOf(message.userId) == -1) - userIdList.add(message.userId) - } - - val usernameList = databaseManager.userDao.getUsernameByListOfId(userIdList, sqlClient) - - val messages = mutableListOf>() - - ticketMessages.forEach { ticketMessage -> - messages.add( - 0, - mapOf( - "id" to ticketMessage.id, - "userId" to ticketMessage.userId, - "ticketId" to ticketMessage.ticketId, - "username" to (usernameList[ticketMessage.userId] ?: "-"), - "message" to ticketMessage.message, - "date" to ticketMessage.date, - "panel" to ticketMessage.panel - ) - ) - } - - return Successful( - mapOf( - "messages" to messages - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketsAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketsAPI.kt deleted file mode 100644 index c9d469d7..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketsAPI.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.panomc.platform.route.api.ticket - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.model.LoggedInApi -import com.panomc.platform.model.Path -import com.panomc.platform.model.Result -import com.panomc.platform.model.RouteType -import com.panomc.platform.util.TicketPageType -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Parameters.optionalParam -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas -import io.vertx.json.schema.common.dsl.Schemas.arraySchema - -@Endpoint -class GetTicketsAPI( - private val getTicketsService: GetTicketsService -) : LoggedInApi() { - override val paths = listOf(Path("/api/tickets", RouteType.GET)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .queryParameter( - optionalParam( - "pageType", - arraySchema() - .items( - Schemas.enumSchema( - *TicketPageType.entries - .map { it.name } - .toTypedArray() - ) - ) - ) - ) - .queryParameter(optionalParam("page", Schemas.numberSchema())) - .queryParameter(optionalParam("categoryUrl", Schemas.stringSchema())) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val sqlClient = getSqlClient() - val parameters = getParameters(context) - - return getTicketsService.handle(context, sqlClient, parameters) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketsService.kt b/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketsService.kt deleted file mode 100644 index 93f1950c..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/ticket/GetTicketsService.kt +++ /dev/null @@ -1,135 +0,0 @@ -package com.panomc.platform.route.api.ticket - - -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.Ticket -import com.panomc.platform.db.model.TicketCategory -import com.panomc.platform.error.NotExists -import com.panomc.platform.error.PageNotFound -import com.panomc.platform.model.Result -import com.panomc.platform.model.Successful -import com.panomc.platform.util.TicketPageType -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestParameters -import io.vertx.sqlclient.SqlClient -import org.springframework.stereotype.Service -import kotlin.math.ceil - -@Service -class GetTicketsService(private val databaseManager: DatabaseManager, private val authProvider: AuthProvider) { - suspend fun handle(context: RoutingContext, sqlClient: SqlClient, parameters: RequestParameters): Result { - val pageType = - TicketPageType.valueOf( - parameters.queryParameter("pageType")?.jsonArray?.first() as String? ?: TicketPageType.ALL.name - ) - val page = parameters.queryParameter("page")?.long ?: 1L - val categoryUrl = parameters.queryParameter("categoryUrl")?.string - - var ticketCategory: TicketCategory? = null - - if (categoryUrl != null && categoryUrl != "-") { - val exists = databaseManager.ticketCategoryDao.existsByUrl( - categoryUrl, - sqlClient - ) - - if (!exists) { - throw NotExists() - } - - ticketCategory = databaseManager.ticketCategoryDao.getByUrl(categoryUrl, sqlClient)!! - } - - if (categoryUrl != null && categoryUrl == "-") { - ticketCategory = TicketCategory() - } - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val count = if (ticketCategory != null) - databaseManager.ticketDao.countByCategoryAndUserId(ticketCategory.id, userId, sqlClient) - else - databaseManager.ticketDao.getCountByPageTypeAndUserId(userId, pageType, sqlClient) - - var totalPage = ceil(count.toDouble() / 10).toLong() - - if (totalPage < 1) - totalPage = 1 - - if (page > totalPage || page < 1) { - throw PageNotFound() - } - - val tickets = if (ticketCategory != null) - databaseManager.ticketDao.getAllByPageCategoryIdAndUserId(page, ticketCategory.id, userId, sqlClient) - else - databaseManager.ticketDao.getAllByPagePageTypeAndUserId(userId, page, pageType, sqlClient) - - if (tickets.isEmpty()) { - return getResults(ticketCategory, tickets, mapOf(), null, count, totalPage) - } - - val username = databaseManager.userDao.getUsernameFromUserId(userId, sqlClient) - - if (ticketCategory != null) { - return getResults(ticketCategory, tickets, mapOf(), username, count, totalPage) - } - - val categoryIdList = - tickets.filter { it.categoryId != -1L }.distinctBy { it.categoryId }.map { it.categoryId } - - if (categoryIdList.isEmpty()) { - return getResults(null, tickets, mapOf(), username, count, totalPage) - } - - val ticketCategoryList = databaseManager.ticketCategoryDao.getByIdList(categoryIdList, sqlClient) - - return getResults(null, tickets, ticketCategoryList, username, count, totalPage) - } - - private fun getResults( - ticketCategory: TicketCategory?, - tickets: List, - ticketCategoryList: Map, - username: String?, - count: Long, - totalPage: Long - ): Result { - val ticketDataList = mutableListOf>() - - tickets.forEach { ticket -> - ticketDataList.add( - mapOf( - "id" to ticket.id, - "title" to ticket.title, - "category" to (ticketCategory ?: if (ticket.categoryId == -1L) - mapOf("id" to -1, "title" to "-", "url" to "-") - else - ticketCategoryList.getOrDefault( - ticket.categoryId, - mapOf("id" to -1, "title" to "-", "url" to "-") - )), - "writer" to mapOf( - "username" to username - ), - "date" to ticket.date, - "lastUpdate" to ticket.lastUpdate, - "status" to ticket.status - ) - ) - } - - val result = mutableMapOf( - "tickets" to ticketDataList, - "ticketCount" to count, - "totalPage" to totalPage - ) - - if (ticketCategory != null) { - result["category"] = ticketCategory - } - - return Successful(result) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/ticket/SendTicketMessageAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/ticket/SendTicketMessageAPI.kt deleted file mode 100755 index 7b36ec0c..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/ticket/SendTicketMessageAPI.kt +++ /dev/null @@ -1,115 +0,0 @@ -package com.panomc.platform.route.api.ticket - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.db.model.TicketMessage -import com.panomc.platform.error.MessageCantBeEmpty -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.error.TicketIsClosed -import com.panomc.platform.model.* -import com.panomc.platform.notification.NotificationManager -import com.panomc.platform.notification.Notifications -import com.panomc.platform.util.TicketStatus -import io.vertx.core.json.JsonObject -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies.json -import io.vertx.ext.web.validation.builder.Parameters.param -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class SendTicketMessageAPI( - private val authProvider: AuthProvider, - private val databaseManager: DatabaseManager, - private val notificationManager: NotificationManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/tickets/:id/message", RouteType.POST)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(param("id", numberSchema())) - .body( - json( - objectSchema() - .property("message", stringSchema()) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val ticketId = parameters.pathParameter("id").long - val message = data.getString("message") - - if (message.isBlank()) { - throw MessageCantBeEmpty() - } - - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.ticketDao.existsById(ticketId, sqlClient) - - if (!exists) { - throw NotExists() - } - - val isBelong = databaseManager.ticketDao.isIdBelongToUserId(ticketId, userId, sqlClient) - - if (!isBelong) { - throw NoPermission() - } - - val isTicketClosed = databaseManager.ticketDao.getStatusById(ticketId, sqlClient) == TicketStatus.CLOSED - - if (isTicketClosed) { - throw TicketIsClosed() - } - - val username = databaseManager.userDao.getUsernameFromUserId(userId, sqlClient) - - val ticketMessage = TicketMessage(userId = userId, ticketId = ticketId, message = message) - - val messageId = databaseManager.ticketMessageDao.addMessage(ticketMessage, sqlClient) - - databaseManager.ticketDao.updateLastUpdateDate( - ticketMessage.ticketId, - System.currentTimeMillis(), - sqlClient - ) - - val notificationProperties = JsonObject().put("id", ticketId) - - notificationManager.sendNotificationToAllWithPermission( - Notifications.PanelNotificationType.NEW_TICKET_MESSAGE, - notificationProperties, - PanelPermission.MANAGE_TICKETS, - sqlClient - ) - - return Successful( - mapOf( - "message" to mapOf( - "id" to messageId, - "userId" to ticketMessage.userId, - "ticketId" to ticketMessage.ticketId, - "username" to username, - "message" to ticketMessage.message, - "date" to ticketMessage.date, - "panel" to ticketMessage.panel - ) - ) - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/api/ticket/UpdateTicketAPI.kt b/src/main/kotlin/com/panomc/platform/route/api/ticket/UpdateTicketAPI.kt deleted file mode 100755 index 4960d29c..00000000 --- a/src/main/kotlin/com/panomc/platform/route/api/ticket/UpdateTicketAPI.kt +++ /dev/null @@ -1,82 +0,0 @@ -package com.panomc.platform.route.api.ticket - - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.auth.AuthProvider -import com.panomc.platform.auth.PanelPermission -import com.panomc.platform.db.DatabaseManager -import com.panomc.platform.error.NoPermission -import com.panomc.platform.error.NotExists -import com.panomc.platform.model.* -import com.panomc.platform.notification.NotificationManager -import com.panomc.platform.notification.Notifications -import com.panomc.platform.util.TicketStatus -import io.vertx.core.json.JsonObject -import io.vertx.ext.web.RoutingContext -import io.vertx.ext.web.validation.RequestPredicate -import io.vertx.ext.web.validation.ValidationHandler -import io.vertx.ext.web.validation.builder.Bodies -import io.vertx.ext.web.validation.builder.Parameters -import io.vertx.ext.web.validation.builder.ValidationHandlerBuilder -import io.vertx.json.schema.SchemaParser -import io.vertx.json.schema.common.dsl.Schemas.* - -@Endpoint -class UpdateTicketAPI( - private val databaseManager: DatabaseManager, - private val authProvider: AuthProvider, - private val notificationManager: NotificationManager -) : LoggedInApi() { - override val paths = listOf(Path("/api/tickets/:id", RouteType.PUT)) - - override fun getValidationHandler(schemaParser: SchemaParser): ValidationHandler = - ValidationHandlerBuilder.create(schemaParser) - .pathParameter(Parameters.param("id", numberSchema())) - .body( - Bodies.json( - objectSchema() - .optionalProperty("status", enumSchema(*TicketStatus.entries.map { it.name }.toTypedArray())) - ) - ) - .predicate(RequestPredicate.BODY_REQUIRED) - .build() - - override suspend fun handle(context: RoutingContext): Result { - val parameters = getParameters(context) - val data = parameters.body().jsonObject - - val id = parameters.pathParameter("id").long - val ticketStatus = - if (data.getString("status") == null) null else TicketStatus.valueOf(data.getString("status")) - val userId = authProvider.getUserIdFromRoutingContext(context) - - val sqlClient = getSqlClient() - - val exists = databaseManager.ticketDao.existsById(id, sqlClient) - - if (!exists) { - throw NotExists() - } - - val isBelong = databaseManager.ticketDao.isIdBelongToUserId(id, userId, sqlClient) - - if (!isBelong) { - throw NoPermission() - } - - if (ticketStatus != null && ticketStatus == TicketStatus.CLOSED) { - databaseManager.ticketDao.closeTicketById(id, sqlClient) - - val notificationProperties = JsonObject().put("id", id) - - notificationManager.sendNotificationToAllWithPermission( - Notifications.PanelNotificationType.TICKET_CLOSED_BY_USER, - notificationProperties, - PanelPermission.MANAGE_TICKETS, - sqlClient - ) - } - - return Successful() - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt b/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt deleted file mode 100755 index b5412658..00000000 --- a/src/main/kotlin/com/panomc/platform/route/template/IndexTemplate.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.panomc.platform.route.template - -import com.panomc.platform.annotation.Endpoint -import com.panomc.platform.model.Path -import com.panomc.platform.model.RouteType -import com.panomc.platform.model.Template -import io.vertx.core.Handler -import io.vertx.ext.web.RoutingContext - -@Endpoint -class IndexTemplate : Template() { - private val mHotLinks = mapOf() - - override val paths = listOf(Path("/*", RouteType.ROUTE)) - - override val order = 999 - - override fun getHandler() = Handler { context -> - val response = context.response() - val normalisedPath = context.normalizedPath() - - if (!mHotLinks[normalisedPath.lowercase()].isNullOrEmpty()) { - response.putHeader( - "location", - mHotLinks[normalisedPath.lowercase()] - ).setStatusCode(302).end() - - return@Handler - } - - response.setStatusCode(401).end() - } -} \ No newline at end of file