diff --git a/app/static/app/js/Dashboard.jsx b/app/static/app/js/Dashboard.jsx index 3c1544444..e4a2283f6 100644 --- a/app/static/app/js/Dashboard.jsx +++ b/app/static/app/js/Dashboard.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import PropTypes from 'prop-types'; import './css/Dashboard.scss'; import ProjectList from './components/ProjectList'; import EditProjectDialog from './components/EditProjectDialog'; @@ -11,9 +12,16 @@ import $ from 'jquery'; import { _ } from './classes/gettext'; class Dashboard extends React.Component { - constructor(){ - super(); - + static defaultProps = { + permissions: [] + }; + static propTypes = { + permissions: PropTypes.array.isRequired, + }; + + constructor(props){ + super(props); + this.handleAddProject = this.handleAddProject.bind(this); this.addNewProject = this.addNewProject.bind(this); } @@ -58,14 +66,15 @@ class Dashboard extends React.Component { return (
+ {this.props.permissions.indexOf("add_project") !== -1 ?
- -
+
: ""} , $(this).get(0)); + let props = $(this).data(); + delete(props.dashboard); + window.ReactDOM.render(, $(this).get(0)); }); - // Warn users if there's any sort of work in progress before // they press the back button on the browser // Yes it's a hack. No we're not going to track state in React just diff --git a/app/static/app/js/tests/Dashboard.test.jsx b/app/static/app/js/tests/Dashboard.test.jsx index 358d6f569..1eea8715b 100644 --- a/app/static/app/js/tests/Dashboard.test.jsx +++ b/app/static/app/js/tests/Dashboard.test.jsx @@ -4,7 +4,7 @@ import Dashboard from '../Dashboard'; describe('', () => { it('renders without exploding', () => { - const wrapper = shallow(); + const wrapper = shallow(); expect(wrapper.exists()).toBe(true); }) }); \ No newline at end of file diff --git a/app/templates/app/dashboard.html b/app/templates/app/dashboard.html index 106998b35..fb162dd3e 100644 --- a/app/templates/app/dashboard.html +++ b/app/templates/app/dashboard.html @@ -43,7 +43,11 @@

{% trans 'Welcome!' %} ☺

{% endif %} -
+
{% endif %} {% endblock %} diff --git a/app/views/app.py b/app/views/app.py index 4256234a0..f909d575a 100644 --- a/app/views/app.py +++ b/app/views/app.py @@ -41,13 +41,20 @@ def dashboard(request): no_tasks = Task.objects.filter(project__owner=request.user).count() == 0 no_projects = Project.objects.filter(owner=request.user).count() == 0 + permissions = [] + if request.user.has_perm('app.add_project'): + permissions.append('add_project') + # Create first project automatically - if no_projects and request.user.has_perm('app.add_project'): + if no_projects and 'add_project' in permissions: Project.objects.create(owner=request.user, name=_("First Project")) return render(request, 'app/dashboard.html', {'title': _('Dashboard'), 'no_processingnodes': no_processingnodes, - 'no_tasks': no_tasks + 'no_tasks': no_tasks, + 'params': { + 'permissions': json.dumps(permissions) + }.items() })