<commit_before># -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013, 2014 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

"""Superdesk Users"""

from superdesk.metadata.item import BYLINE, SIGN_OFF
from superdesk.resource import Resource


class UsersResource(Resource):

    def __init__(self, endpoint_name, app, service, endpoint_schema=None):
        self.readonly = True if app.config.get('LDAP_SERVER', None) else False

        self.additional_lookup = {
            'url': r'regex("[\w]+")',
            'field': 'username'
        }

        self.schema = {
            'username': {
                'type': 'string',
                'unique': True,
                'required': True,
                'minlength': 1
            },
            'password': {
                'type': 'string',
                'minlength': 5
            },
            'password_changed_on': {
                'type': 'datetime',
                'nullable': True
            },
            'first_name': {
                'type': 'string',
                'readonly': self.readonly
            },
            'last_name': {
                'type': 'string',
                'readonly': self.readonly
            },
            'display_name': {
                'type': 'string'
            },
            'email': {
                'unique': True,
                'type': 'email',
                'required': True,
                'coerce': lambda s: s.lower()
            },
            'phone': {
                'type': 'string',
                'nullable': True
            },
            'job_title': {
                'type': 'string',
                'required': False,
            },
            'biography': {
                'type': 'string',
                'required': False,
                'nullable': True,
            },
            'facebook': {
                'type': 'string',
                'required': False,
                'nullable': True,
            },
            'instagram': {
                'type': 'string',
                'required': False,
                'nullable': True,
            },
            'twitter': {
                'type': 'string',
                'required': False,
                'nullable': True,
                'twitter': True,
            },
            'jid': {
                'unique': True,
                'type': 'string',
                'required': False,
            },
            'language': {
                'type': 'string',
                'nullable': True
            },
            'user_info': {
                'type': 'dict'
            },
            'picture_url': {
                'type': 'string',
                'nullable': True
            },
            'avatar': Resource.rel('upload', embeddable=True, nullable=True),
            'avatar_renditions': {'type': 'dict'},
            'role': Resource.rel('roles', True),
            'privileges': {'type': 'dict'},
            'workspace': {
                'type': 'dict'
            },
            'user_type': {
                'type': 'string',
                'allowed': ['user', 'administrator'],
                'default': 'user'
            },
            'is_support': {
                'type': 'boolean',
                'default': False
            },
            'is_author': {
                'type': 'boolean',
                'default': True
            },
            'is_active': {
                'type': 'boolean',
                'default': True
            },
            'is_enabled': {
                'type': 'boolean',
                'default': True
            },
            'needs_activation': {
                'type': 'boolean',
                'default': True
            },
            'desk': Resource.rel('desks'),  # Default desk of the user, which would be selected when logged-in.
            SIGN_OFF: {  # Used for putting a sign-off on the content when it's created/updated except kill
                'type': 'string',
                'required': False,
                'nullable': True,
                'regex': '^[a-zA-Z0-9]+$'
            },
            BYLINE: {
                'type': 'string',
                'required': False,
                'nullable': True
            },
            # list to hold invisible stages.
            # This field is updated under following scenario:
            # 1. stage visible flag is updated
            # 2. desk membership is modified
            # 3. new user is created
            'invisible_stages': {
                'type': 'list',<commit_msg>fixed: Unable to revert "default desk" to no selection<commit_after># -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013, 2014 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

"""Superdesk Users"""

from superdesk.metadata.item import BYLINE, SIGN_OFF
from superdesk.resource import Resource


class UsersResource(Resource):

    def __init__(self, endpoint_name, app, service, endpoint_schema=None):
        self.readonly = True if app.config.get('LDAP_SERVER', None) else False

        self.additional_lookup = {
            'url': r'regex("[\w]+")',
            'field': 'username'
        }

        self.schema = {
            'username': {
                'type': 'string',
                'unique': True,
                'required': True,
                'minlength': 1
            },
            'password': {
                'type': 'string',
                'minlength': 5
            },
            'password_changed_on': {
                'type': 'datetime',
                'nullable': True
            },
            'first_name': {
                'type': 'string',
                'readonly': self.readonly
            },
            'last_name': {
                'type': 'string',
                'readonly': self.readonly
            },
            'display_name': {
                'type': 'string'
            },
            'email': {
                'unique': True,
                'type': 'email',
                'required': True,
                'coerce': lambda s: s.lower()
            },
            'phone': {
                'type': 'string',
                'nullable': True
            },
            'job_title': {
                'type': 'string',
                'required': False,
            },
            'biography': {
                'type': 'string',
                'required': False,
                'nullable': True,
            },
            'facebook': {
                'type': 'string',
                'required': False,
                'nullable': True,
            },
            'instagram': {
                'type': 'string',
                'required': False,
                'nullable': True,
            },
            'twitter': {
                'type': 'string',
                'required': False,
                'nullable': True,
                'twitter': True,
            },
            'jid': {
                'unique': True,
                'type': 'string',
                'required': False,
            },
            'language': {
                'type': 'string',
                'nullable': True
            },
            'user_info': {
                'type': 'dict'
            },
            'picture_url': {
                'type': 'string',
                'nullable': True
            },
            'avatar': Resource.rel('upload', embeddable=True, nullable=True),
            'avatar_renditions': {'type': 'dict'},
            'role': Resource.rel('roles', True),
            'privileges': {'type': 'dict'},
            'workspace': {
                'type': 'dict'
            },
            'user_type': {
                'type': 'string',
                'allowed': ['user', 'administrator'],
                'default': 'user'
            },
            'is_support': {
                'type': 'boolean',
                'default': False
            },
            'is_author': {
                'type': 'boolean',
                'default': True
            },
            'is_active': {
                'type': 'boolean',
                'default': True
            },
            'is_enabled': {
                'type': 'boolean',
                'default': True
            },
            'needs_activation': {
                'type': 'boolean',
                'default': True
            },
            # Default desk of the user, which would be selected when logged-in.
            'desk': Resource.rel('desks', nullable=True),
            SIGN_OFF: {  # Used for putting a sign-off on the content when it's created/updated except kill
                'type': 'string',
                'required': False,
                'nullable': True,
                'regex': '^[a-zA-Z0-9]+$'
            },
            BYLINE: {
                'type': 'string',
                'required': False,
                'nullable': True
            },
            # list to hold invisible stages.
            # This field is updated under following scenario:
            # 1. stage visible flag is updated
            # 2. desk membership is modified
            # 3. new user is created
            'invisible_stages': {
                'type': 'list',
{'fraction_non_alphanumeric': 0.13261798103969163, 'fraction_numerical': 0.003333680591728305, 'mean_word_length': 1.1140717903545474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6056591', 'n_tokens_mistral': 2516, 'n_tokens_neox': 2365, 'n_words': 598}