-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into CVE-2024-47764
- Loading branch information
Showing
62 changed files
with
548 additions
and
477 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* @folio-org/stripes-force | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
|
||
import BadRequestScreen from './BadRequestScreen'; | ||
|
||
jest.mock('../../Pluggable', () => (props) => props.children); | ||
|
||
describe('BadRequestScreen', () => { | ||
it('renders expected message', () => { | ||
render(<BadRequestScreen />); | ||
|
||
screen.getByText('stripes-core.front.error.header'); | ||
screen.getByText(/stripes-core.front.error.general.message/); | ||
}); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import PropTypes from 'prop-types'; | ||
import { useStripes } from '../../StripesContext'; | ||
|
||
const IfAnyPermission = ({ children, perm }) => { | ||
const stripes = useStripes(); | ||
const hasPermission = stripes.hasAnyPerm(perm); | ||
|
||
if (typeof children === 'function') { | ||
return children({ hasPermission }); | ||
} | ||
|
||
return hasPermission ? children : null; | ||
}; | ||
|
||
IfAnyPermission.propTypes = { | ||
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), | ||
perm: PropTypes.string.isRequired | ||
}; | ||
|
||
export default IfAnyPermission; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
|
||
import { useStripes } from '../../StripesContext'; | ||
import Stripes from '../../Stripes'; | ||
import IfAnyPermission from './IfAnyPermission'; | ||
|
||
jest.mock('../../StripesContext'); | ||
const stripes = new Stripes({ | ||
user: { | ||
perms: { | ||
john: true, | ||
george: true, | ||
ringo: true, | ||
} | ||
}, | ||
logger: { | ||
log: jest.fn(), | ||
} | ||
}); | ||
|
||
describe('IfAnyPermission', () => { | ||
it('returns true if any permission matches', () => { | ||
useStripes.mockReturnValue(stripes); | ||
render(<IfAnyPermission perm="john,paul">monkey</IfAnyPermission>); | ||
expect(screen.queryByText(/monkey/)).toBeTruthy(); | ||
}); | ||
|
||
it('returns false if no permissions match', () => { | ||
useStripes.mockReturnValue(stripes); | ||
render(<IfAnyPermission perm="paul,is,dead">monkey</IfAnyPermission>); | ||
expect(screen.queryByText(/monkey/)).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './IfAnyPermission'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# IfAnyPermission | ||
|
||
A wrapper component that facilitates conditional rendering based on | ||
whether the currently authentiated user has _any_ of the permissions | ||
named in the given comma-delimited string. | ||
|
||
Supports children in the form of React nodes or as a render-prop function. | ||
|
||
## Usage (children as nodes) | ||
|
||
``` | ||
<IfAnyPermission perm="users.edit,users.manage"> | ||
<button onClick={this.onClickEditUser}>Edit</button> | ||
</IfAnyPermission> | ||
``` | ||
|
||
## Usage (children as function) | ||
|
||
``` | ||
<IfAnyPermission perm="users.edit,users.manage"> | ||
{({ hasPermission }) => hasPermission ? | ||
<button onClick={this.onClickEditUser}>Edit</button> | ||
: | ||
<span>You do not have permission to edit this user!</span> | ||
} | ||
</IfAnyPermission> | ||
``` | ||
|
||
## Properties | ||
|
||
A single property is supported: | ||
|
||
* `perm`: a comma-delimited string of permissions to check. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
|
||
import { useStripes } from '../../StripesContext'; | ||
import Stripes from '../../Stripes'; | ||
import IfInterface from './IfInterface'; | ||
|
||
jest.mock('../../StripesContext'); | ||
const stripes = new Stripes({ | ||
discovery: { | ||
interfaces: { | ||
foo: '1.0' | ||
} | ||
}, | ||
logger: { | ||
log: jest.fn(), | ||
} | ||
}); | ||
|
||
// IfInterface is just a component version of Stripes::hasInterface | ||
// See more extensive tests there. | ||
describe('IfInterface', () => { | ||
it('returns true if interface is present', () => { | ||
useStripes.mockReturnValue(stripes); | ||
render(<IfInterface name="foo">monkey</IfInterface>); | ||
expect(screen.queryByText(/monkey/)).toBeTruthy(); | ||
}); | ||
|
||
it('returns false if interface is absent', () => { | ||
useStripes.mockReturnValue(stripes); | ||
render(<IfInterface name="paul,is,dead">monkey</IfInterface>); | ||
expect(screen.queryByText(/monkey/)).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; | ||
|
||
import { useStripes } from '../../StripesContext'; | ||
import Stripes from '../../Stripes'; | ||
import IfPermission from './IfPermission'; | ||
|
||
jest.mock('../../StripesContext'); | ||
const stripes = new Stripes({ | ||
user: { | ||
perms: { | ||
john: true, | ||
george: true, | ||
ringo: true, | ||
} | ||
}, | ||
logger: { | ||
log: jest.fn(), | ||
} | ||
}); | ||
|
||
describe('IfPermission', () => { | ||
it('returns true if all permissions match', () => { | ||
useStripes.mockReturnValue(stripes); | ||
render(<IfPermission perm="john,george">monkey</IfPermission>); | ||
expect(screen.queryByText(/monkey/)).toBeTruthy(); | ||
}); | ||
|
||
it('returns false unless all permissions match', () => { | ||
useStripes.mockReturnValue(stripes); | ||
render(<IfPermission perm="john,paul">monkey</IfPermission>); | ||
expect(screen.queryByText(/monkey/)).toBeFalsy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.