Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
fix(glossary):hide delete button for non-glossary admin user
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Nov 6, 2015
1 parent c3f2746 commit 37d95f8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions frontend/src/main/web/lib/components/SystemGlossary.jsx
Expand Up @@ -83,6 +83,7 @@ var SystemGlossary = React.createClass({
totalCount={this.state.totalCount}
canAddNewEntry={this.state.canAddNewEntry}
canUpdateEntry={this.state.canUpdateEntry}
canDeleteEntry={this.state.canDeleteEntry}
user={Configs.user}
srcLocale={srcLocale}
selectedTransLocale={selectedTransLocale}/>);
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/main/web/lib/components/glossary/DataTable.jsx
Expand Up @@ -54,6 +54,7 @@ var DataTable = React.createClass({
),
canAddNewEntry: React.PropTypes.bool.isRequired,
canUpdateEntry: React.PropTypes.bool.isRequired,
canDeleteEntry: React.PropTypes.bool.isRequired,
user: React.PropTypes.shape({
username: React.PropTypes.string,
email: React.PropTypes.string,
Expand Down Expand Up @@ -284,7 +285,9 @@ var DataTable = React.createClass({
columnData, width) {
if(id === null) {
return <LoadingCell/>;
} else if(!this.props.canUpdateEntry && !this.props.canAddNewEntry) {
} else if(!this.props.canUpdateEntry &&
!this.props.canDeleteEntry &&
!this.props.canAddNewEntry) {
return;
}
var entry = this._getGlossaryEntry(id);
Expand All @@ -303,7 +306,7 @@ var DataTable = React.createClass({
srcLocaleId={this.props.srcLocale.locale.localeId}
info={info}
canUpdateEntry={this.props.canUpdateEntry}
canDeleteEntry={this.props.canAddNewEntry}/>
canDeleteEntry={this.props.canDeleteEntry}/>
);
}
},
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/main/web/lib/stores/GlossaryStore.js
Expand Up @@ -24,6 +24,7 @@ EventEmitter.prototype.setMaxListeners(MAX_LISTENERS);
var _state = {
canAddNewEntry: false,
canUpdateEntry: false,
canDeleteEntry: false,
localeOptions: [],
srcLocale: null,
selectedTransLocale: null,
Expand Down Expand Up @@ -99,6 +100,10 @@ function canAddNewEntry () {
function canUpdateEntry() {
return Configs.data.permission.updateGlossary;
}
function canDeleteEntry() {
return Configs.data.permission.deleteGlossary;
}


function processGlossaryList(res) {
if(res.error) {
Expand Down Expand Up @@ -249,6 +254,7 @@ function refreshGlossaryEntries() {
//load permission here
_state.canAddNewEntry = canAddNewEntry();
_state.canUpdateEntry = canUpdateEntry();
_state.canDeleteEntry = canDeleteEntry();

GlossaryAPIStore.loadLocalesStats()
.then(processLocalesStatistic)
Expand Down
Expand Up @@ -47,14 +47,17 @@ public Permission getUserPermission() {
Permission permission = new Permission();
boolean canUpdate = false;
boolean canInsert = false;
boolean canDelete = false;

if(authenticatedAccount != null) {
canUpdate = identity.hasPermission("", "glossary-update");
canInsert = identity.hasPermission("", "glossary-insert");
canDelete = identity.hasPermission("", "glossary-delete");
}

permission.put("updateGlossary", canUpdate);
permission.put("insertGlossary", canInsert);
permission.put("deleteGlossary", canDelete);

return permission;
}
Expand Down

0 comments on commit 37d95f8

Please sign in to comment.