Skip to content

Commit

Permalink
prevent users with only a read role from actions (#558)
Browse files Browse the repository at this point in the history
Signed-off-by: David Huffman <[email protected]>
  • Loading branch information
dshuffma-ibm authored Nov 14, 2023
1 parent 8a48be8 commit 9947b1a
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 27 deletions.
6 changes: 3 additions & 3 deletions packages/apollo/src/components/CADetails/CADetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ export class CADetails extends Component {
fn: () => {
this.generateCertificate(null);
},
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags),
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags),
decoupleFromLoading: true
});
buttons.push({
text: 'register_user',
fn: this.openAddUser,
icon: 'plus',
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags),
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags),
decoupleFromLoading: true
});
}
Expand Down Expand Up @@ -508,7 +508,7 @@ export class CADetails extends Component {
{
text: 'reallocate_resources',
fn: this.showUsageModal,
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags),
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags),
},
]}
/>
Expand Down
7 changes: 5 additions & 2 deletions packages/apollo/src/components/Chaincodes/Chaincodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class Chaincodes extends Component {
text: 'install_chaincode',
fn: this.openInstallChaincodeModal,
label: 'install_chaincode',
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags)
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags)
},
]}
disableAddItem={!this.props.peers || this.props.peers.length === 0}
Expand Down Expand Up @@ -194,7 +194,10 @@ Chaincodes.propTypes = {

export default connect(
state => {
return Helper.mapStateToProps(state[SCOPE], dataProps);
let newProps = Helper.mapStateToProps(state[SCOPE], dataProps);
newProps['userInfo'] = state['userInfo'] ? state['userInfo'] : null;
newProps['feature_flags'] = state['settings'] ? state['settings']['feature_flags'] : null;
return newProps;
},
{
updateState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class ChannelChaincode extends Component {
{
text: 'chaincode_propose',
fn: this.openProposeChaincodeModal,
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags)
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags)
},
]}
select={this.openChaincodeModal}
Expand Down Expand Up @@ -313,6 +313,7 @@ export default connect(
let newProps = Helper.mapStateToProps(state[SCOPE], dataProps);
newProps['docPrefix'] = state['settings'] ? state['settings']['docPrefix'] : null;
newProps['feature_flags'] = state['settings'] ? state['settings']['feature_flags'] : null;
newProps['userInfo'] = state['userInfo'] ? state['userInfo'] : null;
return newProps;
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ class ChannelDetails extends Component {
id: 'add_node',
text: 'add_node',
fn: this.showJoinChannelModal,
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags)
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags)
},
]}
/>
Expand Down Expand Up @@ -1401,6 +1401,7 @@ export default connect(
newProps['settings'] = state['settings'];
newProps['configtxlator_url'] = state['settings']['configtxlator_url'];
newProps['feature_flags'] = state['settings'] ? state['settings']['feature_flags'] : null;
newProps['userInfo'] = state['userInfo'] ? state['userInfo'] : null;
return newProps;
},
{
Expand Down
5 changes: 3 additions & 2 deletions packages/apollo/src/components/Channels/Channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ class ChannelComponent extends Component {
id: 'join_channel',
text: 'join_channel',
fn: this.joinChannel,
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags)
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags)
});

