Skip to content

Commit 6d62a7e

Browse files
Felix KleinekathöferKatrixFaithcaioZidane
authored
Merge staging into production (#1041)
* Update dependencies (#1013) * Update dependencies * Fix tests * Workdarounds and go back to previous versions * Remove ZMX for now * Remove zio's Duration * Combine user and key perms correctly * Add build info to health report page (#1018) * Fix a bunch of warnings from Slick and it's outdated syntax (#1017) * Fix discourse auth params (#1019) * Fix discourse auth params * Fix stack overflow * Use Api-Key in the header for sync sso (#1022) * add support for API8 sponge plugins (#1039) * Update a bunch of dependencies Co-authored-by: Katrix <katrix97@hotmail.com> Co-authored-by: Faithcaio <Faithcaio@users.noreply.github.com> Co-authored-by: Chris Sanders <zidane@spongepowered.org>
1 parent 8bde79e commit 6d62a7e

77 files changed

Lines changed: 493 additions & 315 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ src_managed/
7777
project/boot/
7878
project/plugins/project/
7979
/.jvmopts
80+
.bsp
8081

8182
# Scala-IDE specific
8283
.scala_dependencies

apiV2/app/db/impl/query/APIV2Queries.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import ore.permission.Permission
2121

2222
import cats.Reducible
2323
import cats.data.NonEmptyList
24-
import cats.instances.list._
2524
import cats.syntax.all._
2625
import doobie._
2726
import doobie.implicits._
@@ -191,7 +190,7 @@ object APIV2Queries extends WebDoobieOreProtocol {
191190
limit: Long,
192191
offset: Long
193192
)(
194-
implicit projectFiles: ProjectFiles[ZIO[Blocking, Nothing, ?]],
193+
implicit projectFiles: ProjectFiles[ZIO[Blocking, Nothing, *]],
195194
requestHeader: RequestHeader,
196195
config: OreConfig
197196
): Query0[ZIO[Blocking, Nothing, APIV2.Project]] = {

apiV2/app/models/querymodels/apiV2QueryModels.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import ore.models.user.User
1717
import ore.permission.role.Role
1818
import util.syntax._
1919

20-
import cats.instances.either._
21-
import cats.instances.vector._
2220
import cats.kernel.Order
2321
import cats.syntax.all._
2422
import io.circe.{DecodingFailure, Json}

auth/src/main/scala/ore/auth/AkkaSpongeAuthApi.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import akka.http.scaladsl.model._
1313
import akka.stream.Materializer
1414
import cats.effect.Concurrent
1515
import cats.effect.concurrent.Ref
16-
import cats.instances.list._
1716
import cats.syntax.all._
1817
import com.typesafe.scalalogging
1918
import io.circe.{Decoder, Json}

build.sbt

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
ThisBuild / turbo := true
2+
ThisBuild / usePipelining := true
23
ThisBuild / scalaVersion := Settings.scalaVer
34

4-
//ThisBuild / semanticdbEnabled := true
5-
Global / semanticdbVersion := "4.2.3"
6-
75
lazy val db = project.settings(
86
Settings.commonSettings,
97
name := "ore-db",
@@ -136,15 +134,15 @@ lazy val oreClient = project
136134
useYarn := true,
137135
scalaJSUseMainModuleInitializer := false,
138136
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },
139-
webpackConfigFile in fastOptJS := Some(baseDirectory.value / "webpack.config.dev.js"),
140-
webpackConfigFile in fullOptJS := Some(baseDirectory.value / "webpack.config.prod.js"),
137+
fastOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.dev.js"),
138+
fullOptJS / webpackConfigFile := Some(baseDirectory.value / "webpack.config.prod.js"),
141139
webpackMonitoredDirectories += baseDirectory.value / "assets",
142-
includeFilter in webpackMonitoredFiles := "*.vue" || "*.js",
143-
webpackBundlingMode in fastOptJS := BundlingMode.LibraryOnly(),
144-
webpackBundlingMode in fullOptJS := BundlingMode.LibraryOnly(),
145-
version in startWebpackDevServer := NPMDeps.webpackDevServer,
146-
version in webpack := NPMDeps.webpack,
147-
npmDependencies in Compile ++= Seq(
140+
webpackMonitoredFiles / includeFilter := "*.vue" || "*.js",
141+
fastOptJS / webpackBundlingMode := BundlingMode.LibraryOnly(),
142+
fullOptJS / webpackBundlingMode := BundlingMode.LibraryOnly(),
143+
startWebpackDevServer / version := NPMDeps.webpackDevServer,
144+
webpack / version := NPMDeps.webpack,
145+
Compile / npmDependencies ++= Seq(
148146
NPMDeps.vue,
149147
NPMDeps.lodash,
150148
NPMDeps.queryString,
@@ -153,7 +151,7 @@ lazy val oreClient = project
153151
NPMDeps.fontAwesomeRegular,
154152
NPMDeps.fontAwesomeBrands
155153
),
156-
npmDevDependencies in Compile ++= Seq(
154+
Compile / npmDevDependencies ++= Seq(
157155
NPMDeps.webpackMerge,
158156
NPMDeps.vueLoader,
159157
NPMDeps.vueTemplateCompiler,
@@ -175,7 +173,7 @@ lazy val oreClient = project
175173
)
176174

177175
lazy val ore = project
178-
.enablePlugins(PlayScala, SwaggerPlugin, WebScalaJSBundlerPlugin)
176+
.enablePlugins(PlayScala, SwaggerPlugin, WebScalaJSBundlerPlugin, BuildInfoPlugin)
179177
.dependsOn(orePlayCommon, apiV2)
180178
.settings(
181179
Settings.commonSettings,
@@ -190,8 +188,7 @@ lazy val ore = project
190188
Deps.circeDerivation,
191189
Deps.circeParser,
192190
Deps.macwire,
193-
Deps.periscopeAkka,
194-
Deps.zioZmx
191+
Deps.periscopeAkka
195192
),
196193
libraryDependencies ++= Deps.flexmarkDeps,
197194
libraryDependencies ++= Seq(
@@ -215,9 +212,16 @@ lazy val ore = project
215212
PlayKeys.playMonitoredFiles += baseDirectory.value / "swagger.yml",
216213
PlayKeys.playMonitoredFiles += baseDirectory.value / "swagger-custom-mappings.yml",
217214
scalaJSProjects := Seq(oreClient),
218-
pipelineStages in Assets += scalaJSPipeline,
219-
WebKeys.exportedMappings in Assets := Seq(),
220-
PlayKeys.playMonitoredFiles += (oreClient / baseDirectory).value / "assets"
215+
Assets / pipelineStages += scalaJSPipeline,
216+
Assets / WebKeys.exportedMappings := Seq(),
217+
PlayKeys.playMonitoredFiles += (oreClient / baseDirectory).value / "assets",
218+
buildInfoKeys := Seq[BuildInfoKey](version, scalaVersion, resolvers, libraryDependencies),
219+
buildInfoOptions += BuildInfoOption.BuildTime,
220+
buildInfoPackage := "ore",
221+
//sbt 1.4 workaround
222+
play.sbt.PlayInternalKeys.playCompileEverything ~= (_.map(
223+
_.copy(compilations = sbt.internal.inc.Compilations.of(Seq.empty))
224+
))
221225
)
222226

223227
lazy val oreAll =

db/src/main/scala/ore/db/access/DefaultRunningView.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class DefaultRunningView[F[_], T, M](val profile: JdbcProfile)(
4646
): DefaultRunningView[F, T, M] = new DefaultRunningView[F, T, M](profile)(queryView.modifyingQuery(f), runAction)
4747
}
4848
object DefaultRunningView {
49-
implicit def defaultRunningViewIsQueryView[F[_]]: QueryView[DefaultRunningView[F, ?, ?]] =
50-
new QueryView[DefaultRunningView[F, ?, ?]] {
49+
implicit def defaultRunningViewIsQueryView[F[_]]: QueryView[DefaultRunningView[F, *, *]] =
50+
new QueryView[DefaultRunningView[F, *, *]] {
5151
override def modifyingView[T, M](fa: DefaultRunningView[F, T, M])(
5252
f: fa.profile.api.Query[T, M, Seq] => fa.profile.api.Query[T, M, Seq]
5353
): DefaultRunningView[F, T, M] = fa.modifyingQuery(f)

db/src/main/scala/ore/db/access/ModelView.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ object ModelView {
100100
type Later[T, M] = ModelView[Query[T, M, Seq], Rep, T, M]
101101
type Raw[T, M] = Query[T, M, Seq]
102102

103-
implicit def modelViewIsQueryView[QueryOptRet, SingleRet[_]]: QueryView[ModelView[QueryOptRet, SingleRet, ?, ?]] =
104-
new QueryView[ModelView[QueryOptRet, SingleRet, ?, ?]] {
103+
implicit def modelViewIsQueryView[QueryOptRet, SingleRet[_]]: QueryView[ModelView[QueryOptRet, SingleRet, *, *]] =
104+
new QueryView[ModelView[QueryOptRet, SingleRet, *, *]] {
105105
override def modifyingView[T, M](fa: ModelView[QueryOptRet, SingleRet, T, M])(
106106
f: Query[T, M, Seq] => Query[T, M, Seq]
107107
): ModelView[QueryOptRet, SingleRet, T, M] = fa.modifyingQuery(f)

db/src/main/scala/ore/db/access/QueryView.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait QueryView[F[_, _]] {
1515
}
1616
object QueryView {
1717

18-
implicit val queryIsQueryView: QueryView[Query[?, ?, Seq]] = new QueryView[Query[?, ?, Seq]] {
18+
implicit val queryIsQueryView: QueryView[Query[*, *, Seq]] = new QueryView[Query[*, *, Seq]] {
1919
override def modifyingView[T, M](fa: Query[T, M, Seq])(
2020
f: Query[T, M, Seq] => Query[T, M, Seq]
2121
): Query[T, M, Seq] = f(fa)

discourse/src/main/scala/ore/discourse/AkkaDiscourseApi.scala

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ore.discourse
22

3-
import scala.language.higherKinds
4-
53
import scala.concurrent.duration._
64

75
import ore.discourse.AkkaDiscourseApi.AkkaDiscourseSettings
@@ -13,9 +11,9 @@ import akka.stream.Materializer
1311
import cats.data.EitherT
1412
import cats.effect.Concurrent
1513
import cats.effect.concurrent.Ref
16-
import cats.instances.either._
1714
import cats.syntax.all._
1815
import com.typesafe.scalalogging
16+
import com.typesafe.scalalogging.Logger
1917
import io.circe._
2018

2119
class AkkaDiscourseApi[F[_]] private (
@@ -28,16 +26,13 @@ class AkkaDiscourseApi[F[_]] private (
2826
) extends AkkaClientApi[F, cats.Id, DiscourseError]("Discourse", counter, settings)
2927
with DiscourseApi[F] {
3028

31-
protected val Logger = scalalogging.Logger("DiscourseApi")
29+
protected val Logger: Logger = scalalogging.Logger("DiscourseApi")
3230

33-
private def startParams(poster: Option[String]) = Seq(
34-
"api_key" -> settings.apiKey,
35-
"api_username" -> poster.getOrElse(settings.adminUser)
31+
private def authHeaders(poster: Option[String]) = Seq(
32+
`Api-Key`(settings.apiKey),
33+
`Api-Username`(poster.getOrElse(settings.adminUser))
3634
)
3735

38-
private def apiQuery(poster: Option[String]) =
39-
Uri.Query("api_key" -> settings.apiKey, "api_username" -> poster.getOrElse(settings.adminUser))
40-
4136
override def createStatusError(statusCode: StatusCode, message: Option[String]): DiscourseError = statusCode match {
4237
case StatusCodes.TooManyRequests =>
4338
message match {
@@ -89,7 +84,7 @@ class AkkaDiscourseApi[F[_]] private (
8984
content: String,
9085
categoryId: Option[Int]
9186
): F[Either[DiscourseError, DiscoursePost]] = {
92-
val base = startParams(Some(poster)) ++ Seq(
87+
val base = Seq(
9388
"title" -> title,
9489
"raw" -> content
9590
)
@@ -100,13 +95,14 @@ class AkkaDiscourseApi[F[_]] private (
10095
HttpRequest(
10196
HttpMethods.POST,
10297
apiUri(_ / "posts.json"),
98+
headers = authHeaders(Some(poster)),
10399
entity = FormData(withCat: _*).toEntity
104100
)
105101
)
106102
}
107103

108104
override def createPost(poster: String, topicId: Int, content: String): F[Either[DiscourseError, DiscoursePost]] = {
109-
val params = startParams(Some(poster)) ++ Seq(
105+
val params = Seq(
110106
"topic_id" -> topicId.toString,
111107
"raw" -> content
112108
)
@@ -115,6 +111,7 @@ class AkkaDiscourseApi[F[_]] private (
115111
HttpRequest(
116112
HttpMethods.POST,
117113
apiUri(_ / "posts.json"),
114+
headers = authHeaders(Some(poster)),
118115
entity = FormData(params: _*).toEntity
119116
)
120117
)
@@ -128,7 +125,7 @@ class AkkaDiscourseApi[F[_]] private (
128125
): F[Either[DiscourseError, Unit]] = {
129126
if (title.isEmpty && categoryId.isEmpty) F.pure(Right(()))
130127
else {
131-
val base = startParams(Some(poster)) :+ ("topic_id" -> topicId.toString)
128+
val base = Seq("topic_id" -> topicId.toString)
132129

133130
val withTitle = title.fold(base)(t => base :+ ("title" -> t))
134131
val withCat = categoryId.fold(withTitle)(c => withTitle :+ ("category_id" -> c.toString))
@@ -137,20 +134,20 @@ class AkkaDiscourseApi[F[_]] private (
137134
HttpRequest(
138135
HttpMethods.PUT,
139136
apiUri(_ / "t" / "-" / s"$topicId.json"),
137+
headers = authHeaders(Some(poster)),
140138
entity = FormData(withCat: _*).toEntity
141139
)
142140
).map(_.void)
143141
}
144142
}
145143

146144
override def updatePost(poster: String, postId: Int, content: String): F[Either[DiscourseError, Unit]] = {
147-
val params = startParams(Some(poster)) :+ ("post[raw]" -> content)
148-
149145
makeUnmarshallRequestEither[Json](
150146
HttpRequest(
151147
HttpMethods.PUT,
152148
apiUri(_ / "posts" / s"$postId.json"),
153-
entity = FormData(params: _*).toEntity
149+
headers = authHeaders(Some(poster)),
150+
entity = FormData("post[raw]" -> content).toEntity
154151
)
155152
).map(_.void)
156153
}
@@ -161,7 +158,8 @@ class AkkaDiscourseApi[F[_]] private (
161158
makeRequest(
162159
HttpRequest(
163160
HttpMethods.DELETE,
164-
apiUri(_ / "t" / s"$topicId.json").withQuery(apiQuery(Some(poster)))
161+
apiUri(_ / "t" / s"$topicId.json"),
162+
headers = authHeaders(Some(poster))
165163
)
166164
)
167165
)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ore.discourse
2+
3+
import scala.util.{Success, Try}
4+
5+
import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
6+
7+
case class `Api-Key`(key: String) extends ModeledCustomHeader[`Api-Key`] {
8+
override def companion: ModeledCustomHeaderCompanion[`Api-Key`] = `Api-Key`
9+
10+
override def value: String = key
11+
override def renderInRequests: Boolean = true
12+
override def renderInResponses: Boolean = false
13+
}
14+
object `Api-Key` extends ModeledCustomHeaderCompanion[`Api-Key`] {
15+
override def name: String = "Api-Key"
16+
override def parse(value: String): Try[`Api-Key`] = Success(new `Api-Key`(value))
17+
}
18+
19+
case class `Api-Username`(username: String) extends ModeledCustomHeader[`Api-Username`] {
20+
override def companion: ModeledCustomHeaderCompanion[`Api-Username`] = `Api-Username`
21+
22+
override def value: String = username
23+
override def renderInRequests: Boolean = true
24+
override def renderInResponses: Boolean = false
25+
}
26+
object `Api-Username` extends ModeledCustomHeaderCompanion[`Api-Username`] {
27+
override def name: String = "Api-Username"
28+
override def parse(value: String): Try[`Api-Username`] = Success(new `Api-Username`(value))
29+
}

0 commit comments

Comments
 (0)