예제 #1
0
    def begin_speech(self):
        """
        Let the user speak.

        Set the weight to None and the time to now. If anyone is still
        speaking, end his speech.
        """
        try:
            current_speaker = (
                Speaker.objects.filter(
                    list_of_speakers=self.list_of_speakers, end_time=None
                )
                .exclude(begin_time=None)
                .get()
            )
        except Speaker.DoesNotExist:
            pass
        else:
            # Do not send an autoupdate for the countdown and the list_of_speakers. This is done
            # by saving the list_of_speakers and countdown later.
            current_speaker.end_speech(skip_autoupdate=True)
        self.weight = None
        self.begin_time = timezone.now()
        self.save()  # Here, the list_of_speakers is saved and causes an autoupdate.
        if config["agenda_couple_countdown_and_speakers"]:
            countdown, created = Countdown.objects.get_or_create(
                pk=1,
                defaults={
                    "default_time": config["projector_default_countdown"],
                    "title": "Default countdown",
                    "countdown_time": config["projector_default_countdown"],
                },
            )
            if created:
                restart_id_sequence("core_countdown")
            else:
                countdown.control(action="reset", skip_autoupdate=True)
            countdown.control(action="start", skip_autoupdate=True)

            inform_changed_data(
                countdown
            )  # Here, the autoupdate for the countdown is triggered.
예제 #2
0
    def handle(self, *args, **options):
        userid = None
        try:
            userid = int(options["userid"])
        except (ValueError, TypeError):
            pass

        user_data = {
            "first_name": options["first_name"],
            "last_name": options["last_name"],
            "default_password": options["password"],
            "email": options["email"] or "",
        }
        username = options["username"]
        if (userid is None or not User.objects.filter(pk=userid).exists()
            ) and not User.objects.filter(username=username).exists():
            if userid is not None:
                user_data["pk"] = userid

            user = User.objects.create_user(
                username,
                options["password"],
                **user_data,
            )
            if options["groups_id"].isdigit():
                user.groups.add(int(options["groups_id"]))
                inform_changed_data(user)

            if userid is not None:
                restart_id_sequence("users_user")

            self.stdout.write(self.style.SUCCESS(f"Created user {username}."))
        else:
            self.stdout.write(
                self.style.NOTICE(
                    f"A user with id {userid} or username {username} already exists."
                ))
