Skip to content

Commit 10c1dcb

Browse files
committed
feat: restrict actions data in dashboard on studentMode
if studentMode is enabled, only the current user actions are displayed, otherwise all actions are displayed closes #259
1 parent d537ac4 commit 10c1dcb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/components/dashboard/Dashboard.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import ActionEditor from './ActionEditor';
1919
import Loader from '../common/Loader';
2020
import Main from '../common/Main';
2121
import { getDatabase } from '../../actions';
22-
import { FILTER_ALL_SPACE_ID } from '../../config/constants';
22+
import { FILTER_ALL_SPACE_ID, USER_MODES } from '../../config/constants';
2323
import { DASHBOARD_MAIN_ID } from '../../config/selectors';
2424

2525
const styles = theme => ({
@@ -72,6 +72,8 @@ export class Dashboard extends Component {
7272
actions: PropTypes.arrayOf(PropTypes.object),
7373
}),
7474
dispatchGetDatabase: PropTypes.func.isRequired,
75+
userMode: PropTypes.oneOf(Object.values(USER_MODES)).isRequired,
76+
userId: PropTypes.string.isRequired,
7577
};
7678

7779
static defaultProps = {
@@ -115,10 +117,17 @@ export class Dashboard extends Component {
115117
};
116118

117119
renderActionWidgets = () => {
118-
const { database, t, classes } = this.props;
120+
const { database, t, classes, userMode, userId } = this.props;
119121
const { spaceId } = this.state;
120122

121123
let filteredActions = database.actions;
124+
125+
// filter action per user if userMode is student
126+
if (userMode === USER_MODES.STUDENT) {
127+
filteredActions = filteredActions.filter(({ user }) => user === userId);
128+
}
129+
130+
// filter action per space
122131
if (spaceId !== FILTER_ALL_SPACE_ID) {
123132
filteredActions = filteredActions.filter(
124133
({ spaceId: id }) => id === spaceId
@@ -194,8 +203,10 @@ export class Dashboard extends Component {
194203
}
195204
}
196205

197-
const mapStateToProps = ({ Developer }) => ({
206+
const mapStateToProps = ({ Developer, authentication }) => ({
198207
database: Developer.get('database'),
208+
userId: authentication.getIn(['user', 'id']),
209+
userMode: authentication.getIn(['user', 'settings', 'userMode']),
199210
});
200211

201212
const mapDispatchToProps = {

0 commit comments

Comments
 (0)