예제 #1
0
class Credentials(Document):
    """A set of credentials for a user"""
    schema = {
        'type': 'object',
        'required': ['password', 'salt', 'secret'],
        'properties': {
            'user': S.fk('api', 'auth', 'users'),
            'password': {
                'type': 'string',
                'description': "The user's (encrypted) password."
            },
            'salt': {
                'type': 'string',
                'description': "The salt applied to the password"
            },
            'secret': {
                'type': 'string',
                'description': "The user's secret key, used in JWT auth"
            },
            'jwtClaims': {
                'type': 'object',
                'description': "Any additional claims to add to a user's JSON Web Token before encoding."
            },
            'confirmation_code': {
                'type': 'string',
                'description': "A generated code that confirms a user's email"
            }
        }
    }
예제 #2
0
class IssuedToken(Document):
    schema = S.object(
        properties=S.props(
            ('token', S.string()),
            ('user', S.fk('auth','users')),
            ('exp', S.datetime()),
        )
    )
예제 #3
0
파일: test.py 프로젝트: JeffHeard/sondra
from sondra.schema import S, deep_merge

schema1 = S.object(
    title="Ticket",
    description='A work order for Pronto',
    required=['title', 'creator', 'status', 'open', 'price'],
    properties=S.props(
        ("asset", S.fk('api','core','assets', title="Asset")),
        ("location", S.geo(description="A copy of asset location, for efficient indexing purposes.", geometry_type='Point')),
        ("title", S.string(title="Title", description="A description of the title")),
        ("ticket_type", S.fk('api','core','ticket-types', title="Ticket Type")),
        ("narrative", S.string(title="Narrative", description="Details relevant to fixing the problem.")),
        ("confirm_before_dispatch", S.boolean(title="Confirm before dispatch", description="True if 365 pronto should confirm with the asset contact before a worker arrives on site", default=False)),
        ("clock_running", S.boolean(default=False)),
        ("next_response_due", S.datetime()),
        ("inconsistencies", S.integer(default=0, description="The number of inconsistencies reported in answers or status changes.")),
        ("flags", S.integer(default=0, description="A count of out of bounds values reported in worksheets.")),
        ("requires_review", S.boolean(default=False)),
        ("designated_reviewer", S.fk('api','auth','users')),
        ("related", S.array(items=S.string(), description='Any tickets whose body of work relates to the completion of this ticket.')),
        ("predecessor", S.string(description='The ticket this ticket was raised as a consequence of.')),
        ("antecedent", S.string(description='The ticket raised as a consequence of this one.')),
        ("required_professionals", S.integer(description="The number of people required on this ticket", default=1)),
        ("assigned_professionals", S.array(items=S.ref('assignee'))),
        ("creator", S.fk('api','auth','users', description="The person who created the ticket")),
        ("assignee", S.fk('api','auth','users', description="The person who currently is responsible for the ticket")),
        ("status", S.ref('ticket_status')),
        ("tech_support_token", S.string(
            description="Automatically generated. Send this token as part of a URL in email to allow a third party "
                        "tech support access to view this ticket and communicate with the assigned professionals "
                        "through the admin console or third-party app."
예제 #4
0
class User(Document):
    """A basic, but fairly complete system user record"""
    active_by_default = True
    template = "${username}"

    schema = {
        'type': 'object',
        'required': ['email'],
        'properties': S.props(
            ('username', {
                'title': 'Username',
                'type': 'string',
                'description': 'The user\'s username',
            }),
            ('email', {
                'title': 'Email',
                'type': 'string',
                'description': 'The user\'s email address',
                'format': 'email',
                'pattern': '^[^@]+@[^@]+\.[^@]+$'
            }),
            ('email_verified', {
                'title': 'Email Verified',
                'type': 'boolean',
                'description': 'Whether or not this email address has been verified',
            }),
            ('picture', S.image(description='A URL resource of a photograph')),
            ('family_name', {
                'title': 'Family Name',
                'type': 'string',
                'description': 'The user\'s family name',
            }),
            ('given_name', {
                'title': 'Given Name',
                'type': 'string',
                'description': 'The user\'s family name',
            }),
            ('names', {
                'title': 'Other Names',
                'type': 'array',
                'items': {'type': 'string'},
                'description': 'A list of names that go between the given name and the family name.',
            }),
            ('locale', {
                'title': 'Default Language',
                'type': 'string',
                'description': "The user's locale. Default is en-US",
                'default': 'en-US'
            }),
            ('active', {
                'title': 'Active',
                'type': 'boolean',
                'description': 'Whether or not the user is currently able to log into the system.',
                'default': active_by_default
            }),
            ('admin', {
                'title': 'Administrator',
                'type': 'boolean',
                'description': 'If true, this user can access all methods of all APIs.',
                'default': False
            }),
            ('created', {
                'title': 'Created',
                'format': 'date-time',
                'type': 'string',
                'description': 'The timestamp this user was created',
            }),
            ("roles", {
                'title': 'Roles',
                "type": "array",
                "items": S.fk('api', 'auth', 'roles'),
                "description": "Roles that have been granted to this user",
            }),
            ("dob", {
                "title": "Date of Birth",
                "type": "string",
                "format": "date-time",
                "description": "The user's birthday"
            })
        )
    }

    @expose_method
    def permissions(self) -> [dict]:
        return functools.reduce(operator.add, [role['permissions'] for role in self.fetch('roles')], [])

    @expose_method
    def confirm_email(self, confirmation_code: str) -> bool:
        confirmed = self.application['credentials'][self.url]['confirmation_code'] == confirmation_code
        self['confirmed'] = self['confirmed'] or confirmed
        self.save()
        return self['confirmed']

    @authorized_method
    @expose_method
    def send_confirmation_email(self, _user=None) -> None:
        raise NotImplemented()

    def __str__(self):
        return self['username']
예제 #5
0
파일: test.py 프로젝트: rpangasa/sondra
from sondra.schema import S, deep_merge

schema1 = S.object(
    title="Ticket",
    description='A work order for Pronto',
    required=['title', 'creator', 'status', 'open', 'price'],
    properties=S.props(
        ("asset", S.fk('api', 'core', 'assets', title="Asset")),
        ("location",
         S.geo(description=
               "A copy of asset location, for efficient indexing purposes.",
               geometry_type='Point')),
        ("title",
         S.string(title="Title", description="A description of the title")),
        ("ticket_type", S.fk(
            'api', 'core', 'ticket-types', title="Ticket Type")),
        ("narrative",
         S.string(title="Narrative",
                  description="Details relevant to fixing the problem.")),
        ("confirm_before_dispatch",
         S.boolean(
             title="Confirm before dispatch",
             description=
             "True if 365 pronto should confirm with the asset contact before a worker arrives on site",
             default=False)), ("clock_running", S.boolean(default=False)),
        ("next_response_due", S.datetime()),
        ("inconsistencies",
         S.integer(
             default=0,
             description=
             "The number of inconsistencies reported in answers or status changes."