Changeset - 52617fb79010
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 13 years ago 2012-09-01 21:06:51
marcin@python-works.com
typos+docs.
2 files changed with 31 insertions and 16 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/pullrequests.py
Show inline comments
 
@@ -150,116 +150,118 @@ class PullrequestsController(BaseRepoCon
 
    def create(self, repo_name):
 
        try:
 
            _form = PullRequestForm()().to_python(request.POST)
 
        except formencode.Invalid, errors:
 
            log.error(traceback.format_exc())
 
            if errors.error_dict.get('revisions'):
 
                msg = 'Revisions: %s' % errors.error_dict['revisions']
 
            elif errors.error_dict.get('pullrequest_title'):
 
                msg = _('Pull request requires a title with min. 3 chars')
 
            else:
 
                msg = _('error during creation of pull request')
 

	
 
            h.flash(msg, 'error')
 
            return redirect(url('pullrequest_home', repo_name=repo_name))
 

	
 
        org_repo = _form['org_repo']
 
        org_ref = _form['org_ref']
 
        other_repo = _form['other_repo']
 
        other_ref = _form['other_ref']
 
        revisions = _form['revisions']
 
        reviewers = _form['review_members']
 

	
 
        title = _form['pullrequest_title']
 
        description = _form['pullrequest_desc']
 

	
 
        try:
 
            pull_request = PullRequestModel().create(
 
                self.rhodecode_user.user_id, org_repo, org_ref, other_repo,
 
                other_ref, revisions, reviewers, title, description
 
            )
 
            Session().commit()
 
            h.flash(_('Successfully opened new pull request'),
 
                    category='success')
 
        except Exception:
 
            h.flash(_('Error occurred during sending pull request'),
 
                    category='error')
 
            log.error(traceback.format_exc())
 
            return redirect(url('pullrequest_home', repo_name=repo_name))
 

	
 
        return redirect(url('pullrequest_show', repo_name=other_repo,
 
                            pull_request_id=pull_request.pull_request_id))
 

	
 
    @NotAnonymous()
 
    @jsonify
 
    def update(self, repo_name, pull_request_id):
 
        pull_request = PullRequest.get_or_404(pull_request_id)
 
        if pull_request.is_closed():
 
            raise HTTPForbidden()
 

	
 
        #only owner or admin can update it
 
        owner = pull_request.author.user_id == c.rhodecode_user.user_id
 
        if h.HasPermissionAny('hg.admin', 'repository.admin')() or owner:
 
        reviewers_ids = map(int, filter(lambda v: v not in [None, ''],
 
                   request.POST.get('reviewers_ids', '').split(',')))
 

	
 
        PullRequestModel().update_reviewers(pull_request_id, reviewers_ids)
 
        Session.commit()
 
        return True
 
        raise HTTPForbidden()
 

	
 
    @NotAnonymous()
 
    @jsonify
 
    def delete(self, repo_name, pull_request_id):
 
        pull_request = PullRequest.get_or_404(pull_request_id)
 
        #only owner can delete it !
 
        if pull_request.author.user_id == c.rhodecode_user.user_id:
 
            PullRequestModel().delete(pull_request)
 
            Session().commit()
 
            h.flash(_('Successfully deleted pull request'),
 
                    category='success')
 
            return redirect(url('admin_settings_my_account'))
 
        else:
 
            raise HTTPForbidden()
 

	
 
    def _load_compare_data(self, pull_request, enable_comments=True):
 
        """
 
        Load context data needed for generating compare diff
 

	
 
        :param pull_request:
 
        :type pull_request:
 
        """
 

	
 
        org_repo = pull_request.org_repo
 
        (org_ref_type,
 
         org_ref_name,
 
         org_ref_rev) = pull_request.org_ref.split(':')
 

	
 
        other_repo = pull_request.other_repo
 
        (other_ref_type,
 
         other_ref_name,
 
         other_ref_rev) = pull_request.other_ref.split(':')
 

	
 
        # despite opening revisions for bookmarks/branches/tags, we always
 
        # convert this to rev to prevent changes after book or branch change
 
        org_ref = ('rev', org_ref_rev)
 
        other_ref = ('rev', other_ref_rev)
 

	
 
        c.org_repo = org_repo
 
        c.other_repo = other_repo
 

	
 
        c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
 
                                       org_repo, org_ref, other_repo, other_ref
 
                                      )
 

	
 
        c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
 
                                                   c.cs_ranges])
 
        # defines that we need hidden inputs with changesets
 
        c.as_form = request.GET.get('as_form', False)
 

	
 
        c.org_ref = org_ref[1]
 
        c.other_ref = other_ref[1]
 
        # diff needs to have swapped org with other to generate proper diff
 
        _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
 
                             discovery_data)
 
        diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
 
        _parsed = diff_processor.prepare()
 

	
 
        c.files = []
 
        c.changes = {}
 

	
