コード例 #1
0
    def insert(self):

        lawrence = User()
        lawrence.display_name = "Lawrence L."
        lawrence.email = "*****@*****.**"
        lawrence.password = "******"
        lawrence.profile = Profile.TRUSTED_USER
        lawrence.config = UserConfig()
        self._session.add(lawrence)

        bob = User()
        bob.display_name = "Bob i."
        bob.username = "******"
        bob.email = "*****@*****.**"
        bob.password = "******"
        bob.profile = Profile.TRUSTED_USER
        bob.config = UserConfig()
        self._session.add(bob)

        reader = User()
        reader.display_name = "John Reader"
        reader.email = "*****@*****.**"
        reader.password = "******"
        reader.profile = Profile.USER
        reader.config = UserConfig()
        self._session.add(reader)
コード例 #2
0
    def test__unit__CandidateWorkspaceRoleChecker__err_no_role_in_workspace(
            self, session):

        current_user = User(user_id=2, email="*****@*****.**")
        current_user.profile = Profile.TRUSTED_USER
        candidate_workspace = Workspace(workspace_id=3, owner=current_user)
        session.add(current_user)
        session.add(candidate_workspace)
        session.flush()
        transaction.commit()

        class FakeBaseFakeTracimContext(BaseFakeTracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def candidate_workspace(self):
                return candidate_workspace

        assert CandidateWorkspaceRoleChecker(0).check(
            FakeBaseFakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            CandidateWorkspaceRoleChecker(1).check(FakeBaseFakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            CandidateWorkspaceRoleChecker(2).check(FakeBaseFakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            CandidateWorkspaceRoleChecker(3).check(FakeBaseFakeTracimContext())
        with pytest.raises(InsufficientUserRoleInWorkspace):
            CandidateWorkspaceRoleChecker(4).check(FakeBaseFakeTracimContext())
コード例 #3
0
    def test__unit__CandidateWorkspaceRoleChecker__ok__nominal_case(
            self, session):

        current_user = User(user_id=2, email="*****@*****.**")
        current_user.profile = Profile.TRUSTED_USER
        candidate_workspace = Workspace(workspace_id=3, owner=current_user)
        role = UserRoleInWorkspace(user_id=2, workspace_id=3, role=2)
        session.add(current_user)
        session.add(candidate_workspace)
        session.add(role)
        session.flush()
        transaction.commit()

        class FakeBaseFakeTracimContext(BaseFakeTracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def candidate_workspace(self):
                return candidate_workspace

        assert CandidateWorkspaceRoleChecker(1).check(
            FakeBaseFakeTracimContext())
        assert CandidateWorkspaceRoleChecker(2).check(
            FakeBaseFakeTracimContext())
コード例 #4
0
 def insert(self):
     u = User()
     u.display_name = "Global manager"
     u.email = "*****@*****.**"
     u.password = "******"
     u.profile = Profile.ADMIN
     self._session.add(u)
コード例 #5
0
ファイル: user.py プロジェクト: PhilippeAccorsi/tracim
    def create_minimal_user(self,
                            email,
                            profile: typing.Optional[Profile] = None,
                            save_now=False) -> User:
        """Previous create_user method"""
        lowercase_email = email.lower() if email is not None else None
        validator = TracimValidator()
        validator.add_validator("email", lowercase_email, user_email_validator)
        validator.validate_all()
        self._check_email(lowercase_email)
        user = User()
        user.email = lowercase_email
        # TODO - G.M - 2018-11-29 - Check if this default_value can be
        # incorrect according to user_public_name_validator
        user.display_name = email.split("@")[0]
        user.created = datetime.datetime.utcnow()
        if not profile:
            profile = Profile.get_profile_from_slug(
                self._config.USER__DEFAULT_PROFILE)
        user.profile = profile

        self._session.add(user)

        if save_now:
            self._session.flush()

        return user
コード例 #6
0
 def insert(self):
     u = User()
     u.display_name = "Global manager"
     u.username = "******"
     u.email = "*****@*****.**"
     u.password = "******"
     u.profile = Profile.ADMIN
     u.config = UserConfig()
     self._session.add(u)
コード例 #7
0
    def test__unit__ContentTypeCreationChecker__err__implicit_insufficent_role_in_workspace(
            self, session):

        current_user = User(user_id=2, email="*****@*****.**")
        current_user.profile = Profile.TRUSTED_USER
        current_workspace = Workspace(workspace_id=3, owner=current_user)
        candidate_content_type = TracimContentType(
            slug="test",
            fa_icon="",
            label="Test",
            creation_label="Test",
            available_statuses=[],
            minimal_role_content_creation=WorkspaceRoles.CONTENT_MANAGER,
        )
        role = UserRoleInWorkspace(user_id=2,
                                   workspace_id=3,
                                   role=WorkspaceRoles.CONTRIBUTOR.level)
        session.add(current_user)
        session.add(current_workspace)
        session.add(role)
        session.flush()
        transaction.commit()

        class FakeContentTypeList(object):
            def get_one_by_slug(self, slug=str) -> TracimContentType:
                return candidate_content_type

        class FakeBaseFakeTracimContext(BaseFakeTracimContext):
            @property
            def current_user(self):
                return current_user

            @property
            def current_workspace(self):
                return current_workspace

            @property
            def candidate_content_type(self):
                return candidate_content_type

        with pytest.raises(InsufficientUserRoleInWorkspace):
            assert ContentTypeCreationChecker(FakeContentTypeList()).check(
                FakeBaseFakeTracimContext())
コード例 #8
0
ファイル: user.py プロジェクト: inkhey/tracim
    def create_minimal_user(
        self,
        email: typing.Optional[str] = None,
        username: typing.Optional[str] = None,
        profile: typing.Optional[Profile] = None,
        save_now=False,
    ) -> User:
        """Previous create_user method"""
        if not email:
            if self._config.EMAIL__REQUIRED:
                raise EmailRequired("Email is required to create an user")
            if not username:
                raise EmailOrUsernameRequired(
                    "Email or username is required to create an user")
        lowercase_email = email.lower() if email is not None else None
        validator = TracimValidator()
        validator.add_validator("email", lowercase_email, user_email_validator)
        validator.validate_all()
        if lowercase_email is not None:
            self._check_email(lowercase_email)
        if username is not None:
            self.check_username(username)
        user = User()
        user.email = lowercase_email
        user.username = username
        # TODO - G.M - 2018-11-29 - Check if this default_value can be
        # incorrect according to user_public_name_validator
        user.display_name = email.split("@")[0] if email else username
        user.created = datetime.datetime.utcnow()
        if not profile:
            profile = Profile.get_profile_from_slug(
                self._config.USER__DEFAULT_PROFILE)
        user.profile = profile

        if save_now:
            self.save(user)

        return user
コード例 #9
0
ファイル: user.py プロジェクト: inkhey/tracim
    def update(
        self,
        user: User,
        name: str = None,
        email: str = None,
        password: str = None,
        timezone: str = None,
        lang: str = None,
        auth_type: AuthType = None,
        profile: typing.Optional[Profile] = None,
        allowed_space: typing.Optional[int] = None,
        username: str = None,
        do_save=True,
    ) -> User:
        """Update given user instance with given parameters"""
        validator = TracimValidator()
        validator.add_validator("name", name, user_public_name_validator)
        validator.add_validator("password", password, user_password_validator)
        validator.add_validator("email", email, user_email_validator)
        validator.add_validator("username", name, user_username_validator)
        validator.add_validator("timezone", timezone, user_timezone_validator)
        validator.add_validator("lang", lang, user_lang_validator)
        validator.validate_all()

        if name is not None:
            user.display_name = name

        if auth_type is not None:
            if (auth_type not in [AuthType.UNKNOWN, AuthType.REMOTE]
                    and auth_type not in self._config.AUTH_TYPES):
                raise UserAuthTypeDisabled(
                    'Can\'t update user "{}" auth_type with unavailable value "{}".'
                    .format(user.login, auth_type))
            user.auth_type = auth_type

        if email is not None:
            lowercase_email = email.lower()
            if lowercase_email != user.email:
                self._check_email_modification_allowed(user)
                self._check_email(lowercase_email)
                user.email = lowercase_email

        if username is not None:
            if username != user.username:
                self.check_username(username)
                user.username = username

        if password is not None:
            self._check_password_modification_allowed(user)
            user.password = password

        if timezone is not None:
            user.timezone = timezone

        if lang is not None:
            user.lang = lang

        if profile is not None:
            if self._user and self._user == user:
                raise UserCantChangeIsOwnProfile(
                    "User {} can't change is own profile".format(user.user_id))
            user.profile = profile

        if allowed_space is not None:
            user.allowed_space = allowed_space

        if do_save:
            self.save(user)

        return user