Skip to content
This repository has been archived by the owner on Aug 4, 2018. It is now read-only.

Commit

Permalink
Merged branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fingercomp committed Jul 9, 2016
2 parents 13fc1c9 + f8a0802 commit 47267d8
Show file tree
Hide file tree
Showing 20 changed files with 1,523 additions and 558 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ notifications:
template:
- "\x0300,01New build on \x02%{repository_slug}\x02!"
- "\x02%{repository_name}#%{build_number}\x02 [\x1f%{branch}\x1f] %{message}"
- "\x02Elapsed time:\x02 %{elapsed_time} | \x02Total duration:\x02 %{duration}"
- "[\x1f%{commit}\x1f] \x02%{author}\x02: %{commit_message}"
- "\x02Changes:\x02 %{compare_url}"
- "\x02Build details:\x02 %{build_url}"
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.3.0
-----
- Wrappers for the remaining views.
- A wrapper around package creating.
- A User:GET wrapper.
- A User:POST wrapper.
- 100% test coverage.

0.2.0
-----
- Short description search.
Expand Down
18 changes: 12 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@
if __name__ == '__main__':
here = os.path.dirname(os.path.abspath(__file__))

if 'OPENSHIFT_APP_NAME' in os.environ: #are we on OPENSHIFT?
# are we on OPENSHIFT?
if 'OPENSHIFT_APP_NAME' in os.environ:
ip = os.environ['OPENSHIFT_PYTHON_IP']
port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
config = os.path.join(here, 'production.ini')
else:
ip = '0.0.0.0' #localhost
# localhost
ip = '0.0.0.0'
port = 6543
config = os.path.join(here, 'development.ini')

app = get_app(config, 'main') #find 'main' method in __init__.py. That is our wsgi app
settings = get_appsettings(config, 'main') #don't really need this but is an example on how to get settings from the '.ini' files
# find 'main' method in __init__.py. That is our wsgi app
app = get_app(config, 'main')
# don't really need this but is an example on how to get settings
# from the '.ini' files
settings = get_appsettings(config, 'main')

# Waitress (remember to include the waitress server in "install_requires" in the setup.py)
# Waitress (remember to include the waitress server in
# "install_requires" in the setup.py)
from waitress import serve
print("Starting Waitress.")
serve(app, host=ip, port=port, threads=50)
serve(app, host=ip, port=port, threads=50)
6 changes: 3 additions & 3 deletions hel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def main(global_config, **settings):

# Auth
auth_secret = "巏⇟ू攛劈ᜤ漢࿅䓽奧䬙摀曇䰤䙙൪ᴹ喼唣壆"
if 'AUTH_SECRET' in os.environ:
if 'AUTH_SECRET' in os.environ: # pragma: no cover
auth_secret = os.environ["AUTH_SECRET"]
authentication_policy = HELAuthenticationPolicy(
auth_secret, hashalg='sha512')
Expand All @@ -61,9 +61,9 @@ def main(global_config, **settings):

# Setup MongoDB
url = 'mongodb://localhost:27017/'
if 'MONGODB_URL' in os.environ:
if 'MONGODB_URL' in os.environ: # pragma: no cover
url = os.environ['MONGODB_URL']
elif 'mongo_db_url' in settings:
elif 'mongo_db_url' in settings: # pragma: no cover
url = settings['mongo_db_url']
config.registry.mongo = MongoClient(url)

Expand Down
42 changes: 26 additions & 16 deletions hel/resources.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from bson.objectid import ObjectId
from pyramid.traversal import find_root
from pyramid.security import Allow, Everyone, Authenticated, ALL_PERMISSIONS
from pyramid.traversal import find_root


class Resource(dict):
Expand Down Expand Up @@ -45,7 +45,8 @@ def retrieve(self, query=None):

def create(self, document):
object_id = self.collection.insert(document)
return self.resource_name(ref=str(object_id), parent=self)
return self.resource_name(ref=str(object_id), parent=self,
id_as_ref=True)


class MongoDocument(Resource):
Expand All @@ -65,30 +66,38 @@ def retrieve(self):
return self.collection.find_one(self.get_spec())

def update(self, *args, **kwargs):
self.collection.update(self.get_spec(), args[0])
self.collection.find_and_modify(self.get_spec(), args[0])

def delete(self):
self.collection.remove(self.get_spec())


class Package(MongoDocument):

def __init__(self, ref, parent):
owner = None

def __init__(self, ref, parent, id_as_ref=False):
MongoDocument.__init__(self, ref, parent)
if id_as_ref:
self.get_owner()
self.spec = {'name': ref}
if not id_as_ref:
self.get_owner()

def retrieve_owner(self):
if not hasattr(self, 'owner'):
self.owner = self.retrieve()['owner']
self.acl += [
(Allow, '@' + self.owner, ('pkg_delete', 'pkg_update',),),
]
def get_owner(self):
try:
self.owner = self.owner or self.retrieve()['owner']
except:
pass
return self.owner

def __acl__(self):
self.retrieve_owner()
return self.acl + [
(Allow, Everyone, 'pkg_view',)
data = self.acl + [
(Allow, Everyone, 'pkg_view',),
]
if self.owner:
data += [(Allow, self.owner, ('pkg_delete', 'pkg_update',),)]
return data


class Packages(MongoCollection):
Expand All @@ -101,13 +110,14 @@ def __getitem__(self, ref):

def __acl__(self):
return self.acl + [
(Allow, Everyone, 'pkgs_view',)
(Allow, Everyone, 'pkgs_view',),
(Allow, Authenticated, 'pkg_create',) # TODO: Activated only
]


class User(MongoDocument):

def __init__(self, ref, parent):
def __init__(self, ref, parent, id_as_ref=False):
MongoDocument.__init__(self, ref, parent)
self.spec = {'nickname': ref}

Expand All @@ -127,7 +137,7 @@ def __getitem__(self, ref):

def __acl__(self):
return self.acl + [
(Allow, Authenticated, 'user_list',)
(Allow, Everyone, 'user_list',)
]


Expand Down
2 changes: 1 addition & 1 deletion hel/templates/home.pt
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<div class="row red">
<div class="links">
<ul>
<li class="current-version">v 0.1.0</li>
<li class="current-version">v 0.3.0</li>
<li><i class="glyphicon glyphicon-bookmark icon-muted"></i><a href="https://github.com/hel-repo/hel/wiki">Docs</a></li>
<li><i class="glyphicon glyphicon-cog icon-muted"></i><a href="https://github.com/hel-repo/hel">Github Project</a></li>
<li><i class="glyphicon glyphicon-globe icon-muted"></i><a href="http://webchat.esper.net/?channels=#cc.ru">IRC Channel</a></li>
Expand Down
Loading

0 comments on commit 47267d8

Please sign in to comment.