Exemplo n.º 1
0
def has_permission_handler(username, path, perm):
    if not username or not path:
        return False

    if path.endswith(".git"):
        path = path[:-4]

    # gist
    if path.startswith("gist/"):
        gist_id = path.rpartition("/")[-1]
        if username == Gist.get(gist_id).owner_id:
            return True
        return False

    # project
    project = Project.get_by_name(path)
    if not project:
        return False
    if perm == "read":
        return True
    if not project.can_push:
        return False
    if project.has_push_perm(username):
        return True
    return False
Exemplo n.º 2
0
    def patch(self, request):
        if not self.is_owner:
            raise api_errors.NotTheAuthorError('gist', 'update')

        desc = request.data.get('description')
        if not desc:
            desc = self.gist.description

        files = request.data.get('files')
        file_names = []
        file_contents = []

        for file_name in self.gist.files:
            if file_name in files:
                file = files[file_name]
                if file:
                    file_names.append(file_name)
                    file_contents.append(file.get("content"))
            else:
                file_names.append(file_name)
                file_contents.append(self.gist.get_file(file_name))

        self.gist.update(desc, file_names, file_contents)
        gist = Gist.get(self.gist.id)
        return gist_detail(gist, include_forks=True)
Exemplo n.º 3
0
    def test_gist_delete(self):
        gist = self._add_gist()
        gist_id = gist.id
        gist.delete()

        ret = Gist.get(gist_id)
        eq_(ret, None)
Exemplo n.º 4
0
def has_permission_handler(username, path, perm):
    if not username or not path:
        return False

    if path.endswith('.git'):
        path = path[:-4]

    # gist
    if path.startswith('gist/'):
        gist_id = path.rpartition("/")[-1]
        if username == Gist.get(gist_id).owner_id:
            return True
        return False

    # project
    project = Project.get_by_name(path)
    if not project:
        return False
    if perm == 'read':
        return True
    if not project.can_push:
        return False
    if project.has_push_perm(username):
        return True
    return False
Exemplo n.º 5
0
    def patch(self, request):
        if not self.is_owner:
            raise api_errors.NotTheAuthorError("gist", "update")

        desc = request.data.get("description")
        if not desc:
            desc = self.gist.description

        files = request.data.get("files")
        file_names = []
        file_contents = []

        for file_name in self.gist.files:
            if file_name in files:
                file = files[file_name]
                if file:
                    file_names.append(file_name)
                    file_contents.append(file.get("content"))
            else:
                file_names.append(file_name)
                file_contents.append(self.gist.get_file(file_name))

        self.gist.update(desc, file_names, file_contents)
        gist = Gist.get(self.gist.id)
        return gist_detail(gist, include_forks=True)
Exemplo n.º 6
0
    def __init__(self, request, id):
        self.id = id
        self.gist = Gist.get(self.id)

        if not self.gist:
            raise api_errors.NotFoundError("gist")

        self.is_owner = False
        self.comments = GistCommentsUI(request, self.gist)
Exemplo n.º 7
0
    def __init__(self, request, id):
        self.id = id
        self.gist = Gist.get(self.id)

        if not self.gist:
            raise api_errors.NotFoundError("gist")

        self.is_owner = False
        self.comments = GistCommentsUI(request, self.gist)
Exemplo n.º 8
0
 def index_a_gist(cls, id):
     gist = Gist.get(id)
     if not gist:
         return
     data = gist.as_dict()
     result = {}
     if data:
         serial = str(id)
         result = cls.c.post(
             'doc/gist_%s/' % serial, data=data, params={'refresh': True})
     return result
Exemplo n.º 9
0
def _get_gist_by_id(id):
    gist = {}
    _gist = Gist.get(id)
    if not _gist:
        return gist
    _owner = _get_user_by_name(_gist.owner_id)
    gist = dict(
        id=_gist.id,
        name=_gist.name,
        owner=_owner,
    )
    if _gist.fork_from:
        _from_gist = Gist.get(_gist.fork_from)
        _owner = _get_user_by_name(_from_gist.owner_id)
        gist['from_gist'] = dict(
            id=_from_gist.id,
            name=_from_gist.name,
            owner=_owner,
        )
    return gist
