コード例 #1
0
def test_role_has_perm():
    role = Role()
    role.permissions = ["test"]
    assert service.role_has_perm(role, "test")
    assert service.role_has_perm(role, "false") == False
コード例 #2
0
    def migrate(apps, schema_editor):
        roles = [{
            'name':
            'Owner',
            'slug':
            'owner',
            'order':
            50,
            'computable':
            False,
            'permissions': [
                'add_issue', 'modify_issue', 'delete_issue', 'view_issues',
                'add_milestone', 'modify_milestone', 'delete_milestone',
                'view_milestones', 'view_project', 'add_task', 'modify_task',
                'delete_task', 'view_tasks', 'add_us', 'modify_us',
                'delete_us', 'view_us', 'add_wiki_page', 'modify_wiki_page',
                'delete_wiki_page', 'view_wiki_pages', 'add_wiki_link',
                'delete_wiki_link', 'view_wiki_links', 'view_epics',
                'add_epic', 'modify_epic', 'delete_epic', 'comment_epic',
                'comment_us', 'comment_task', 'comment_issue',
                'comment_wiki_page'
            ]
        }, {
            'name':
            'Stakeholder',
            'slug':
            'stakeholder',
            'order':
            60,
            'computable':
            False,
            'permissions': [
                'add_issue', 'modify_issue', 'delete_issue', 'view_issues',
                'view_milestones', 'view_project', 'view_tasks', 'view_us',
                'modify_wiki_page', 'view_wiki_pages', 'add_wiki_link',
                'delete_wiki_link', 'view_wiki_links', 'view_epics',
                'comment_epic', 'comment_us', 'comment_task', 'comment_issue',
                'comment_wiki_page'
            ]
        }, {
            "name":
            "Member",
            "slug":
            "member",
            "order":
            70,
            "computable":
            False,
            "permissions": [
                "add_issue", "modify_issue", "view_issues", "view_project",
                "add_task", "modify_task", "view_tasks", "add_us", "modify_us",
                "view_us", "add_wiki_page", "modify_wiki_page",
                "view_wiki_pages", "add_wiki_link", "view_wiki_links",
                "comment_us", "comment_task", "comment_issue"
            ]
        }, {
            "name":
            "Viewer",
            "slug":
            "viewer",
            "order":
            80,
            "computable":
            False,
            "permissions": [
                "view_issues", "view_project", "view_tasks", "view_us",
                "view_wiki_pages", "view_wiki_links"
            ]
        }, {
            "name":
            "Follower",
            "slug":
            "follower",
            "order":
            90,
            "computable":
            False,
            "permissions": [
                "view_issues", "view_project", "view_tasks", "view_us",
                "view_wiki_pages", "view_wiki_links", "comment_us",
                "comment_task", "comment_issue", "comment_wiki_page"
            ]
        }]

        us_statuses = [{
            'name': 'New',
            'slug': 'new',
            'color': '#878a84',
            'order': 1,
            'is_closed': False,
            'wip_limit': None,
            'is_archived': False
        }, {
            'name': 'To Start',
            'slug': 'to-start',
            'color': '#1f4a87',
            'order': 2,
            'is_closed': False,
            'wip_limit': None,
            'is_archived': False
        }, {
            'name': 'In progress',
            'slug': 'in-progress',
            'color': '#729fcf',
            'order': 3,
            'is_closed': False,
            'wip_limit': None,
            'is_archived': False
        }, {
            'name': 'Blocked',
            'slug': 'blocked',
            'color': '#ef4049',
            'order': 4,
            'is_closed': False,
            'wip_limit': None,
            'is_archived': False
        }, {
            'name': 'Verification',
            'slug': 'verification',
            'color': '#4f9a04',
            'order': 5,
            'is_closed': False,
            'wip_limit': None,
            'is_archived': False
        }, {
            'name': 'Done',
            'slug': 'done',
            'color': '#8ae235',
            'order': 6,
            'is_closed': True,
            'wip_limit': None,
            'is_archived': False
        }, {
            'name': 'Archived',
            'slug': 'archived',
            'color': '#444644',
            'order': 7,
            'is_closed': True,
            'wip_limit': None,
            'is_archived': True
        }]

        ProjectTemplate.objects.update(us_statuses=us_statuses, roles=roles)

        Role.objects.filter(
            slug__in=['ux', 'design', 'front', 'back']).delete()
        Role.objects.filter(slug='product-owner').update(slug='owner',
                                                         name='Owner')

        UserStoryStatus.objects.filter(name='New').update(color='#878a84')
        UserStoryStatus.objects.filter(name='Ready').update(name='To Start',
                                                            slug='to-start',
                                                            color='#1f4a87')
        UserStoryStatus.objects.filter(name='In Progress').update(
            color='#729fcf')
        UserStoryStatus.objects.filter(name='Ready for test').update(
            color='#4f9a04', slug='blocked', name='Blocked')
        UserStoryStatus.objects.filter(name='Done').update(color='#8ae235',
                                                           order=6)
        UserStoryStatus.objects.filter(name='Archived').update(color='#444644',
                                                               order=7)

        for p in Project.objects.values('pk').all():
            pk = p['pk']
            if UserStoryStatus.objects.filter(slug='blocked',
                                              project_id=pk).count() == 0:
                UserStoryStatus(name='Verification',
                                slug='verification',
                                color='#4f9a04',
                                order=5,
                                is_closed=False,
                                wip_limit=None,
                                is_archived=None,
                                project_id=pk).save()

            if Role.objects.filter(slug='member', project_id=pk).count() == 0:
                Role(name="Member",
                     slug="member",
                     order=70,
                     computable=False,
                     permissions=[
                         "add_issue", "modify_issue", "view_issues",
                         "view_project", "add_task", "modify_task",
                         "view_tasks", "add_us", "modify_us", "view_us",
                         "add_wiki_page", "modify_wiki_page",
                         "view_wiki_pages", "add_wiki_link", "view_wiki_links",
                         "comment_us", "comment_task", "comment_issue"
                     ],
                     project_id=pk).save()

            if Role.objects.filter(slug='viewer', project_id=pk).count() == 0:
                Role(name="Viewer",
                     slug="viewer",
                     order=80,
                     computable=False,
                     permissions=[
                         "view_issues", "view_project", "view_tasks",
                         "view_us", "view_wiki_pages", "view_wiki_links"
                     ],
                     project_id=pk).save()

            if Role.objects.filter(slug='follower',
                                   project_id=pk).count() == 0:
                Role(name="Follower",
                     slug="follower",
                     order=90,
                     computable=False,
                     permissions=[
                         "view_issues", "view_project", "view_tasks",
                         "view_us", "view_wiki_pages", "view_wiki_links",
                         "comment_us", "comment_task", "comment_issue",
                         "comment_wiki_page"
                     ],
                     project_id=pk).save()
