Skip to content
This repository was archived by the owner on Sep 7, 2023. It is now read-only.

Commit 332feea

Browse files
author
Barry de Graaff
committed
release more robust version of integration, prepare compatiblity with Zimbra 9 Zimlet
1 parent 6380b9b commit 332feea

File tree

8 files changed

+13
-119
lines changed

8 files changed

+13
-119
lines changed

extension/.idea/workspace.xml

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.

extension/src/tk/barrydegraaff/rocket/Rocket.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOExc
225225
case "createUser":
226226
String password = newPassword();
227227
if (this.createUser(zimbraAccount.getName(), zimbraAccount.getGivenName() + " " + zimbraAccount.getSn(), password, zimbraAccount.getName().replace("@", "."), zimbraAccount)) {
228+
resp.setHeader("Content-Type", "text/plain");
228229
responseWriter("ok", resp, password);
229230
} else {
230231
responseWriter("error", resp, null);
@@ -260,17 +261,20 @@ private void responseWriter(String action, HttpServletResponse resp, String mess
260261
case "ok":
261262
resp.setStatus(HttpServletResponse.SC_OK);
262263
if (message == null) {
264+
resp.setHeader("Content-Type", "text/plain");
263265
resp.getWriter().write("OK");
264266
} else {
265267
resp.getWriter().write(message);
266268
}
267269
break;
268270
case "unauthorized":
269271
resp.setHeader("Content-Type", "text/html");
272+
resp.setStatus(HttpServletResponse.SC_OK);
270273
resp.getWriter().write("<html><head></head><body><div style=\"background-color:white;color:black;padding:10px\">Please <a target=\"_blank\" href=\"" + this.loginurl + "\">Log in</a>.</div></body>");
271274
break;
272275
case "error":
273-
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
276+
resp.setHeader("Content-Type", "text/plain");
277+
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
274278
resp.getWriter().write("The request did not succeed successfully.");
275279
break;
276280
}

zimlet/com_zimbra_rocket/com_zimbra_rocket.css

100755100644
File mode changed.

zimlet/com_zimbra_rocket/com_zimbra_rocket.js

100755100644
Lines changed: 6 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ ZimbraRocketZimlet.prototype.init = function () {
1010
try {
1111
var zimletInstance = appCtxt._zimletMgr.getZimletByName('com_zimbra_rocket').handlerObject;
1212
zimletInstance.rocketurl = zimletInstance._zimletContext.getConfig("rocketurl");
13-
zimletInstance.createRocketAccount = zimletInstance._zimletContext.getConfig("createRocketAccount");
14-
zimletInstance.accountCreateInteger = zimletInstance._zimletContext.getConfig("accountCreateInteger");
15-
zimletInstance.userAccountCreateInteger = zimletInstance.getUserProperty("accountCreateInteger")
13+
zimletInstance.createRocketAccount = zimletInstance._zimletContext.getConfig("createRocketAccount");
1614

1715
if(!zimletInstance.userAccountCreateInteger)
1816
{
@@ -21,15 +19,7 @@ ZimbraRocketZimlet.prototype.init = function () {
2119

2220
if(zimletInstance.createRocketAccount == "true")
2321
{
24-
if(parseInt(zimletInstance.accountCreateInteger) > parseInt(zimletInstance.userAccountCreateInteger))
25-
{
26-
zimletInstance.setUserProperty("accountCreateInteger", zimletInstance.accountCreateInteger, true);
27-
ZimbraRocketZimlet.prototype.createAccount();
28-
}
29-
else
30-
{
31-
ZimbraRocketZimlet.prototype.setIframe();
32-
}
22+
ZimbraRocketZimlet.prototype.createAccount();
3323
}
3424
else
3525
{
@@ -52,25 +42,6 @@ ZimbraRocketZimlet.prototype.setIframe = function()
5242
} catch (err) { console.log (err)}
5343
};
5444

55-
/* status method show a Zimbra status message
56-
* */
57-
ZimbraRocketZimlet.prototype.status = function(text, type) {
58-
var transitions = [ ZmToast.FADE_IN, ZmToast.PAUSE, ZmToast.FADE_OUT ];
59-
appCtxt.getAppController().setStatusMsg(text, type, null, transitions);
60-
};
61-
62-
/* Called when the panel is double-clicked.
63-
*/
64-
ZimbraRocketZimlet.prototype.doubleClicked = function() {
65-
this.singleClicked();
66-
};
67-
68-
/* Called when the panel is single-clicked.
69-
*/
70-
ZimbraRocketZimlet.prototype.singleClicked = function() {
71-
72-
};
73-
7445
/**
7546
* This method gets called by the Zimlet framework each time the application is opened or closed.
7647
*
@@ -124,58 +95,12 @@ ZimbraRocketZimlet.prototype.createAccount = function()
12495
console.log(err);
12596
};
12697

127-
xhr.send();
128-
xhr.onreadystatechange = function (oEvent)
98+
xhr.onload = function (oEvent)
12999
{
130-
if (xhr.readyState === 4)
131-
{
132-
if (xhr.status === 200)
133-
{
134-
if(xhr.response)
135-
{
136-
var zimletInstance = appCtxt._zimletMgr.getZimletByName('com_zimbra_rocket').handlerObject;
137-
zimletInstance._dialog = new ZmDialog( { title:'Your Rocket Chat Account is created', parent:zimletInstance.getShell(), standardButtons:[DwtDialog.OK_BUTTON], disposeOnPopDown:true } );
138-
zimletInstance._dialog.setContent(
139-
'<div style="width:450px; height:160px;">'+
140-
'Your Rocket Chat account has been created!<br><br>'+
141-
'Here are your credentials for the Rocket.Chat App on Android and iPhone:<br>'+
142-
'<textarea style="width:100%" rows=2>Username: '+appCtxt.getActiveAccount().name.replace('@','.')+'\r\nPassword: '+xhr.response+'</textarea><br><br>'+
143-
'Please store these credentials.<br>'+
144-
'</div>'
145-
);
146-
147-
zimletInstance._dialog.setButtonListener(DwtDialog.OK_BUTTON, new AjxListener(zimletInstance, zimletInstance._cancelBtn));
148-
zimletInstance._dialog.setEnterListener(new AjxListener(zimletInstance, zimletInstance._cancelBtn));
149-
150-
document.getElementById(zimletInstance._dialog.__internalId+'_handle').style.backgroundColor = '#eeeeee';
151-
document.getElementById(zimletInstance._dialog.__internalId+'_title').style.textAlign = 'center';
152-
zimletInstance._dialog.popup();
153-
ZimbraRocketZimlet.prototype.setIframe();
154-
}
155-
}
156-
if (xhr.status === 500)
157-
{
158-
if(xhr.response)
159-
{
160-
ZimbraRocketZimlet.prototype.status("Could not create your Rocket Chat Account", ZmStatusView.LEVEL_CRITICAL);
161-
ZimbraRocketZimlet.prototype.setIframe();
162-
}
163-
}
164-
165-
}
166-
}
100+
ZimbraRocketZimlet.prototype.setIframe();
101+
};
102+
xhr.send();
167103
} catch (err) {
168104
console.log(err);
169105
}
170106
};
171-
172-
ZimbraRocketZimlet.prototype._cancelBtn =
173-
function() {
174-
var zimletInstance = appCtxt._zimletMgr.getZimletByName('com_zimbra_rocket').handlerObject;
175-
176-
try{
177-
zimletInstance._dialog.setContent('');
178-
zimletInstance._dialog.popdown();
179-
}
180-
catch (err) {}
181-
};

zimlet/com_zimbra_rocket/com_zimbra_rocket.xml

100755100644
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<zimlet name="com_zimbra_rocket"
2-
version="0.0.4"
2+
version="0.0.5"
33
target="main compose-window view-window"
44
label="Zimbra Rocket"
55
description="Zimbra Rocket">
66
<include>com_zimbra_rocket.js</include>
77
<includeCSS>com_zimbra_rocket.css</includeCSS>
88
<handlerObject>com_zimbra_rocket_HandlerObject</handlerObject>
9-
<userProperties>
10-
<property type="string" label="" name="accountCreateInteger" rows="1"/>
11-
</userProperties>
129
</zimlet>

zimlet/com_zimbra_rocket/config_template.xml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,12 @@ rocketurl = the url to your rocket chat instance
88
The rocket Zimbra server extension automatically creates
99
accounts for each Zimbra account in Rocket, to enable account
1010
creation set createRocketAccount = true
11-
12-
accountCreateInteger (for migration purposes)
13-
14-
Whenever the account has been created by Zimbra the accountCreateInteger
15-
on the Users Zimlet userProperties is incremented. The Zimlet will not
16-
re-attempt to create the users account, unless the accountCreateInteger
17-
in the Users Zimlet userProperties is < the one set in the Zimlets configuration
18-
template.
19-
20-
This will help you in case you want to run a fresh install of Rocket, but with
21-
an existing deployment of Zimbra OR in case you merge multiple Zimbra instances
22-
to a single instance. In which case you can increment the accountCreateInteger
23-
in the configuration template to make sure all users have their account
24-
created.
25-
11+
2612
-->
2713
<zimletConfig name="com_zimbra_rocket" version="1.0">
2814
<global>
2915
<property name="rocketurl">https://rocketserverhere.org/</property>
3016
<property name="createRocketAccount">true</property>
31-
<property name="accountCreateInteger">1</property>
3217
</global>
3318
</zimletConfig>
3419

0 commit comments

Comments
 (0)