Commits

Stefan Saasen committed fea4137

Show an error message if the HipChat API token key is missing.

Comments (0)

Files changed (2)

src/main/resources/templates/macro/hipchat-token-missing.vm

+<div class="error">
+    The HipChat API token is missing.
+    Please create a HipChat token and <a href="../../admin/hipchat.action">configure it here.</a>
+</div>

src/main/scala/com/atlassian/plugins/polyglot/scalaexample/macro/HipChatMacro.scala

 /**
  * Macro that provides the initial data required to show the recent messages in a HipChat chat room.
  */
-class HipChatMacro(val templateRenderer:TemplateRenderer) extends Macro
+class HipChatMacro(val templateRenderer:TemplateRenderer, val pluginSettings: CustomPluginSettings) extends Macro
   with TemplateEngineAware with EditorImagePlaceholder {
 
   def execute(params: JMap[String, String], body: String, context: ConversionContext) = {
     val writer = new StringWriter()
-    val context = Map[String,AnyRef]("remoteUser" -> AuthenticatedUserThreadLocal.getUser, "roomId" -> (params.get("roomId") getOrElse "0"))
-    render(writer, "/templates/macro/hipchat-history.vm", context)
+    pluginSettings.authenticationToken match {
+      case Some(token) => {
+        val context = Map[String,AnyRef]("remoteUser" -> AuthenticatedUserThreadLocal.getUser, "roomId" -> (params.get("roomId") getOrElse "0"))
+        render(writer, "/templates/macro/hipchat-history.vm", context)
+      }
+      case None => render(writer, "/templates/macro/hipchat-token-missing.vm", Map[String,AnyRef]())
+    }
+
     writer.toString
   }