예제 #3
0
def create_builtin_groups_and_admin(**kwargs):
    """
    Creates the builtin groups: Default, Delegates, Staff and Committees.

    Creates the builtin user: admin.
    """
    # Check whether there are groups in the database.
    if Group.objects.exists():
        # Do completely nothing if there are already some groups in the database.
        return

    permission_strings = (
        "agenda.can_be_speaker",
        "agenda.can_manage",
        "agenda.can_manage_list_of_speakers",
        "agenda.can_see",
        "agenda.can_see_internal_items",
        "agenda.can_see_list_of_speakers",
        "assignments.can_manage",
        "assignments.can_nominate_other",
        "assignments.can_nominate_self",
        "assignments.can_see",
        "core.can_manage_config",
        "core.can_manage_logos_and_fonts",
        "core.can_manage_projector",
        "core.can_manage_tags",
        "core.can_see_frontpage",
        "core.can_see_history",
        "core.can_see_projector",
        "core.can_see_autopilot",
        "mediafiles.can_manage",
        "mediafiles.can_see",
        "motions.can_create",
        "motions.can_create_amendments",
        "motions.can_manage",
        "motions.can_manage_metadata",
        "motions.can_see",
        "motions.can_see_internal",
        "motions.can_support",
        "users.can_change_password",
        "users.can_manage",
        "users.can_see_extra_data",
        "users.can_see_name",
        "chat.can_manage",
    )
    permission_query = Q()
    permission_dict = {}

    # Load all permissions
    for permission_string in permission_strings:
        app_label, codename = permission_string.split(".")
        query_part = Q(content_type__app_label=app_label) & Q(
            codename=codename)
        permission_query = permission_query | query_part
    for permission in Permission.objects.select_related("content_type").filter(
            permission_query):
        permission_string = ".".join(
            (permission.content_type.app_label, permission.codename))
        permission_dict[permission_string] = permission

    # Default (pk 1 == GROUP_DEFAULT_PK)
    base_permissions = (
        permission_dict["agenda.can_see"],
        permission_dict["agenda.can_see_internal_items"],
        permission_dict["agenda.can_see_list_of_speakers"],
        permission_dict["assignments.can_see"],
        permission_dict["core.can_see_frontpage"],
        permission_dict["core.can_see_projector"],
        permission_dict["mediafiles.can_see"],
        permission_dict["motions.can_see"],
        permission_dict["users.can_see_name"],
        permission_dict["users.can_change_password"],
    )
    group_default = Group(pk=GROUP_DEFAULT_PK, name="Default")
    group_default.save(skip_autoupdate=True)
    group_default.permissions.add(*base_permissions)

    # Admin (pk 2 == GROUP_ADMIN_PK)
    group_admin = Group(pk=GROUP_ADMIN_PK, name="Admin")
    group_admin.save(skip_autoupdate=True)

    # Delegates (pk 3)
    delegates_permissions = (
        permission_dict["agenda.can_see"],
        permission_dict["agenda.can_see_internal_items"],
        permission_dict["agenda.can_be_speaker"],
        permission_dict["agenda.can_see_list_of_speakers"],
        permission_dict["assignments.can_see"],
        permission_dict["assignments.can_nominate_other"],
        permission_dict["assignments.can_nominate_self"],
        permission_dict["core.can_see_frontpage"],
        permission_dict["core.can_see_projector"],
        permission_dict["core.can_see_autopilot"],
        permission_dict["mediafiles.can_see"],
        permission_dict["motions.can_see"],
        permission_dict["motions.can_create"],
        permission_dict["motions.can_create_amendments"],
        permission_dict["motions.can_support"],
        permission_dict["users.can_see_name"],
        permission_dict["users.can_change_password"],
    )
    group_delegates = Group(pk=3, name="Delegates")
    group_delegates.save(skip_autoupdate=True)
    group_delegates.permissions.add(*delegates_permissions)

    # Staff (pk 4)
    staff_permissions = (
        permission_dict["agenda.can_see"],
        permission_dict["agenda.can_see_internal_items"],
        permission_dict["agenda.can_be_speaker"],
        permission_dict["agenda.can_manage"],
        permission_dict["agenda.can_see_list_of_speakers"],
        permission_dict["agenda.can_manage_list_of_speakers"],
        permission_dict["assignments.can_see"],
        permission_dict["assignments.can_manage"],
        permission_dict["assignments.can_nominate_other"],
        permission_dict["assignments.can_nominate_self"],
        permission_dict["core.can_see_frontpage"],
        permission_dict["core.can_see_history"],
        permission_dict["core.can_see_projector"],
        permission_dict["core.can_manage_projector"],
        permission_dict["core.can_manage_tags"],
        permission_dict["mediafiles.can_see"],
        permission_dict["mediafiles.can_manage"],
        permission_dict["motions.can_see"],
        permission_dict["motions.can_see_internal"],
        permission_dict["motions.can_create"],
        permission_dict["motions.can_create_amendments"],
        permission_dict["motions.can_manage"],
        permission_dict["motions.can_manage_metadata"],
        permission_dict["users.can_see_name"],
        permission_dict["users.can_manage"],
        permission_dict["users.can_see_extra_data"],
        permission_dict["users.can_change_password"],
    )
    group_staff = Group(pk=4, name="Staff")
    group_staff.save(skip_autoupdate=True)
    group_staff.permissions.add(*staff_permissions)

    # Committees (pk 5)
    committees_permissions = (
        permission_dict["agenda.can_see"],
        permission_dict["agenda.can_see_internal_items"],
        permission_dict["agenda.can_see_list_of_speakers"],
        permission_dict["assignments.can_see"],
        permission_dict["core.can_see_frontpage"],
        permission_dict["core.can_see_projector"],
        permission_dict["mediafiles.can_see"],
        permission_dict["motions.can_see"],
        permission_dict["motions.can_create"],
        permission_dict["motions.can_create_amendments"],
        permission_dict["motions.can_support"],
        permission_dict["users.can_see_name"],
        permission_dict["users.can_change_password"],
    )
    group_committee = Group(pk=5, name="Committees")
    group_committee.save(skip_autoupdate=True)
    group_committee.permissions.add(*committees_permissions)

    # Create or reset admin user
    User.objects.create_or_reset_admin_user(skip_autoupdate=True)

    # After each group was created, the permissions (many to many fields) where
    # added to the group. But we do not have to update the cache by calling
    # inform_changed_data() because the cache is updated on server start.

    # For postgres: After inserting the groups by id, the id sequence needs to be restarted.
    restart_id_sequence("auth_group")
예제 #4
0
def postgres_restart_auth_group_id_sequence(*args, **kwargs):
    restart_id_sequence("auth_group")