class Schema(object): key = fields.String(description='The unique name of the resource.', enum=CONFIGURATION_KEYS) value = fields.Custom( fields.Any(), attribute='key', description='The current value of the configuration setting. ', io='r', formatter=get_configuration, ) description = fields.Custom( fields.String(), attribute='key', description= 'An explanation of what the configuration setting does.', io='r', formatter=lambda key: _DEFAULT_CONFIGURATION_STORE[key][ 'description'], ) defaultValue = fields.Custom( fields.Any(), attribute='key', description='The default value of the setting.', io='r', formatter=lambda key: _DEFAULT_CONFIGURATION_STORE[key]['value'], )
class Schema(object): name = fields.Custom( fields.String(enum=RESOURCE_TYPES), formatter=lambda rsc_type: rsc_type.name, title='Name', description='The string representation of the resource type.', )
class Schema: uuid = fields.UUID() user = fields.Inline('user') host = fields.Inline('host') start = fields.DateTimeString() end = fields.DateTimeString() duration = fields.Custom('{"type": "integer"}', io="r", formatter=lambda x: x.total_seconds())
class Schema(object): users = fields.List(CONCISE_USER_SCHEMA, description='The individual users in a group.', io='r') roles = fields.Custom( ROLE_MAP_SCHEMA, description='The role(s) that all members of the group possess', attribute='roles', formatter=role_list_as_map, default=[], io='r', )
class Schema(object): permissions = fields.List( PERMISSION_SCHEMA, title='Role Permissions', description='The permissions the role has.', ) resourceType = fields.Custom( fields.String(), attribute='resource_type', converter=None, formatter=lambda rsc_type: rsc_type.name.name, title='resourceType', description='The resource type this role is associated with.', io='r', )
class Schema(object): username = USERNAME_SCHEMA roles = fields.Custom( ROLE_MAP_SCHEMA, description='The role(s) that the user currently possesses.', attribute='roles', formatter=role_list_as_map, default=[], ) firstName = fields.String( description='The first name of the user.', attribute='first_name', pattern=INTERNATIONALIZED_ALPHANUMERIC_AND_DELIMITER, ) lastName = fields.String( description='The last name of the user.', attribute='last_name', pattern=INTERNATIONALIZED_ALPHANUMERIC_AND_DELIMITER_OR_EMPTY, ) phoneNumber = fields.String( description='The phone number of the user.', attribute='phone_number') # Disabling this warning because Hyper-Schema is enforcing # that the value of this field MUST match one of the values # of the Enum. # pylint:disable=E1136 # pylint: disable=E1101 status = fields.Custom( fields.String(enum=USER_STATUSES), attribute='status_id', formatter=lambda status_id: UserStatusEnum(status_id).name.lower(), converter=lambda status_value: UserStatusEnum[status_value.upper()] .value, default=UserStatusEnum.ACTIVE.value, nullable=False, )
class Schema(object): name = fields.String(description='The unique name of the resource.') resourceType = fields.Custom( fields.String(), attribute='resource_type', converter=None, formatter=lambda rsc_type: rsc_type.name.name, title='resourceType', description='The string representation of the resource type.', io='r', ) users = fields.List( CONCISE_USER_SCHEMA, description= 'The user(s) that hold one or more roles for this resource.', io='r', ) groups = fields.List( CONCISE_GROUP_SCHEMA, description= 'The group(s) that hold one or more roles for this resource.', io='r', )
# need to expose the exact structure. Instead we offer a nice JSONified version of it for # easy consumption on the client side. Clients are able to change Roles that a User/Group is # a member of via the APIs and as such, don't need to interact with # `UserRoles`/`GroupRoles`/`DefaultRoles` directly. '''The schema for the `UserRoles` model. ''' USER_ROLES_SCHEMA = fields.Custom( fields.Object({ 'roleName': fields.String(io='r', description='The name of the role. '), 'resourceName': fields.String( io='r', description= 'The resource that the role is tied to. If null, this role is applicable ' 'sitewide on all resources of the specified type.', nullable=True, ), 'resourceType': fields.String( io='r', description='The type of resource the role is associated with.'), }), converter=None, formatter=lambda user_role: user_role_as_dictionary(user_role, True), ) # NOTE(vedant): The structure of `GroupRoles` is identical to `UserRoles` although the models # have different Primary Key constraints which is why they are represented separately. '''The schema for the `GroupRoles` model. ''' GROUP_ROLES_SCHEMA = USER_ROLES_SCHEMA
from web.server.util.util import EMAIL_PATTERN, as_dictionary from web.server.errors import NotificationError # TODO(vedant) - Allow users to change their Dashboard Slugs via the Settings # Modal. Once this is done, we will restrict the ability to use whitespaces # in dashboard slugs. DASHBOARD_SLUG_PATTERN = r'(^[a-zA-Z0-9-_ ]*)$' # The schema for the `selections` object that is POSTed to the `visualization` API. This # essentially represents the selections generated by the Query Tool. We are not specifying # A detailed schema for this object as it is not really necessary at this stage since the # selections object is in flux and if the structure ever changes without this schema definition # being altered, any APIs that reference this schema will reject the client request since it # will not match the defined schema. SELECTIONS_SCHEMA = fields.Custom( fields.Any(), description='The selections object containing the query to be added to a dashboard.', ) # The schema for the `query_result_spec` object that is POSTed to the # `visualization` API. This represents the frontend configuration for a query # result (e.g. custom fields, filters, settings, etc.) We are not specifying a # detailed schema for this object yet, but we should. QUERY_RESULT_SPEC_SCHEMA = fields.Custom( fields.Any(), description='The query result spec object describing a query result and its configuration to be added to a dashboard.', ) ADD_QUERY_TO_DASHBOARD_SCHEMA = fields.Object( properties={ 'activeViewType': fields.String( description='The currently active view type when the query was saved',
Success, ) from web.server.potion.signals import after_user_role_change # The schema for an invite user request INVITE_OBJECT_FIELDS = { 'name': fields.String( description='The invited user\'s name.', pattern=INTERNATIONALIZED_ALPHANUMERIC_AND_DELIMITER, ), 'email': USERNAME_SCHEMA, } INVITE_OBJECT_SCHEMA = fields.Custom(fields.Object(INVITE_OBJECT_FIELDS), converter=lambda value: Invitee(**value)) class UserResource(PrincipalResource): '''The potion class for performing CRUD operations on the `User` class. ''' class Meta(object): title = 'Users API' description = ( 'The API through which CRUD operations can be performed on User(s).' ) model = User natural_key = 'username' permissions = {'read': 'yes'} # Read Permissions are the defaults as defined in