Commits

Joseph Walton committed 09888c2

Initial commit working against confxhtml.

Comments (0)

Files changed (4)

+Confluence Active User Speakeasy plugin
+
+Strikes through user links for users without an active account.
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.atlassian.labs.jwalton</groupId>
+    <artifactId>confluence-active-user-plugin</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <organization>
+        <name>Atlassian Labs</name>
+        <url>http://labs.atlassian.com/</url>
+    </organization>
+
+    <name>confluence-active-user-plugin</name>
+    <description>Strikes &lt;del>through&lt;/del> users without an active account.</description>
+    <packaging>atlassian-plugin</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.atlassian.confluence</groupId>
+            <artifactId>confluence</artifactId>
+            <version>${confluence.version}</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>com.atlassian.maven.plugins</groupId>
+                <artifactId>maven-confluence-plugin</artifactId>
+                <version>3.3-m7</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <productVersion>${confluence.version}</productVersion>
+                    <productDataVersion>${confluence.data.version}</productDataVersion>
+                    <pluginArtifacts>
+                        <pluginArtifact>
+                            <groupId>com.atlassian.labs</groupId>
+                            <artifactId>speakeasy-plugin</artifactId>
+                            <version>0.2</version>
+                        </pluginArtifact>
+                    </pluginArtifacts>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <properties>
+        <confluence.version>3.4</confluence.version>
+        <confluence.data.version>3.1</confluence.data.version>
+    </properties>
+</project>

src/main/resources/atlassian-plugin.xml

+<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
+    <plugin-info>
+        <description>${project.description}</description>
+        <version>${project.version}</version>
+        <vendor name="${project.organization.name}" url="${project.organization.url}" />
+    </plugin-info>
+
+    <scoped-web-resource key="strikethrough">
+        <resource type="download" name="strikethrough.js" location="js/strikethrough.js" />
+        <context>page</context>
+        <context>blogpost</context>
+    </scoped-web-resource>
+</atlassian-plugin>

src/main/resources/js/strikethrough.js

+jQuery(function() {
+  var userElements = {};
+
+  // Gather the user links by name
+  jQuery('.confluence-userlink').each(function() {
+    var link = jQuery(this);
+
+    var username = link.attr('data-username');
+
+    var list;
+
+    list = userElements[username];
+
+    if (list) {
+      list.push(link);
+    } else {
+      userElements[username] = [link];
+    }
+  });
+
+  // Check for each user referenced
+  for (var username in userElements) {
+    strikeUser(username, userElements[username]);
+  }
+});
+
+function strikeUser(username, elements)
+{
+//  strikeUserWithRestCall(username, elements);
+  strikeUserWithPopupScraping(username, elements);
+}
+
+/* Use a custom REST service */
+function strikeUserWithRestCall(username, elements)
+{
+  var serviceUrl = '/confluence/rest/active/1/' + username;
+
+  jQuery.ajax({
+    url: serviceUrl,
+    success: function(data) {
+      window.alert('Requested for ' + username + " (" + elements.length + ")");
+      if ("true" != data) {
+        elements.forEach(function(e) {
+          e.wrap('<del>');
+        });
+      }
+    },
+    failure: function() {
+//      window.alert('Failure for ' + username);
+    }
+  });
+}
+
+/**
+ * Use the user profile popup. Rely on only
+ *  active users having a link marked with the 'follow-text' class.
+ */
+function strikeUserWithPopupScraping(username, elements)
+{
+  var serviceUrl = '/users/userinfopopup.action?username=' + username;
+
+  jQuery.ajax({
+    url: serviceUrl,
+    success: function(data) {
+      var div = jQuery(data);
+
+      if (jQuery('.follow-text', div).length == 0) {
+        elements.forEach(function(e) {
+          e.wrap('<del>');
+        });
+      }
+    },
+    failure: function() {
+//      window.alert('Failure for ' + username);
+    }
+  });
+}