Esempio n. 1
0
 def update_user_permission(self, repository, user, permission):
     permission = Permission.get_by_key(permission)
     current = self.get_user_permission(repository, user)
     if current:
         if not current.permission is permission:
             current.permission = permission
     else:
         p = RepoToPerm()
         p.user = user
         p.repository = repository
         p.permission = permission
         Session.add(p)
     Session.commit()
Esempio n. 2
0
    def update(self, repo_name, form_data):
        try:
            cur_repo = self.get_by_repo_name(repo_name, cache=False)

            # update permissions
            for member, perm, member_type in form_data["perms_updates"]:
                if member_type == "user":
                    r2p = (
                        self.sa.query(RepoToPerm)
                        .filter(RepoToPerm.user == User.by_username(member))
                        .filter(RepoToPerm.repository == cur_repo)
                        .one()
                    )

                    r2p.permission = self.sa.query(Permission).filter(Permission.permission_name == perm).scalar()
                    self.sa.add(r2p)
                else:
                    g2p = (
                        self.sa.query(UsersGroupRepoToPerm)
                        .filter(UsersGroupRepoToPerm.users_group == UsersGroup.get_by_group_name(member))
                        .filter(UsersGroupRepoToPerm.repository == cur_repo)
                        .one()
                    )

                    g2p.permission = self.sa.query(Permission).filter(Permission.permission_name == perm).scalar()
                    self.sa.add(g2p)

            # set new permissions
            for member, perm, member_type in form_data["perms_new"]:
                if member_type == "user":
                    r2p = RepoToPerm()
                    r2p.repository = cur_repo
                    r2p.user = User.by_username(member)

                    r2p.permission = self.sa.query(Permission).filter(Permission.permission_name == perm).scalar()
                    self.sa.add(r2p)
                else:
                    g2p = UsersGroupRepoToPerm()
                    g2p.repository = cur_repo
                    g2p.users_group = UsersGroup.get_by_group_name(member)
                    g2p.permission = self.sa.query(Permission).filter(Permission.permission_name == perm).scalar()
                    self.sa.add(g2p)

            # update current repo
            for k, v in form_data.items():
                if k == "user":
                    cur_repo.user = User.by_username(v)
                elif k == "repo_name":
                    cur_repo.repo_name = form_data["repo_name_full"]
                elif k == "repo_group":
                    cur_repo.group_id = v

                else:
                    setattr(cur_repo, k, v)

            self.sa.add(cur_repo)

            if repo_name != form_data["repo_name_full"]:
                # rename repository
                self.__rename_repo(old=repo_name, new=form_data["repo_name_full"])

            self.sa.commit()
        except:
            log.error(traceback.format_exc())
            self.sa.rollback()
            raise
Esempio n. 3
0
    def update(self, repo_name, form_data):
        try:
            cur_repo = self.get_by_repo_name(repo_name, cache=False)

            # update permissions
            for member, perm, member_type in form_data['perms_updates']:
                if member_type == 'user':
                    r2p = self.sa.query(RepoToPerm)\
                            .filter(RepoToPerm.user == User.get_by_username(member))\
                            .filter(RepoToPerm.repository == cur_repo)\
                            .one()

                    r2p.permission = self.sa.query(Permission)\
                                        .filter(Permission.permission_name ==
                                                perm).scalar()
                    self.sa.add(r2p)
                else:
                    g2p = self.sa.query(UsersGroupRepoToPerm)\
                            .filter(UsersGroupRepoToPerm.users_group ==
                                    UsersGroup.get_by_group_name(member))\
                            .filter(UsersGroupRepoToPerm.repository ==
                                    cur_repo).one()

                    g2p.permission = self.sa.query(Permission)\
                                        .filter(Permission.permission_name ==
                                                perm).scalar()
                    self.sa.add(g2p)

            # set new permissions
            for member, perm, member_type in form_data['perms_new']:
                if member_type == 'user':
                    r2p = RepoToPerm()
                    r2p.repository = cur_repo
                    r2p.user = User.get_by_username(member)

                    r2p.permission = self.sa.query(Permission)\
                                        .filter(Permission.
                                                permission_name == perm)\
                                                .scalar()
                    self.sa.add(r2p)
                else:
                    g2p = UsersGroupRepoToPerm()
                    g2p.repository = cur_repo
                    g2p.users_group = UsersGroup.get_by_group_name(member)
                    g2p.permission = self.sa.query(Permission)\
                                        .filter(Permission.
                                                permission_name == perm)\
                                                .scalar()
                    self.sa.add(g2p)

            # update current repo
            for k, v in form_data.items():
                if k == 'user':
                    cur_repo.user = User.get_by_username(v)
                elif k == 'repo_name':
                    pass
                elif k == 'repo_group':
                    cur_repo.group_id = v

                else:
                    setattr(cur_repo, k, v)

            new_name = cur_repo.get_new_name(form_data['repo_name'])
            cur_repo.repo_name = new_name

            self.sa.add(cur_repo)

            if repo_name != new_name:
                # rename repository
                self.__rename_repo(old=repo_name, new=new_name)

            self.sa.commit()
            return cur_repo
        except:
            log.error(traceback.format_exc())
            self.sa.rollback()
            raise