Exemple #1
0
    def get_current(self):
        """Fetch the currently logged in User"""

        req = None

        # If user is not yet a list owner, either submit a request
        # or, if user is an admin, create owner record
        if self.owner is None:
            if self.user.is_admin:
                self.owner = self.db.add_owner(self.user)
            else:
                req = self.db.get_req_by_user(self.user)
                if req is None:
                    req = self.db.add_req(self.user)

        js_owner = JsOwner.from_db(self.owner) if self.owner else None
        js_user = JsUser(user_id=self.user.user_id(),
                         nickname=self.user.nickname(),
                         email=self.user.email(),
                         was_request_denied=req.denied if req else False,
                         is_admin=self.user.is_admin,
                         owner_id=js_owner.id if js_owner else -1,
                         logout_url=self.ae.create_logout_url('/'))

        self.dump(js_user)
Exemple #2
0
    def get_current(self):
        """Fetch the currently logged in User"""

        req = None

        # If user is not yet a list owner, either submit a request
        # or, if user is an admin, create owner record
        if self.owner is None:
            if self.user.is_admin:
                self.owner = self.db.add_owner(self.user)
            else:
                req = self.db.get_req_by_user(self.user)
                if req is None:
                    req = self.db.add_req(self.user)

        js_owner = JsOwner.from_db(self.owner) if self.owner else None
        js_user = JsUser(
            user_id=self.user.user_id(),
            nickname=self.user.nickname(),
            email=self.user.email(),
            was_request_denied=req.denied if req else False,
            is_admin=self.user.is_admin,
            owner_id=js_owner.id if js_owner else -1,
            logout_url=self.ae.create_logout_url('/')
        )

        self.dump(js_user)
Exemple #3
0
 def update_owner(self, owner_id, name, nickname):
     '''
     Update the name and nickname of the ListOwner object with the given
     owner_id and return the updated object.
     '''
     owner = self.db.get_owner(owner_id)
     owner.name = name
     owner.nickname = nickname
     return ListOwner.from_db(owner.put())
Exemple #4
0
 def update_owner(self, owner_id, name, nickname):
     '''
     Update the name and nickname of the ListOwner object with the given
     owner_id and return the updated object.
     '''
     owner = self.db.get_owner(owner_id)
     owner.name = name
     owner.nickname = nickname
     return ListOwner.from_db(owner.put())
Exemple #5
0
    def put(self, resource_id):
        """ Update owner """
        extra = dict(owner_id=resource_id, body=self.request.body)
        logging.info('owners::put', extra=extra)

        data = json.loads(self.request.body)
        owner = self.db.get_owner(int(resource_id))
        owner.name = data.name
        owner.nickname = data.nickname
        js_owner = JsOwner.from_db(owner.put())
        self.dump(js_owner)
Exemple #6
0
    def put(self, resource_id):
        """ Update owner """
        extra = dict(owner_id=resource_id, body=self.request.body)
        logging.info("owners::put", extra=extra)

        data = json.loads(self.request.body)
        owner = self.db.get_owner(int(resource_id))
        owner.name = data.name
        owner.nickname = data.nickname
        js_owner = JsOwner.from_db(owner.put())
        self.dump(js_owner)
Exemple #7
0
    def get(self, resource_id=None):
        """ Fetch owner """

        logging.info('owners::get', extra=dict(owner_id=resource_id))
        if resource_id is None:
            self.abort(404)

        owner = self.db.get_owner(int(resource_id))
        if owner is None:
            self.abort(404)

        js_owner = JsOwner.from_db(owner)
        self.dump(js_owner)
Exemple #8
0
    def get(self, resource_id=None):
        """ Fetch owner """

        logging.info("owners::get", extra=dict(owner_id=resource_id))
        if resource_id is None:
            self.abort(404)

        owner = self.db.get_owner(int(resource_id))
        if owner is None:
            self.abort(404)

        js_owner = JsOwner.from_db(owner)
        self.dump(js_owner)
Exemple #9
0
 def get_available_owners(self, owner_id):
     self._verify_owner()
     # TODO: optimize this to minimize queries
     owner = self.db.get_owner(owner_id)
     gs, gms = (owner.groups, owner.memberships)
     owners = [ owner ]
     owners.extend(m.member for g in gs for m in g.members)
     owners.extend(m.member for gm in gms for m in gm.group.members)
     unique_owners = []
     oids = []
     for owner in owners:
         if owner.key().id() not in oids:
             oids.append(owner.key().id())
             unique_owners.append(owner)
     return [ ListOwner.from_db(o) for o in unique_owners ]
Exemple #10
0
 def get_available_owners(self, owner_id):
     self._verify_owner()
     # TODO: optimize this to minimize queries
     owner = self.db.get_owner(owner_id)
     gs, gms = (owner.groups, owner.memberships)
     owners = [owner]
     owners.extend(m.member for g in gs for m in g.members)
     owners.extend(m.member for gm in gms for m in gm.group.members)
     unique_owners = []
     oids = []
     for owner in owners:
         if owner.key().id() not in oids:
             oids.append(owner.key().id())
             unique_owners.append(owner)
     return [ListOwner.from_db(o) for o in unique_owners]
Exemple #11
0
 def get_owner(self, owner_id):
     '''
     Return the ListOwner object with the given owner_id
     '''
     return ListOwner.from_db(self.db.get_owner(owner_id))
Exemple #12
0
 def get_owner(self, owner_id):
     '''
     Return the ListOwner object with the given owner_id
     '''
     return ListOwner.from_db(self.db.get_owner(owner_id))