Exemplo n.º 1
0
def user_update_preferences(user_id, preferences):
    for key in preferences:
        value = preferences[key]
        prefs = api_base.entity_get_all(models.UserPreference,
                                        user_id=user_id,
                                        key=key)

        if prefs:
            pref = prefs[0]
        else:
            pref = None

        # If the preference exists and it's null.
        if pref and value is None:
            api_base.entity_hard_delete(models.UserPreference, pref.id)
            continue

        # If the preference exists and has a new value.
        if pref and value and pref.cast_value != value:
            pref.cast_value = value
            api_base.entity_update(models.UserPreference, pref.id, dict(pref))
            continue

        # If the preference does not exist and a new value exists.
        if not pref and value:
            api_base.entity_create(models.UserPreference, {
                'user_id': user_id,
                'key': key,
                'cast_value': value
            })

    return user_get_preferences(user_id)
Exemplo n.º 2
0
def get_all(title=None, creator_id=None, user_id=None, project_id=None,
            task_id=None, story_id=None, sort_field=None, sort_dir=None,
            **kwargs):
    if user_id is not None:
        user = users_api.user_get(user_id)
        boards = []
        for board in get_all():
            if any(permission in board.permissions
                   for permission in user.permissions):
                boards.append(board)
        return boards

    boards = api_base.entity_get_all(models.Board,
                                     title=title,
                                     creator_id=creator_id,
                                     project_id=project_id,
                                     sort_field=sort_field,
                                     sort_dir=sort_dir,
                                     **kwargs)
    if task_id:
        matching = []
        for board in boards:
            if has_card(board, 'task', task_id):
                matching.append(board)
        boards = matching

    if story_id:
        matching = []
        for board in boards:
            if has_card(board, 'story', story_id):
                matching.append(board)
        boards = matching

    return boards
Exemplo n.º 3
0
def project_group_get_all(marker=None, limit=None, sort_field=None,
                          sort_dir=None, **kwargs):
    return api_base.entity_get_all(models.ProjectGroup,
                                   marker=marker,
                                   limit=limit,
                                   sort_field=sort_field,
                                   sort_dir=sort_dir,
                                   **kwargs)
Exemplo n.º 4
0
def events_get_all(marker=None, limit=None, sort_field=None, sort_dir=None,
                   **kwargs):
    return api_base.entity_get_all(models.TimeLineEvent,
                                   marker=marker,
                                   limit=limit,
                                   sort_field=sort_field,
                                   sort_dir=sort_dir,
                                   **kwargs)
Exemplo n.º 5
0
def team_get_all(marker=None, limit=None, sort_field=None,
                 sort_dir=None, **kwargs):
    return api_base.entity_get_all(models.Team,
                                   marker=marker,
                                   limit=limit,
                                   sort_field=sort_field,
                                   sort_dir=sort_dir,
                                   **kwargs)
Exemplo n.º 6
0
def milestone_get_all(marker=None, limit=None, sort_field=None, sort_dir=None,
                      **kwargs):
    return api_base.entity_get_all(models.Milestone,
                                   marker=marker,
                                   limit=limit,
                                   sort_field=sort_field,
                                   sort_dir=sort_dir,
                                   **kwargs)
Exemplo n.º 7
0
def user_get_all(marker=None, limit=None, filter_non_public=False,
                 sort_field=None, sort_dir=None, **kwargs):
    return api_base.entity_get_all(models.User,
                                   marker=marker,
                                   limit=limit,
                                   filter_non_public=filter_non_public,
                                   sort_field=sort_field,
                                   sort_dir=sort_dir,
                                   **kwargs)
    def testSimpleGroupMigration(self):

        # Clear out previous projects.
        for project in api_base.entity_get_all(Project):
            api_base.entity_hard_delete(Project, project.id)

        projects_loader.do_load_models('./etc/projects.yaml.sample')

        all_groups = api_base.entity_get_all(ProjectGroup)
        all_projects = api_base.entity_get_all(Project)
        self.assertEqual(3, len(all_groups))
        self.assertEqual(2, len(all_projects))

        for project in all_projects:
            branches = api_base.entity_get_count(Branch,
                                                 project_id=project.id,
                                                 name='master')
            self.assertEqual(1, branches)
Exemplo n.º 9
0
def user_get_preferences(user_id):
    preferences = api_base.entity_get_all(models.UserPreference,
                                          user_id=user_id)

    pref_dict = dict()
    for pref in preferences:
        pref_dict[pref.key] = pref.cast_value

    # Decorate with plugin defaults.
    for key in PREFERENCE_DEFAULTS:
        if key not in pref_dict:
            pref_dict[key] = PREFERENCE_DEFAULTS[key]

    return pref_dict
Exemplo n.º 10
0
    def handle_deletions(self, session, resource_name, resource_id):
        target_subs = []
        sub_ids = set()
        resource_name = resource_name[:-1]

        target_sub = db_api.entity_get_all(models.Subscription,
                                           target_type=resource_name,
                                           target_id=resource_id,
                                           session=session)
        target_subs.extend(target_sub)

        for sub in target_subs:
            sub_ids.add(sub.id)

        for sub_id in sub_ids:
            db_api.entity_hard_delete(models.Subscription,
                                      sub_id,
                                      session=session)
Exemplo n.º 11
0
def user_update_preferences(user_id, preferences):
    for key in preferences:
        value = preferences[key]
        prefs = api_base.entity_get_all(models.UserPreference,
                                        user_id=user_id,
                                        key=key)

        matching_prefs = []
        if prefs:
            for p in prefs:
                if p.key == key:
                    # FIXME: We create a list here because there appears to
                    # currently be a bug which means that each preference may
                    # appear more than once per-user. We should fix that once
                    # we discover the cause.
                    matching_prefs.append(p)
        else:
            pref = None

        for pref in matching_prefs:
            # If the preference exists and it's null.
            if pref and value is None:
                api_base.entity_hard_delete(models.UserPreference, pref.id)
                continue

            # If the preference exists and has a new value.
            if pref and value is not None and pref.cast_value != value:
                pref.cast_value = value
                api_base.entity_update(
                    models.UserPreference, pref.id, dict(pref))
                continue

        # If the preference does not exist and a new value exists.
        if not matching_prefs and value is not None:
            api_base.entity_create(models.UserPreference, {
                'user_id': user_id,
                'key': key,
                'cast_value': value
            })

    return user_get_preferences(user_id)
Exemplo n.º 12
0
def tag_get_all(marker=None, limit=None):
    return api_base.entity_get_all(models.StoryTag,
                                   marker=marker,
                                   limit=limit)
Exemplo n.º 13
0
def get_from_lane(worklist):
    lanes = api_base.entity_get_all(models.BoardWorklist,
                                    list_id=worklist.id)
    if lanes:
        lane = lanes[0]
        return lane.board
Exemplo n.º 14
0
def is_lane(worklist):
    lanes = api_base.entity_get_all(models.BoardWorklist,
                                    list_id=worklist.id)
    if lanes:
        return True
    return False
Exemplo n.º 15
0
def subscription_get_all_by_target(target_type, target_id):
    return api_base.entity_get_all(models.Subscription,
                                   target_type=target_type,
                                   target_id=target_id)
Exemplo n.º 16
0
def subscription_get_all(**kwargs):
    return api_base.entity_get_all(models.Subscription,
                                   **kwargs)