Exemplo n.º 10
0
    def __call__(self, request):
        resp = request.response
        resp.set_header("Content-Type", "text/javascript")
        resp.set_header('Expires', 'Sun, 1 Jan 2006 01:00:00 GMT')
        resp.set_header('Pragma', 'no-cache')
        resp.set_header('Cache-Control', 'must-revalidate, no-cache, private')
        if not self.gist_id.isdigit() or not Gist.get(self.gist_id):
            return "document.write('<span style=\"color:red;\">NOT EXIST GIST</span>')"  # noqa
        gist = Gist.get(self.gist_id)
        html = EMBED_CSS + EMBED_HEAD % gist.id
        for path in gist.files:
            path = path.encode('utf8')
            # TODO: clean this
            src = gist.get_file(path, rev='HEAD')
            src = highlight_code(path, src)
            src = src.replace('"', '\"').replace("'", "\'")
            html += SRC_FORMAT % (src, DOMAIN, gist.id, path, DOMAIN,
                                  gist.id, path, path, gist.url, DOMAIN)

        html += EMBED_FOOTER
        html = html.replace('\n', '\\n')
        return "document.write('%s')" % html
Exemplo n.º 11
0
    def __call__(self, request):
        resp = request.response
        resp.set_header("Content-Type", "text/javascript")
        resp.set_header('Expires', 'Sun, 1 Jan 2006 01:00:00 GMT')
        resp.set_header('Pragma', 'no-cache')
        resp.set_header('Cache-Control', 'must-revalidate, no-cache, private')
        if not self.gist_id.isdigit() or not Gist.get(self.gist_id):
            return "document.write('<span style=\"color:red;\">NOT EXIST GIST</span>')"  # noqa
        gist = Gist.get(self.gist_id)
        html = EMBED_CSS + EMBED_HEAD % gist.id
        for path in gist.files:
            path = path.encode('utf8')
            # TODO: clean this
            src = gist.get_file(path, rev='HEAD')
            src = highlight_code(path, src)
            src = src.replace('"', '\"').replace("'", "\'")
            html += SRC_FORMAT % (src, DOMAIN, gist.id, path, DOMAIN, gist.id,
                                  path, path, gist.url, DOMAIN)

        html += EMBED_FOOTER
        html = html.replace('\n', '\\n')
        return "document.write('%s')" % html
