Skip to content

Commit

Permalink
Merge branch 'feature/downloads'
Browse files Browse the repository at this point in the history
  • Loading branch information
windy1 committed Feb 28, 2017
2 parents 609aa0b + 824b5e9 commit 008ce9e
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 216 deletions.
358 changes: 183 additions & 175 deletions app/controllers/project/Versions.scala

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion app/db/impl/schema.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ class DownloadWarningsTable(tag: Tag) extends ModelTable[DownloadWarning](tag, "
def versionId = column[Int]("version_id")
def address = column[InetString]("address")
def downloadId = column[Int]("download_id")
def isConfirmed = column[Boolean]("is_confirmed")

override def * = (id.?, createdAt.?, expiration, token, versionId, address,
override def * = (id.?, createdAt.?, expiration, token, versionId, address, isConfirmed,
downloadId) <> ((DownloadWarning.apply _).tupled, DownloadWarning.unapply)

}
Expand Down
1 change: 1 addition & 0 deletions app/db/impl/table/ModelKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ object ModelKeys {

// DownloadWarning
val DownloadId = new IntKey[DownloadWarning](_.downloadId, _.downloadId)
val IsConfirmed = new BooleanKey[DownloadWarning](_.isConfirmed, _.isConfirmed)

// Channel
val Color = new MappedTypeKey[Channel, Color](_.color, _.color)
Expand Down
8 changes: 8 additions & 0 deletions app/models/project/DownloadWarning.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ case class DownloadWarning(override val id: Option[Int] = None,
token: String,
versionId: Int,
address: InetString,
private var _isConfirmed: Boolean = false,
private var _downloadId: Int = -1) extends OreModel(id, createdAt) with Expirable {

override type M = DownloadWarning
override type T = DownloadWarningsTable

def isConfirmed: Boolean = this._isConfirmed

def setConfirmed(confirmed: Boolean = true) = Defined {
this._isConfirmed = confirmed
update(IsConfirmed)
}

/**
* Returns the ID of the download this warning was for.
*
Expand Down
10 changes: 2 additions & 8 deletions app/views/projects/versions/list.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,10 @@ <h2 class="versions-header">Versions</h2>
<div class="pull-right">
<span class="date">@prettifyDate(version.createdAt.get)</span>
<span class="date">@version.humanFileSize</span>
<a href="#" class="a-download"
data-form="form-download-@version.id.get">
<a href="@versionRoutes.download(
model.ownerName, model.slug, version.versionString, None)">
<i title="Download" class="fa fa-download"></i>
</a>
<form action="@versionRoutes.download(
model.ownerName, model.slug, version.versionString)"
method="post" style="display: none;"
id="form-download-@version.id.get">
@CSRF.formField
</form>
</div>
</td>
</tr>
Expand Down
10 changes: 5 additions & 5 deletions app/views/projects/versions/unsafeDownload.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@import views.html.helper.CSRF
@(project: Project,
target: Version,
origin: Option[String],
downloadType: DownloadType)(implicit messages: Messages, request: Request[_], service: ModelService,
downloadType: DownloadType,
token: String)(implicit messages: Messages, request: Request[_], service: ModelService,
config: OreConfig, users: UserBase)

@versionRoutes = @{ controllers.project.routes.Versions }
Expand All @@ -26,15 +26,15 @@ <h4 class="panel-title">
</div>
<div class="panel-body">
@Html(messages("version.download.confirm.body"))
<a href="@origin.getOrElse(versionRoutes.show(project.ownerName, project.slug, target.name))"
<a href="@versionRoutes.show(project.ownerName, project.slug, target.name)"
class="pull-left unsafe-dl-back">
<i class="fa fa-arrow-left"></i> @messages("project.back")
</a>
<button type="submit" form="form-download" class="pull-right btn btn-primary">
@messages("general.continue")
</button>
<form action="@versionRoutes.downloadUnsafely(
project.ownerName, project.slug, target.name, origin, Some(downloadType.id), None)"
<form action="@versionRoutes.confirmDownload(project.ownerName, project.slug, target.name,
Some(downloadType.id), token)"
method="post" style="display: none;" id="form-download">
@CSRF.formField
</form>
Expand Down
11 changes: 4 additions & 7 deletions app/views/projects/versions/view.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,11 @@ <h1 class="pull-left">@version.versionString</h1>
}
}

<button type="submit" form="form-download" class="btn btn-primary">
<a href="@versionRoutes.download(
project.ownerName, project.slug, version.versionString, None)"
class="btn btn-primary">
<i class="fa fa-download"></i> @messages("general.download")
</button>
<form action="@versionRoutes.download(
project.ownerName, project.slug, version.versionString)"
method="post" style="display: none;" id="form-download">
@CSRF.formField
</form>
</a>

</div>
</div>
Expand Down
11 changes: 4 additions & 7 deletions app/views/projects/view.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,11 @@ <h4 class="modal-title" id="label-flag">Flag project</h4>
}

<!-- Download button -->
<button form="form-download" type="submit" title="@messages("project.download.recommend")"
data-toggle="tooltip" data-placement="bottom" class="btn btn-primary">
<a href="@versionRoutes.downloadRecommended(project.ownerName, project.slug, None)"
title="@messages("project.download.recommend")" data-toggle="tooltip"
data-placement="bottom" class="btn btn-primary">
<i class="fa fa-download"></i> @messages("general.download")
</button>
<form action="@versionRoutes.downloadRecommended(project.ownerName, project.slug)"
method="post" style="display: none;" id="form-download">
@CSRF.formField
</form>
</a>
</div>
}
</div>
Expand Down
7 changes: 7 additions & 0 deletions conf/evolutions/default/70.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# --- !Ups

alter table project_version_download_warnings add column is_confirmed boolean not null default false;

# --- !Downs

alter table project_version_download_warnings drop column is_confirmed;
8 changes: 6 additions & 2 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,12 @@ version.download.confirm.body.plain = \
This version has not been reviewed by our moderation staff and may not be safe for download.\n\
Disclaimer: We disclaim all responsibility for any harm to your server or system should you choose not to heed this \
warning.\n\
Please use the following URL to acknowledge this disclaimer and continue to the download:\n\
{0}
Please use the following curl to acknowledge this disclaimer and continue to the download:\n\
curl -O -J -L -d -X "{0}&csrfToken={1}"

version.download.confirm.wget = Sorry, but Ore does not support the use of wget. \
Please use the following curl instead:\n\
curl -O -J -L "<url>"

channel.name = Channel name
channel.edit.title = Edit channel
Expand Down
22 changes: 11 additions & 11 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ GET /api/projects/:pluginId @controllers
GET /api/projects/:pluginId/versions @controllers.ApiController.listVersions(version = "v1", pluginId, channels: Option[String], limit: Option[Int], offset: Option[Int])
GET /api/projects/:pluginId/versions/:name @controllers.ApiController.showVersion(version = "v1", pluginId, name)

POST /api/projects/:pluginId/versions/recommended/download @controllers.project.Versions.downloadRecommendedJarById(pluginId)
POST /api/projects/:pluginId/versions/recommended/signature @controllers.project.Versions.downloadRecommendedSignatureById(pluginId)
POST /api/projects/:pluginId/versions/:name/download @controllers.project.Versions.downloadJarById(pluginId, name)
POST /api/projects/:pluginId/versions/:name/signature @controllers.project.Versions.downloadSignatureById(pluginId, name)
GET /api/projects/:pluginId/versions/recommended/download @controllers.project.Versions.downloadRecommendedJarById(pluginId, token: Option[String])
GET /api/projects/:pluginId/versions/recommended/signature @controllers.project.Versions.downloadRecommendedSignatureById(pluginId)
GET /api/projects/:pluginId/versions/:name/download @controllers.project.Versions.downloadJarById(pluginId, name, token: Option[String])
GET /api/projects/:pluginId/versions/:name/signature @controllers.project.Versions.downloadSignatureById(pluginId, name)

GET /api/users @controllers.ApiController.listUsers(version = "v1", limit: Option[Int], offset: Option[Int])
GET /api/users/:user @controllers.ApiController.showUser(version = "v1", user)
Expand Down Expand Up @@ -139,16 +139,16 @@ GET /:author/:slug/versions @controllers
POST /:author/:slug/versions/:version/approve @controllers.project.Versions.approve(author, slug, version)
POST /:author/:slug/versions/:version/delete @controllers.project.Versions.delete(author, slug, version)

GET /:author/:slug/versions/:version/confirm @controllers.project.Versions.showDownloadConfirm(author, slug, version, origin: Option[String], downloadType: Option[Int])
POST /:author/:slug/versions/:version/unsafe @controllers.project.Versions.downloadUnsafely(author, slug, version, origin: Option[String], downloadType: Option[Int], token: Option[String])
GET /:author/:slug/versions/:version/confirm @controllers.project.Versions.showDownloadConfirm(author, slug, version, downloadType: Option[Int])
POST /:author/:slug/versions/:version/confirm @controllers.project.Versions.confirmDownload(author, slug, version, downloadType: Option[Int], token)

POST /:author/:slug/versions/recommended/download @controllers.project.Versions.downloadRecommended(author, slug)
POST /:author/:slug/versions/recommended/signature @controllers.project.Versions.downloadRecommendedSignature(author, slug)
POST /:author/:slug/versions/:version/download @controllers.project.Versions.download(author, slug, version)
GET /:author/:slug/versions/recommended/download @controllers.project.Versions.downloadRecommended(author, slug, token: Option[String])
GET /:author/:slug/versions/recommended/signature @controllers.project.Versions.downloadRecommendedSignature(author, slug)
GET /:author/:slug/versions/:version/download @controllers.project.Versions.download(author, slug, version, token: Option[String])
GET /:author/:slug/versions/:version/signature @controllers.project.Versions.downloadSignature(author, slug, version)

POST /:author/:slug/versions/recommended/jar @controllers.project.Versions.downloadRecommendedJar(author, slug)
POST /:author/:slug/versions/:version/jar @controllers.project.Versions.downloadJar(author, slug, version)
GET /:author/:slug/versions/recommended/jar @controllers.project.Versions.downloadRecommendedJar(author, slug, token: Option[String])
GET /:author/:slug/versions/:version/jar @controllers.project.Versions.downloadJar(author, slug, version, token: Option[String])

GET /:author/:slug/versions/new @controllers.project.Versions.showCreator(author, slug)
POST /:author/:slug/versions/new/upload @controllers.project.Versions.upload(author, slug)
Expand Down

0 comments on commit 008ce9e

Please sign in to comment.