コード例 #3
0
    def migrate(apps, schema_editor):
        us_statuses = [{
            "name": "New",
            "slug": "new",
            "color": "#878a84",
            "order": 1,
            "is_closed": False,
            "wip_limit": None,
            "is_archived": False
        }, {
            "name": "To Start",
            "slug": "to-start",
            "color": "#1f4a87",
            "order": 2,
            "is_closed": False,
            "wip_limit": None,
            "is_archived": False
        }, {
            "name": "In progress",
            "slug": "in-progress",
            "color": "#729fcf",
            "order": 3,
            "is_closed": False,
            "wip_limit": None,
            "is_archived": False
        }, {
            "name": "Blocked",
            "slug": "blocked",
            "color": "#ef4049",
            "order": 4,
            "is_closed": False,
            "wip_limit": None,
            "is_archived": False
        }, {
            "name": "Verification",
            "slug": "verification",
            "color": "#4f9a04",
            "order": 5,
            "is_closed": False,
            "wip_limit": None,
            "is_archived": False
        }, {
            "name": "Done",
            "slug": "done",
            "color": "#8ae235",
            "order": 6,
            "is_closed": True,
            "wip_limit": None,
            "is_archived": False
        }, {
            "name": "Archived",
            "slug": "archived",
            "color": "#444644",
            "order": 7,
            "is_closed": True,
            "wip_limit": None,
            "is_archived": True
        }]

        roles = [{
            "name":
            "OWNER",
            "slug":
            "owner",
            "order":
            10,
            "computable":
            True,
            "permissions": [
                "add_issue", "modify_issue", "delete_issue", "view_issues",
                "add_milestone", "modify_milestone", "delete_milestone",
                "view_milestones", "view_project", "add_task", "modify_task",
                "delete_task", "view_tasks", "add_us", "modify_us",
                "delete_us", "view_us", "add_wiki_page", "modify_wiki_page",
                "delete_wiki_page", "view_wiki_pages", "add_wiki_link",
                "delete_wiki_link", "view_wiki_links", "view_epics",
                "add_epic", "modify_epic", "delete_epic", "comment_epic",
                "comment_us", "comment_task", "comment_issue",
                "comment_wiki_page"
            ]
        }, {
            "name":
            "CIRCLE MEMBER",
            "slug":
            "circle_member",
            "order":
            20,
            "computable":
            False,
            "permissions": [
                "add_issue", "modify_issue", "delete_issue", "view_issues",
                "view_project", "add_task", "modify_task", "delete_task",
                "view_tasks", "add_us", "modify_us", "delete_us", "view_us",
                "add_wiki_page", "modify_wiki_page", "delete_wiki_page",
                "view_wiki_pages", "add_wiki_link", "delete_wiki_link",
                "view_wiki_links", "comment_us", "comment_task",
                "comment_issue"
            ]
        }, {
            "name":
            "Stakeholder",
            "slug":
            "stakeholder",
            "order":
            30,
            "computable":
            False,
            "permissions": [
                "add_issue", "modify_issue", "delete_issue", "view_issues",
                "view_project", "add_task", "modify_task", "delete_task",
                "view_tasks", "add_us", "modify_us", "delete_us", "view_us",
                "add_wiki_page", "modify_wiki_page", "delete_wiki_page",
                "view_wiki_pages", "add_wiki_link", "delete_wiki_link",
                "view_wiki_links", "comment_us", "comment_task",
                "comment_issue"
            ]
        }, {
            "name":
            "VIEWER",
            "slug":
            "viewer",
            "order":
            40,
            "computable":
            False,
            "permissions": [
                "view_issues", "view_project", "view_us", "view_tasks",
                "view_wiki_links", "view_wiki_pages"
            ]
        }]

        if ProjectTemplate.objects.count() > 0:
            ProjectTemplate.objects.update(us_statuses=us_statuses,
                                           roles=roles)
            UserStoryStatus.objects.filter(name='New').update(color='#878a84')
            UserStoryStatus.objects.filter(name='Ready').update(
                name='To Start', slug='to-start', color='#1f4a87')
            UserStoryStatus.objects.filter(name='In Progress').update(
                color='#729fcf')
            UserStoryStatus.objects.filter(name='Ready for test').update(
                color='#4f9a04', slug='verification', name='Verification')
            UserStoryStatus.objects.filter(name='Done').update(color='#8ae235')
            UserStoryStatus.objects.filter(name='Archived').update(
                color='#444644')
            UserStoryStatus.objects.filter(name='New').update(color='#878a84')

            # Update old Projects
            for x in UserStoryStatus.objects.order_by('project_id').values(
                    'project_id').distinct('project_id'):
                pid = x['project_id']
                if UserStoryStatus.objects.filter(slug='blocked',
                                                  project_id=pid).count() == 0:
                    UserStoryStatus(name='BLOCKED',
                                    is_closed=False,
                                    color='#ef4049',
                                    project_id=pid,
                                    slug='blocked',
                                    is_archived=False,
                                    order=4).save()

        if Role.objects.count() > 0:
            Role.objects.filter(
                slug__in=['ux', 'design', 'front', 'back']).delete()

            # Update old roles
            for x in Role.objects.order_by('project_id').all().distinct(
                    'project_id'):
                pid = x.project_id
                if x.slug == 'product-owner':
                    try:
                        x.owner = 'owner'
                        x.name = 'Owner'
                        x.save()
                    except:
                        pass

                if Role.objects.filter(project_id=pid,
                                       slug='circle_member').count() == 0:
                    Role(name='CIRCLE MEMBER',
                         computable=False,
                         permissions=[
                             "add_issue", "modify_issue", "delete_issue",
                             "view_issues", "view_project", "add_task",
                             "modify_task", "delete_task", "view_tasks",
                             "add_us", "modify_us", "delete_us", "view_us",
                             "add_wiki_page", "modify_wiki_page",
                             "delete_wiki_page", "view_wiki_pages",
                             "add_wiki_link", "delete_wiki_link",
                             "view_wiki_links", "comment_us", "comment_task",
                             "comment_issue"
                         ],
                         project_id=pid,
                         slug='circle_member',
                         order=20).save()

                if Role.objects.filter(project_id=pid,
                                       slug='viewer').count() == 0:
                    Role(name='VIEWER',
                         computable=False,
                         permissions=[
                             "view_issues", "view_project", "view_us",
                             "view_tasks", "view_wiki_links", "view_wiki_pages"
                         ],
                         project_id=pid,
                         slug='viewer',
                         order=40).save()