Exemplo n.º 12
0
Arquivo: feed.py Projeto: zhmch/code
def gist_updated_receiver(sender, **kw):
    gist_id = kw.get("gist_id")
    gist = Gist.get(gist_id)
    data = {
        "uid": "gist-update-%s" % gist.id,
        "author": gist.owner_id,
        "url": gist.url,
        "name": gist.full_name,
        "desc": gist.description,
        "date": gist.updated_at,
        "type": "gist_updated",
    }
    feeds = get_related_feeds(gist.owner_id)
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 13
0
def gist_updated_receiver(sender, **kw):
    gist_id = kw.get('gist_id')
    gist = Gist.get(gist_id)
    data = {
        'uid': 'gist-update-%s' % gist.id,
        'author': gist.owner_id,
        'url': gist.url,
        'name': gist.full_name,
        'desc': gist.description,
        'date': gist.updated_at,
        'type': 'gist_updated'
    }
    feeds = get_related_feeds(gist.owner_id)
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 14
0
def gist_updated_receiver(sender, **kw):
    gist_id = kw.get('gist_id')
    gist = Gist.get(gist_id)
    data = {
        'uid': 'gist-update-%s' % gist.id,
        'author': gist.owner_id,
        'url': gist.url,
        'name': gist.full_name,
        'desc': gist.description,
        'date': gist.updated_at,
        'type': 'gist_updated'
    }
    feeds = get_related_feeds(gist.owner_id)
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 15
0
def gist_commented_receiver(sender, **kw):
    gist_id = kw.get('gist_id')
    gist = Gist.get(gist_id)
    comment = kw.get('comment')
    data = {
        'uid': 'gist-comment-%s' % gist.id,
        'author': comment.user_id,
        'name': gist.full_name,
        'url': comment.url,
        'content': comment.content,
        'date': comment.created_at,
        'type': 'gist_commented',
    }
    feeds = get_related_feeds('', extra_receivers=[gist.owner_id])
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 16
0
def gist_commented_receiver(sender, **kw):
    gist_id = kw.get('gist_id')
    gist = Gist.get(gist_id)
    comment = kw.get('comment')
    data = {
        'uid': 'gist-comment-%s' % gist.id,
        'author': comment.user_id,
        'name': gist.full_name,
        'url': comment.url,
        'content': comment.content,
        'date': comment.created_at,
        'type': 'gist_commented',
    }
    feeds = get_related_feeds('', extra_receivers=[gist.owner_id])
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 17
0
Arquivo: feed.py Projeto: zhmch/code
def gist_commented_receiver(sender, **kw):
    gist_id = kw.get("gist_id")
    gist = Gist.get(gist_id)
    comment = kw.get("comment")
    data = {
        "uid": "gist-comment-%s" % gist.id,
        "author": comment.user_id,
        "name": gist.full_name,
        "url": comment.url,
        "content": comment.content,
        "date": comment.created_at,
        "type": "gist_commented",
    }
    feeds = get_related_feeds("", extra_receivers=[gist.owner_id])
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 18
0
Arquivo: feed.py Projeto: zhmch/code
def gist_starred_receiver(sender, **kw):
    author = kw.get("author")
    gist_id = kw.get("gist_id")
    gist = Gist.get(gist_id)
    uid = "gist-star-%s-%s" % (gist.id, author)
    data = {
        "uid": uid,
        "author": author,
        "url": gist.url,
        "name": gist.full_name,
        "desc": gist.description,
        "date": datetime.now(),
        "type": "gist_starred",
    }
    feeds = get_related_feeds(author, extra_receivers=[gist.owner_id])
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 19
0
def gist_starred_receiver(sender, **kw):
    author = kw.get('author')
    gist_id = kw.get('gist_id')
    gist = Gist.get(gist_id)
    uid = 'gist-star-%s-%s' % (gist.id, author)
    data = {
        'uid': uid,
        'author': author,
        'url': gist.url,
        'name': gist.full_name,
        'desc': gist.description,
        'date': datetime.now(),
        'type': 'gist_starred'
    }
    feeds = get_related_feeds(author, extra_receivers=[gist.owner_id])
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 20
0
def gist_starred_receiver(sender, **kw):
    author = kw.get('author')
    gist_id = kw.get('gist_id')
    gist = Gist.get(gist_id)
    uid = 'gist-star-%s-%s' % (gist.id, author)
    data = {
        'uid': uid,
        'author': author,
        'url': gist.url,
        'name': gist.full_name,
        'desc': gist.description,
        'date': datetime.now(),
        'type': 'gist_starred'
    }
    feeds = get_related_feeds(author, extra_receivers=[gist.owner_id])
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 21
0
    def _q_lookup(self, request, item):
        gid = item
        extend = None
        if item.count('.') == 1:
            gid, extend = item.split('.')

        if not gid.isdigit():
            raise TraversalError()

        gist = Gist.get(gid)

        if not gist or gist.owner_id != self.name:
            raise TraversalError()

        if extend == 'js':
            return GistEmbedUI(gid)

        return GistUI(gid)
Exemplo n.º 22
0
    def _q_lookup(self, request, item):
        gid = item
        extend = None
        if item.count('.') == 1:
            gid, extend = item.split('.')

        if not gid.isdigit():
            raise TraversalError()

        gist = Gist.get(gid)

        if not gist or gist.owner_id != self.name:
            raise TraversalError()

        if extend == 'js':
            return GistEmbedUI(gid)

        return GistUI(gid)
