diff --git a/app/controllers/project/Projects.scala b/app/controllers/project/Projects.scala index 0720f8527..5ed763b1b 100755 --- a/app/controllers/project/Projects.scala +++ b/app/controllers/project/Projects.scala @@ -34,6 +34,8 @@ class Projects @Inject()(stats: StatTracker, implicit override val service: ModelService) extends BaseController { + implicit val fileManager = factory.fileManager + private val self = controllers.project.routes.Projects private def SettingsEditAction(author: String, slug: String) diff --git a/app/models/project/ProjectSettings.scala b/app/models/project/ProjectSettings.scala index 6846a95de..7ad0a5042 100644 --- a/app/models/project/ProjectSettings.scala +++ b/app/models/project/ProjectSettings.scala @@ -1,5 +1,7 @@ package models.project +import java.nio.file.Files +import java.nio.file.Files._ import java.sql.Timestamp import db.impl.ProjectSettingsTable @@ -9,12 +11,15 @@ import form.project.ProjectSettingsForm import models.user.Notification import models.user.role.ProjectRole import ore.permission.role.RoleTypes +import ore.project.io.ProjectFileManager import ore.project.{Categories, ProjectOwned} import ore.user.notification.NotificationTypes import play.api.Logger import play.api.i18n.MessagesApi import util.StringUtils._ +import scala.collection.JavaConverters._ + /** * Represents a [[Project]]'s settings. * @@ -115,7 +120,8 @@ case class ProjectSettings(override val id: Option[Int] = None, * @param messages MessagesApi instance */ //noinspection ComparingUnrelatedTypes - def save(project: Project, formData: ProjectSettingsForm)(implicit messages: MessagesApi) = { + def save(project: Project, formData: ProjectSettingsForm)(implicit messages: MessagesApi, + fileManager: ProjectFileManager) = { Logger.info("Saving project settings") Logger.info(formData.toString) @@ -130,6 +136,17 @@ case class ProjectSettings(override val id: Option[Int] = None, // Update the owner if needed formData.ownerId.find(_ != project.ownerId).foreach(ownerId => project.owner = this.userBase.get(ownerId).get) + // Update icon + if (formData.updateIcon) { + fileManager.getPendingIconPath(project).foreach { pendingPath => + val iconDir = fileManager.getIconDir(project.ownerName, project.name) + if (notExists(iconDir)) + createDirectories(iconDir) + list(iconDir).iterator().asScala.foreach(delete) + move(pendingPath, iconDir.resolve(pendingPath.getFileName)) + } + } + // Handle member changes if (project.isDefined) { // Add new roles diff --git a/build.sbt b/build.sbt index 7e026790f..0a4ea5e90 100755 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ name := "ore" -version := "1.1.2" +version := "1.1.3" lazy val `ore` = (project in file(".")).enablePlugins(PlayScala)