diff options
author | Endi S. Dewata <edewata@redhat.com> | 2016-02-03 19:20:31 +0100 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2016-02-05 22:40:44 +0100 |
commit | 9bd94a0a54793a0720b803846ce2291e5064c2ae (patch) | |
tree | 0e0d5731923844454c23fc89e7a10b5abb708a58 /base/tps | |
parent | 987dda15acdd6e6f4c7c477fed122a76ad40260c (diff) | |
download | pki-9bd94a0a54793a0720b803846ce2291e5064c2ae.tar.gz pki-9bd94a0a54793a0720b803846ce2291e5064c2ae.tar.xz pki-9bd94a0a54793a0720b803846ce2291e5064c2ae.zip |
Added resource bundle for token state labels.
The labels for token states and the transitions are now stored
in token-states.properties. The default file will be stored
in the /usr/share/pki/tps/conf, but it can be overriden by
copying and customizing the file into <instance>/tps/conf.
When the UI retrieves the token data the labels for the current
state and the valid transitions will be loaded from the file
and returned to the UI. The UI will show the transition labels
in the dropdown list for changing token status.
https://fedorahosted.org/pki/ticket/1289
https://fedorahosted.org/pki/ticket/1291
Diffstat (limited to 'base/tps')
-rw-r--r-- | base/tps/shared/conf/token-states.properties | 21 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/js/token.js | 43 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/ui/token.html | 2 | ||||
-rw-r--r-- | base/tps/shared/webapps/tps/ui/tokens.html | 2 | ||||
-rw-r--r-- | base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java | 27 |
5 files changed, 68 insertions, 27 deletions
diff --git a/base/tps/shared/conf/token-states.properties b/base/tps/shared/conf/token-states.properties new file mode 100644 index 000000000..f67688d4b --- /dev/null +++ b/base/tps/shared/conf/token-states.properties @@ -0,0 +1,21 @@ +# Token states +UNINITIALIZED = Uninitialized +ACTIVE = Active +TEMP_LOST = Temporarily lost +PERM_LOST = Permanently lost +DAMAGED = Physically damaged +TEMP_LOST_PERM_LOST = Temporarily lost then permanently lost +TERMINATED = Terminated + +# Token state transitions +UNINITIALIZED.DAMAGED = This token has been physically damaged. +UNINITIALIZED.PERM_LOST = This token has been permanently lost. +UNINITIALIZED.TEMP_LOST = This token has been temporarily lost. +UNINITIALIZED.TERMINATED = This token has been terminated. +TEMP_LOST.ACTIVE = This temporarily lost token has been found. +TEMP_LOST.PERM_LOST = This temporarily lost token has become permanently lost. +TEMP_LOST.TERMINATED = This temporarily lost token has been terminated. +ACTIVE.DAMAGED = This token has been physically damaged. +ACTIVE.PERM_LOST = This token has been permanently lost. +ACTIVE.TEMP_LOST = This token has been temporarily lost. +ACTIVE.TERMINATED = This token has been terminated. diff --git a/base/tps/shared/webapps/tps/js/token.js b/base/tps/shared/webapps/tps/js/token.js index b4d5a717b..fb1c3ea46 100644 --- a/base/tps/shared/webapps/tps/js/token.js +++ b/base/tps/shared/webapps/tps/js/token.js @@ -19,16 +19,6 @@ * @author Endi S. Dewata */ -var TokenStatus = { - UNINITIALIZED: "Uninitialized", - ACTIVE: "Active", - TEMP_LOST: "Temporarily lost", - PERM_LOST: "Permanently lost", - DAMAGED: "Physically damaged", - TEMP_LOST_PERM_LOST: "Temporarily lost then permanently lost", - TERMINATED: "Terminated" -}; - var TokenModel = Model.extend({ urlRoot: "/tps/rest/tokens", parseResponse: function(response) { @@ -38,7 +28,6 @@ var TokenModel = Model.extend({ userID: response.UserID, type: response.Type, status: response.Status, - statusLabel: TokenStatus[response.Status], nextStates: response.NextStates, appletID: response.AppletID, keyInfo: response.KeyInfo, @@ -53,7 +42,6 @@ var TokenModel = Model.extend({ TokenID: attributes.tokenID, UserID: attributes.userID, Type: attributes.type, - Status: attributes.status, AppletID: attributes.appletID, KeyInfo: attributes.keyInfo, Policy: attributes.policy, @@ -92,7 +80,6 @@ var TokenCollection = Collection.extend({ userID: entry.UserID, type: entry.Type, status: entry.Status, - statusLabel: TokenStatus[entry.Status], nextStates: entry.NextStates, appletID: entry.AppletID, keyInfo: entry.KeyInfo, @@ -114,19 +101,19 @@ var TokenDialog = Dialog.extend({ } var select = input.empty(); - var status = self.entry["status"]; + var status = self.entry.status; $('<option/>', { - text: TokenStatus[status], - value: status, + text: status.label, + value: status.name, selected: true }).appendTo(select); - var nextStates = self.entry["nextStates"]; + var nextStates = self.entry.nextStates; _.each(nextStates, function(nextState) { $('<option/>', { - text: TokenStatus[nextState], - value: nextState + text: nextState.label, + value: nextState.name }).appendTo(select); }); } @@ -212,7 +199,7 @@ var TokenPage = EntryPage.extend({ self.$("label[name='modifyTimestamp']").hide(); self.$("input[name='modifyTimestamp']").hide(); self.$("label[name='status']").hide(); - self.$("input[name='statusLabel']").hide(); + self.$("input[name='status']").hide(); } else { self.changeStatusAction.show(); @@ -227,8 +214,22 @@ var TokenPage = EntryPage.extend({ self.$("label[name='modifyTimestamp']").show(); self.$("input[name='modifyTimestamp']").show(); self.$("label[name='status']").show(); - self.$("input[name='statusLabel']").show(); + self.$("input[name='status']").show(); + } + }, + loadField: function(input) { + var self = this; + + var name = input.attr("name"); + if (name != "status") { + TokenPage.__super__.loadField.call(self, input); + return; } + + var value = self.entry.status; + if (value) value = value.label; + if (value === undefined) value = ""; + input.val(value); } }); diff --git a/base/tps/shared/webapps/tps/ui/token.html b/base/tps/shared/webapps/tps/ui/token.html index aaf181414..bc4b01d22 100644 --- a/base/tps/shared/webapps/tps/ui/token.html +++ b/base/tps/shared/webapps/tps/ui/token.html @@ -60,7 +60,7 @@ <label name="modifyTimestamp">Modified</label> <input name="modifyTimestamp" readonly="readonly"><br> <label name="status">Status</label> - <input name="statusLabel" readonly="readonly"><br> + <input name="status" readonly="readonly"><br> </fieldset> </div> diff --git a/base/tps/shared/webapps/tps/ui/tokens.html b/base/tps/shared/webapps/tps/ui/tokens.html index ec89de958..b0782d373 100644 --- a/base/tps/shared/webapps/tps/ui/tokens.html +++ b/base/tps/shared/webapps/tps/ui/tokens.html @@ -56,7 +56,7 @@ <td name="id"><a href="#tokens/${id}">${id}</a></td> <td name="userID">${userID}</td> <td name="type">${type}</td> - <td name="status"><a href="#tokens/${id}/status">${statusLabel}</a></td> + <td name="status"><a href="#tokens/${id}/status">${status.label}</a></td> <td name="appletID">${appletID}</td> <td name="keyInfo">${keyInfo}</td> <td name="policy">${policy}</td> diff --git a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java index 247aa911c..cb660f3b1 100644 --- a/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java +++ b/base/tps/src/org/dogtagpki/server/tps/rest/TokenService.java @@ -21,11 +21,13 @@ package org.dogtagpki.server.tps.rest; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLEncoder; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.ResourceBundle; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; @@ -50,6 +52,7 @@ import com.netscape.certsrv.dbs.EDBException; import com.netscape.certsrv.ldap.LDAPExceptionConverter; import com.netscape.certsrv.tps.token.TokenCollection; import com.netscape.certsrv.tps.token.TokenData; +import com.netscape.certsrv.tps.token.TokenData.TokenStatusData; import com.netscape.certsrv.tps.token.TokenResource; import com.netscape.certsrv.tps.token.TokenStatus; import com.netscape.cms.servlet.base.PKIService; @@ -192,7 +195,9 @@ public class TokenService extends PKIService implements TokenResource { } - public TokenData createTokenData(TokenRecord tokenRecord) { + public TokenData createTokenData(TokenRecord tokenRecord) throws Exception { + + ResourceBundle labels = getResourceBundle("token-states"); TokenData tokenData = new TokenData(); tokenData.setID(tokenRecord.getId()); @@ -200,9 +205,23 @@ public class TokenService extends PKIService implements TokenResource { tokenData.setUserID(tokenRecord.getUserID()); tokenData.setType(tokenRecord.getType()); - TokenStatus currentState = getTokenStatus(tokenRecord); - tokenData.setStatus(currentState); - tokenData.setNextStates(transitions.get(currentState)); + TokenStatus status = getTokenStatus(tokenRecord); + TokenStatusData statusData = new TokenStatusData(); + statusData.name = status; + statusData.label = labels.getString(status.toString()); + tokenData.setStatus(statusData); + + Collection<TokenStatus> nextStates = transitions.get(status); + if (nextStates != null) { + Collection<TokenStatusData> nextStatesData = new ArrayList<TokenStatusData>(); + for (TokenStatus nextState : nextStates) { + TokenStatusData nextStateData = new TokenStatusData(); + nextStateData.name = nextState; + nextStateData.label = labels.getString(status + "." + nextState); + nextStatesData.add(nextStateData); + } + tokenData.setNextStates(nextStatesData); + } tokenData.setAppletID(tokenRecord.getAppletID()); tokenData.setKeyInfo(tokenRecord.getKeyInfo()); |