Exemplo n.º 23
0
Arquivo: feed.py Projeto: zhmch/code
def gist_forked_receiver(sender, **kw):
    gist_id = kw.get("gist_id")
    gist = Gist.get(gist_id)
    forked_from = gist.forked_from
    uid = "gist-fork-%s-%s" % (forked_from.id, gist.id)
    data = {
        "uid": uid,
        "author": gist.owner_id,
        "forked_from_name": forked_from.full_name,
        "forked_from_url": forked_from.url,
        "url": gist.url,
        "name": gist.full_name,
        "desc": gist.description,
        "date": gist.created_at,
        "type": "gist_forked",
    }
    feeds = get_related_feeds(gist.owner_id, extra_receivers=[forked_from.owner_id])
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 24
0
def gist_forked_receiver(sender, **kw):
    gist_id = kw.get('gist_id')
    gist = Gist.get(gist_id)
    forked_from = gist.forked_from
    uid = 'gist-fork-%s-%s' % (forked_from.id, gist.id)
    data = {
        'uid': uid,
        'author': gist.owner_id,
        'forked_from_name': forked_from.full_name,
        'forked_from_url': forked_from.url,
        'url': gist.url,
        'name': gist.full_name,
        'desc': gist.description,
        'date': gist.created_at,
        'type': 'gist_forked'
    }
    feeds = get_related_feeds(
        gist.owner_id, extra_receivers=[forked_from.owner_id])
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 25
0
def gist_forked_receiver(sender, **kw):
    gist_id = kw.get('gist_id')
    gist = Gist.get(gist_id)
    forked_from = gist.forked_from
    uid = 'gist-fork-%s-%s' % (forked_from.id, gist.id)
    data = {
        'uid': uid,
        'author': gist.owner_id,
        'forked_from_name': forked_from.full_name,
        'forked_from_url': forked_from.url,
        'url': gist.url,
        'name': gist.full_name,
        'desc': gist.description,
        'date': gist.created_at,
        'type': 'gist_forked'
    }
    feeds = get_related_feeds(gist.owner_id,
                              extra_receivers=[forked_from.owner_id])
    for feed in feeds:
        feed.add_action(data)
Exemplo n.º 26
0
def has_permission_handler(environ, path, perm):

    if DEVELOP_MODE:
        return True

    username = environ.get('REMOTE_USER')

    # if len(path) < 4:
    #    return
    name = path[:-4]

    # gist
    if name.startswith('gist/'):
        gist_id = name.rpartition("/")[-1]
        gist = Gist.get(gist_id)
        if not gist:
            return

        if perm == 'read':
            return True

        if not username:
            return

        return gist.owner_id == username

    # project
    project = CodeDoubanProject.get_by_name(name)
    if not project:
        return

    if perm == 'read':
        return True

    if not username:
        return
    if not project.can_push:
        # merge only
        return
    return project.has_push_perm(username)
Exemplo n.º 27
0
def has_permission_handler(environ, path, perm):

    if DEVELOP_MODE:
        return True

    username = environ.get('REMOTE_USER')

    # if len(path) < 4:
    #    return
    name = path[:-4]

    # gist
    if name.startswith('gist/'):
        gist_id = name.rpartition("/")[-1]
        gist = Gist.get(gist_id)
        if not gist:
            return

        if perm == 'read':
            return True

        if not username:
            return

        return gist.owner_id == username

    # project
    project = CodeDoubanProject.get_by_name(name)
    if not project:
        return

    if perm == 'read':
        return True

    if not username:
        return
    if not project.can_push:
        # merge only
        return
    return project.has_push_perm(username)
Exemplo n.º 28
0
 def __init__(self, gist_id):
     self.gist = Gist.get(gist_id)
Exemplo n.º 29
0
 def __init__(self, id):
     self.rev = ''
     self.gist = Gist.get(id)
Exemplo n.º 30
0
 def __init__(self, gist_id):
     self.gist = Gist.get(gist_id)
Exemplo n.º 31
0
 def __init__(self, id):
     self.id = id
     self.gist = Gist.get(id)
Exemplo n.º 32
0
 def url(self):
     from vilya.models.gist import Gist
     return '%s/#comment-%s' % (Gist.get(self.gist_id).url, self.id)
Exemplo n.º 33
0
 def __init__(self, id):
     self.rev = ''
     self.gist = Gist.get(id)
Exemplo n.º 34
0
 def url(self):
     from vilya.models.gist import Gist
     return '%s/#comment-%s' % (Gist.get(self.gist_id).url, self.id)
Exemplo n.º 35
0
 def __init__(self, id):
     self.id = id
     self.gist = Gist.get(id)