# Path: moonrock/models/users.py
# class User(BaseObject):
#     __tablename__ = 'users'
# 
#     id = Column(Integer,
#                 Sequence('user_id_seq'),
#                 primary_key=True)
#     userid = Column(String(20), unique=True)
#     username = Column(String(120), unique=True)
#     email = Column(String(120))
#     first_name = Column(String(120))
#     last_name = Column(String(120))
#     twitter = Column(String(120))
#     password = Column(String(120))
#     groups = Column(ArrayType)
# 
#     def __repr__(self):
#         return "<User(id=%d, username='%s')>" % (self.id, self.username)
# 
#     def __json__(self, request):
#         return dict(
#             id=self.id,
#             userid=self.userid,
#             first_name=self.first_name,
#             last_name=self.last_name,
#             twitter=self.twitter,
#             email=self.email
#         )
# 
# Path: moonrock/models/site.py
# class Folder(Node):
#     __tablename__ = 'folder'
#     id = Column(Integer, ForeignKey('node.id'), primary_key=True)
#     title = Column(Text)
#     __acl__ = [(Allow, Everyone, 'view'),
#                (Allow, 'group:editors', 'edit')]
# 
#     def __json__(self, request):
#         return dict(
#             id=self.id,
#             title=self.title,
#             resourceType='Folder'
#         )
# 
# class Document(Node):
#     __tablename__ = 'document'
#     id = Column(Integer, ForeignKey('node.id'), primary_key=True)
#     title = Column(Text)
# 
#     def __json__(self, request):
#         return dict(
#             id=self.id,
#             title=self.title
#         )
# 
# Path: moonrock/rest_ext.py
# class MoonSQLResource(SQLResource):
#     """Base class for resources based on SQLAlchemy ORM models.
#     """
# 
#     toplevel_key = 'data'
# 
#     @property
#     def userid(self):
#         return int(self.request.authenticated_userid)
# 
#     def to_dict(self):
#         data = super(MoonSQLResource, self).to_dict()
#         return {self.toplevel_key: data}


from sqlalchemy.orm import Query
from pyramid.security import Authenticated
from pyramid.view import (
    view_config,
    view_defaults
)
from rest_toolkit import resource
from rest_toolkit.abc import ViewableResource
from pyramid_sqlalchemy import Session
from .models.users import User
from .models.site import Folder, Document
from .rest_ext import MoonSQLResource




# Don't delete this...we have some kind of eager loading on
# polymorphic identity tht causes an error if Folder is not imported.



@resource('/api/me', read_permission='view')
class ProfileResource(MoonSQLResource, ViewableResource):
    __acl__ = (('Allow', Authenticated, 'view'),)

    @property
    def context_query(self):

# Path: moonrock/models/users.py
# class User(BaseObject):
#     __tablename__ = 'users'
# 
#     id = Column(Integer,
#                 Sequence('user_id_seq'),
#                 primary_key=True)
#     userid = Column(String(20), unique=True)
#     username = Column(String(120), unique=True)
#     email = Column(String(120))
#     first_name = Column(String(120))
#     last_name = Column(String(120))
#     twitter = Column(String(120))
#     password = Column(String(120))
#     groups = Column(ArrayType)
# 
#     def __repr__(self):
#         return "<User(id=%d, username='%s')>" % (self.id, self.username)
# 
#     def __json__(self, request):
#         return dict(
#             id=self.id,
#             userid=self.userid,
#             first_name=self.first_name,
#             last_name=self.last_name,
#             twitter=self.twitter,
#             email=self.email
#         )
# 
# Path: moonrock/models/site.py
# class Folder(Node):
#     __tablename__ = 'folder'
#     id = Column(Integer, ForeignKey('node.id'), primary_key=True)
#     title = Column(Text)
#     __acl__ = [(Allow, Everyone, 'view'),
#                (Allow, 'group:editors', 'edit')]
# 
#     def __json__(self, request):
#         return dict(
#             id=self.id,
#             title=self.title,
#             resourceType='Folder'
#         )
# 
# class Document(Node):
#     __tablename__ = 'document'
#     id = Column(Integer, ForeignKey('node.id'), primary_key=True)
#     title = Column(Text)
# 
#     def __json__(self, request):
#         return dict(
#             id=self.id,
#             title=self.title
#         )
# 
# Path: moonrock/rest_ext.py
# class MoonSQLResource(SQLResource):
#     """Base class for resources based on SQLAlchemy ORM models.
#     """
# 
#     toplevel_key = 'data'
# 
#     @property
#     def userid(self):
#         return int(self.request.authenticated_userid)
# 
#     def to_dict(self):
#         data = super(MoonSQLResource, self).to_dict()
#         return {self.toplevel_key: data}


# Path: moonrock/views.py
from sqlalchemy.orm import Query
from pyramid.security import Authenticated
from pyramid.view import (
    view_config,
    view_defaults
)
from rest_toolkit import resource
from rest_toolkit.abc import ViewableResource
from pyramid_sqlalchemy import Session
from .models.users import User
from .models.site import Folder, Document
from .rest_ext import MoonSQLResource





# Don't delete this...we have some kind of eager loading on
# polymorphic identity tht causes an error if Folder is not imported.



@resource('/api/me', read_permission='view')
class ProfileResource(MoonSQLResource, ViewableResource):
    __acl__ = (('Allow', Authenticated, 'view'),)

    @property
    def context_query(self):

        return Query(User).filter(User.id == self.userid)