# Path: datawire/model/user.py
# class User(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     login = db.Column(db.Unicode(255))
#     email = db.Column(db.Unicode, nullable=True)
#     oauth_id = db.Column(db.Unicode)
#     api_key = db.Column(db.Unicode, default=make_token)
# 
#     is_admin = db.Column(db.Boolean, nullable=False, default=False)
# 
#     created_at = db.Column(db.DateTime, default=datetime.utcnow)
#     updated_at = db.Column(db.DateTime, default=datetime.utcnow,
#                            onupdate=datetime.utcnow)
# 
#     def is_active(self):
#         return True
# 
#     def is_authenticated(self):
#         return True
# 
#     def is_anonymous(self):
#         return False
# 
#     def get_id(self):
#         return self.login
# 
#     def __repr__(self):
#         return '<User(%r,%r)>' % (self.id, self.login)
# 
#     def __unicode__(self):
#         return self.login
# 
#     def to_dict(self):
#         return {
#             'id': self.id,
#             'login': self.login,
#             'is_admin': self.is_admin,
#             'created_at': self.created_at,
#             'updated_at': self.updated_at,
#             'api_url': url_for('users.view', login=self.login)
#         }
# 
#     def update(self, data):
#         data = UserForm().deserialize(data)
#         self.email = data.get('email')
# 
#     @classmethod
#     def load(cls, data):
#         user = cls.by_oauth_id(data.get('oauth_id'))
# 
#         if user is None:
#             user = cls()
#             user.login = data.get('login')
#             user.oauth_id = data.get('oauth_id')
# 
#         if data.get('email'):
#             # FIXME: better to overwrite with upstream or keep?
#             user.email = data.get('email')
#         db.session.add(user)
#         return user
# 
#     @classmethod
#     def all(cls):
#         q = db.session.query(cls)
#         return q
# 
#     @classmethod
#     def by_login(cls, login):
#         q = db.session.query(cls).filter_by(login=login)
#         return q.first()
# 
#     @classmethod
#     def by_api_key(cls, api_key):
#         q = db.session.query(cls).filter_by(api_key=api_key)
#         return q.first()
# 
#     @classmethod
#     def by_oauth_id(cls, oauth_id):
#         q = db.session.query(cls).filter_by(oauth_id=unicode(oauth_id))
#         return q.first()
# 
# Path: datawire/core.py
# def url_for(*a, **kw):
# 
# Path: datawire/authz.py
# def authz_collections(action):
# def collection_read(id):
# def collection_write(id):
# def logged_in():
# def require(pred):


from flask import Blueprint
from flask.ext.login import current_user
from apikit import obj_or_404, request_data, Pager, jsonify
from datawire.model import User
from datawire.core import db
from datawire import authz



blueprint = Blueprint('users', __name__)


@blueprint.route('/api/1/users', methods=['GET'])
def index():

# Path: datawire/model/user.py
# class User(db.Model):
#     id = db.Column(db.Integer, primary_key=True)
#     login = db.Column(db.Unicode(255))
#     email = db.Column(db.Unicode, nullable=True)
#     oauth_id = db.Column(db.Unicode)
#     api_key = db.Column(db.Unicode, default=make_token)
# 
#     is_admin = db.Column(db.Boolean, nullable=False, default=False)
# 
#     created_at = db.Column(db.DateTime, default=datetime.utcnow)
#     updated_at = db.Column(db.DateTime, default=datetime.utcnow,
#                            onupdate=datetime.utcnow)
# 
#     def is_active(self):
#         return True
# 
#     def is_authenticated(self):
#         return True
# 
#     def is_anonymous(self):
#         return False
# 
#     def get_id(self):
#         return self.login
# 
#     def __repr__(self):
#         return '<User(%r,%r)>' % (self.id, self.login)
# 
#     def __unicode__(self):
#         return self.login
# 
#     def to_dict(self):
#         return {
#             'id': self.id,
#             'login': self.login,
#             'is_admin': self.is_admin,
#             'created_at': self.created_at,
#             'updated_at': self.updated_at,
#             'api_url': url_for('users.view', login=self.login)
#         }
# 
#     def update(self, data):
#         data = UserForm().deserialize(data)
#         self.email = data.get('email')
# 
#     @classmethod
#     def load(cls, data):
#         user = cls.by_oauth_id(data.get('oauth_id'))
# 
#         if user is None:
#             user = cls()
#             user.login = data.get('login')
#             user.oauth_id = data.get('oauth_id')
# 
#         if data.get('email'):
#             # FIXME: better to overwrite with upstream or keep?
#             user.email = data.get('email')
#         db.session.add(user)
#         return user
# 
#     @classmethod
#     def all(cls):
#         q = db.session.query(cls)
#         return q
# 
#     @classmethod
#     def by_login(cls, login):
#         q = db.session.query(cls).filter_by(login=login)
#         return q.first()
# 
#     @classmethod
#     def by_api_key(cls, api_key):
#         q = db.session.query(cls).filter_by(api_key=api_key)
#         return q.first()
# 
#     @classmethod
#     def by_oauth_id(cls, oauth_id):
#         q = db.session.query(cls).filter_by(oauth_id=unicode(oauth_id))
#         return q.first()
# 
# Path: datawire/core.py
# def url_for(*a, **kw):
# 
# Path: datawire/authz.py
# def authz_collections(action):
# def collection_read(id):
# def collection_write(id):
# def logged_in():
# def require(pred):


# Path: datawire/views/api/users.py
from flask import Blueprint
from flask.ext.login import current_user
from apikit import obj_or_404, request_data, Pager, jsonify
from datawire.model import User
from datawire.core import db
from datawire import authz




blueprint = Blueprint('users', __name__)


@blueprint.route('/api/1/users', methods=['GET'])
def index():

    authz.require(authz.logged_in())