const osnadminFeatsEnabled = this.props.feature_flags ? this.props.feature_flags.osnadmin_feats_enabled : false;
Expand Down Expand Up @@ -679,7 +679,7 @@ class ChannelComponent extends Component {
fn: () => {
this.createChannel(null);
},
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags)
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags)
});
}
return items;
Expand Down Expand Up @@ -975,6 +975,7 @@ export default connect(
state => {
let newProps = Helper.mapStateToProps(state[SCOPE], dataProps);
newProps['feature_flags'] = state['settings'] ? state['settings']['feature_flags'] : null;
newProps['userInfo'] = state['userInfo'] ? state['userInfo'] : null;
newProps['signature_requests'] = state['signatureCollection'] ? state['signatureCollection']['requests'] : [];
newProps['host_url'] = state['settings'] ? state['settings']['host_url'] : [];
return newProps;
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo/src/components/Identities/Identities.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class Identities extends Component {
{
text: 'add_identity',
fn: this.openAddIdentity,
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags),
disabled: ActionsHelper.inReadOnly(this.props.feature_flags),
},
]}
select={this.openIdentity}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ class ItemContainer extends Component {
onClick={button.fn}
kind={button.kind || (i !== this.props.addItems.length - 1 ? 'secondary' : 'primary')}
title={!button.tooltip ? (button.title ? translate(button.title) : translate(button.text)) : ''}
disabled={button.decoupleFromLoading ? false : (this.props.disableAddItem || this.props.loading || button.disabled)}
disabled={button.decoupleFromLoading ? (this.props.disableAddItem || button.disabled) :
(this.props.disableAddItem || this.props.loading || button.disabled)}
>
{!button.tooltip && <span className="ibp__button-text bx--type-zeta">{translate(button.text)}</span>}
{button.tooltip && (
Expand Down
7 changes: 5 additions & 2 deletions packages/apollo/src/components/OrdererAdmins/OrdererAdmins.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class OrdererAdmins extends Component {
fn: this.openAddMSPModal,
label: 'add_orderer_admin',
text: 'add_orderer_admin',
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags),
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags),
},
]}
tileMapping={{
Expand Down Expand Up @@ -252,7 +252,10 @@ OrdererAdmins.propTypes = {

export default connect(
state => {
return Helper.mapStateToProps(state[SCOPE], dataProps);
let newProps = Helper.mapStateToProps(state[SCOPE], dataProps);
newProps['userInfo'] = state['userInfo'] ? state['userInfo'] : null;
newProps['feature_flags'] = state['settings'] ? state['settings']['feature_flags'] : null;
return newProps;
},
{
updateState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class ChannelParticipationDetails extends Component {
fn: () => {
this.joinChannel(null);
},
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags)
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags)
}]

: []
Expand Down Expand Up @@ -243,7 +243,10 @@ ChannelParticipationDetails.propTypes = {

export default connect(
state => {
return Helper.mapStateToProps(state[SCOPE], dataProps);
let newProps = Helper.mapStateToProps(state[SCOPE], dataProps);
newProps['userInfo'] = state['userInfo'] ? state['userInfo'] : null;
newProps['feature_flags'] = state['settings'] ? state['settings']['feature_flags'] : null;
return newProps;
},
{
updateState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ class OrdererDetails extends Component {
{
text: 'reallocate_resources',
fn: this.showUsageModal,
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags),
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags),
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class OrdererMembers extends Component {
fn: this.openAddMSPModal,
label: 'add_organization',
text: 'add_organization',
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags),
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags),
},
]}
tileMapping={{
Expand Down Expand Up @@ -207,7 +207,10 @@ OrdererMembers.propTypes = {

export default connect(
state => {
return Helper.mapStateToProps(state[SCOPE], dataProps);
let newProps = Helper.mapStateToProps(state[SCOPE], dataProps);
newProps['userInfo'] = state['userInfo'] ? state['userInfo'] : null;
newProps['feature_flags'] = state['settings'] ? state['settings']['feature_flags'] : null;
return newProps;
},
{
updateState,
Expand Down
7 changes: 5 additions & 2 deletions packages/apollo/src/components/PeerChaincode/PeerChaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class PeerChaincode extends Component {
text: 'install_chaincode',
fn: this.openInstallChaincodeModal,
label: 'install_chaincode',
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags)
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags)
},
]}
disableAddItem={this.props.empty || this.props.parentLoading || this.props.state !== STATES.READY}
Expand Down Expand Up @@ -252,7 +252,10 @@ PeerChaincode.propTypes = {

export default connect(
state => {
return Helper.mapStateToProps(state[SCOPE], dataProps);
let newProps = Helper.mapStateToProps(state[SCOPE], dataProps);
newProps['userInfo'] = state['userInfo'] ? state['userInfo'] : null;
newProps['feature_flags'] = state['settings'] ? state['settings']['feature_flags'] : null;
return newProps;
},
{
updateState,
Expand Down
7 changes: 5 additions & 2 deletions packages/apollo/src/components/PeerChannels/PeerChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class PeerChannels extends Component {
{
text: 'join_channel',
fn: this.joinChannel,
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags)
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags)
},
]}
disableAddItem={this.props.empty || this.props.joinInProgress}
Expand Down Expand Up @@ -227,7 +227,10 @@ PeerChannels.propTypes = {

export default connect(
state => {
return Helper.mapStateToProps(state[SCOPE], dataProps);
let newProps = Helper.mapStateToProps(state[SCOPE], dataProps);
newProps['userInfo'] = state['userInfo'] ? state['userInfo'] : null;
newProps['feature_flags'] = state['settings'] ? state['settings']['feature_flags'] : null;
return newProps;
},
{
clearNotifications,
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo/src/components/PeerDetails/PeerDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class PeerDetails extends Component {
{
text: 'reallocate_resources',
fn: this.showUsageModal,
disabled: !ActionsHelper.canEditComponent(this.props.feature_flags)
disabled: !ActionsHelper.canEditComponent(this.props.userInfo, this.props.feature_flags)
},
]}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo/src/components/StickySection/StickySection.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const StickySection = ({
<p className="ibp-node-detail-title">{translate(title)}</p>
<div className="ibp-node-detail-icons">
{(details && (details.id || details.name) && !loading) ? (
ActionsHelper.canEditComponent(feature_flags) && <Button
ActionsHelper.canEditComponent(userInfo, feature_flags) && <Button
id={`${details.id || details.name}-sticky-settings-button`}
className="ibp-detail-page-icon-button"
kind="secondary"
Expand All @@ -193,7 +193,7 @@ const StickySection = ({
)}
{!hideRefreshCerts &&
((details && (details.id || details.name) && !loading) ? (
ActionsHelper.canEditComponent(feature_flags) && <Button
ActionsHelper.canEditComponent(userInfo, feature_flags) && <Button
id={`${details.id || details.name}-sticky-refresh-button`}
className="ibp-detail-page-icon-button"
kind="secondary"
Expand Down
12 changes: 10 additions & 2 deletions packages/apollo/src/utils/actionsHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@
import * as constants from './constants';

const ActionsHelper = {
canEditComponent(feature_flags) {

// return true if the console is in read only mode
inReadOnly(feature_flags) {
const in_read_only_mode = feature_flags ? feature_flags.read_only_enabled : false;
return !in_read_only_mode;
return in_read_only_mode;
},

// return true if the user has the right roles to edit a component (ca/peer/orderer)
canEditComponent(user, feature_flags) {
return ActionsHelper.canCreateComponent(user, feature_flags);
},

// return true if the user has the right role to create a component (ca/peer/orderer)
canCreateComponent(user, feature_flags) {
const in_read_only_mode = feature_flags ? feature_flags.read_only_enabled : false;
return ActionsHelper._actionCheck(user, constants.ACTION_COMPONENT_CREATE) && !in_read_only_mode;
Expand Down

0 comments on commit 9947b1a

Please sign in to comment.