rhodecode/lib/dbmigrate/versions/006_version_1_4_0.py
Show inline comments
 
@@ -23,151 +23,164 @@ def upgrade(migrate_engine):
 
    """
 

	
 
    #==========================================================================
 
    # USEREMAILMAP
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_4_0 import UserEmailMap
 
    tbl = UserEmailMap.__table__
 
    tbl.create()
 
    #==========================================================================
 
    # PULL REQUEST
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_4_0 import PullRequest
 
    tbl = PullRequest.__table__
 
    tbl.create()
 

	
 
    #==========================================================================
 
    # PULL REQUEST REVIEWERS
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_4_0 import PullRequestReviewers
 
    tbl = PullRequestReviewers.__table__
 
    tbl.create()
 

	
 
    #==========================================================================
 
    # CHANGESET STATUS
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_4_0 import ChangesetStatus
 
    tbl = ChangesetStatus.__table__
 
    tbl.create()
 

	
 
    ## RESET COMPLETLY THE metadata for sqlalchemy to use the 1_3_0 Base 
 
    Base = declarative_base()
 
    Base.metadata.clear()
 
    Base.metadata = MetaData()
 
    Base.metadata.bind = migrate_engine
 
    meta.Base = Base
 

	
 
    #==========================================================================
 
    # USERS TABLE
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_3_0 import User
 
    tbl = User.__table__
 

	
 
    # change column name -> firstname
 
    col = User.__table__.columns.name
 
    col.alter(index=Index('u_username_idx', 'username'))
 
    col.alter(index=Index('u_email_idx', 'email'))
 
    col.alter(name="firstname", table=tbl)
 

	
 
    inherit_default_permissions = Column("users_group_inherit_default_permission",
 
                                         Boolean(), nullable=True, unique=None,
 
                                         default=True)
 
    inherit_default_permissions.create(table=tbl)
 
    inherit_default_permissions.alter(nullable=False, default=True, table=tbl)
 

	
 
    #==========================================================================
 
    # GROUPS TABLE
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_3_0 import RepoGroup
 
    tbl = RepoGroup.__table__
 
    # add inherit_default_permission column
 
    inherit_default_permissions = Column("inherit_default_permissions",
 
                                         Boolean(), nullable=True, unique=None,
 
                                         default=True)
 
    inherit_default_permissions.create(table=tbl)
 
    inherit_default_permissions.alter(nullable=False, default=True, table=tbl)
 

	
 
    #==========================================================================
 
    # USERS GROUP TABLE
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_3_0 import UsersGroup
 
    tbl = UsersGroup.__table__
 
    # add inherit_default_permission column
 
    gr_inherit_default_permissions = Column(
 
                                    "users_group_inherit_default_permissions",
 
                                    Boolean(), nullable=True, unique=None,
 
                                    default=True)
 
    gr_inherit_default_permissions.create(table=tbl)
 
    gr_inherit_default_permissions.alter(nullable=False, default=True, table=tbl)
 

	
 
    #==========================================================================
 
    # REPOSITORIES
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_3_0 import Repository
 
    tbl = Repository.__table__
 

	
 
    # add enable locking column
 
    enable_locking = Column("enable_locking", Boolean(), nullable=True,
 
                            unique=None, default=False)
 
    enable_locking.create(table=tbl)
 
    enable_locking.alter(nullable=False, default=False, table=tbl)
 

	
 
    # add locked column
 
    _locked = Column("locked", String(255), nullable=True, unique=False,
 
                     default=None)
 
    _locked.create(table=tbl)
 

	
 
    #add langing revision column
 
    landing_rev = Column("landing_revision", String(255), nullable=True,
 
                         unique=False, default='tip')
 
    landing_rev.create(table=tbl)
 
    landing_rev.alter(nullable=False, default='tip', table=tbl)
 

	
 
    #==========================================================================
 
    # GROUPS
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_3_0 import RepoGroup
 
    tbl = RepoGroup.__table__
 

	
 
    # add enable locking column
 
    enable_locking = Column("enable_locking", Boolean(), nullable=True,
 
                            unique=None, default=False)
 
    enable_locking.create(table=tbl)
 
    enable_locking.alter(nullable=False, default=False)
 

	
 
    #==========================================================================
 
    # CACHE INVALIDATION
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_3_0 import CacheInvalidation
 
    tbl = CacheInvalidation.__table__
 

	
 
    # change column name -> firstname
 
    # add INDEX for cache keys
 
    col = CacheInvalidation.__table__.columns.cache_key
 
    col.alter(index=Index('key_idx', 'cache_key'))
 

	
 
    #==========================================================================
 
    # NOTIFICATION
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_3_0 import Notification
 
    tbl = Notification.__table__
 

	
 
    # change column name -> firstname
 
    # add index for notification type
 
    col = Notification.__table__.columns.type
 
    col.alter(index=Index('notification_type_idx', 'type'),)
 

	
 
    #==========================================================================
 
    # CHANGESET_COMMENTS
 
    #==========================================================================
 
    from rhodecode.lib.dbmigrate.schema.db_1_3_0 import ChangesetComment
 

	
 
    tbl = ChangesetComment.__table__
 
    col = ChangesetComment.__table__.columns.revision
 

	
 
    col = ChangesetComment.__table__.columns.revision
 
    # add index for revisions
 
    col.alter(index=Index('cc_revision_idx', 'revision'),)
 

	
 
    # add hl_lines column
 
    hl_lines = Column('hl_lines', Unicode(512), nullable=True)
 
    hl_lines.create(table=tbl)
 

	
 
    # add created_on column
 
    created_on = Column('created_on', DateTime(timezone=False), nullable=True,
 
                        default=datetime.datetime.now)
 
    created_on.create(table=tbl)
 
    created_on.alter(nullable=False, default=datetime.datetime.now)
 

	
 
    modified_at = Column('modified_at', DateTime(timezone=False), nullable=False,
 
                         default=datetime.datetime.now)
 
    modified_at.alter(type=DateTime(timezone=False), table=tbl)
 

	
 
    # add FK to pull_request
 
    pull_request_id = Column("pull_request_id", Integer(),
 
                             ForeignKey('pull_requests.pull_request_id'),
 
                             nullable=True)
 
    pull_request_id.create(table=tbl)
 
    ## RESET COMPLETLY THE metadata for sqlalchemy back after using 1_3_0
 
    Base = declarative_base()
 
    Base.metadata.clear()
 
    Base.metadata = MetaData()
 
    Base.metadata.bind = migrate_engine
 
    meta.Base = Base
 

	
 

	
 
def downgrade(migrate_engine):
 
    meta = MetaData()
 
    meta.bind = migrate_engine
0 comments (0 inline, 0 general)