Example #1
0
    def create_number_of_shifts():
        shift_numbers = {'furnace': 2, 'leaching': 2, 'electrolysis': 2}

        for pl, num in shift_numbers.items():
            plant = Plant.objects.get(name=pl)
            Setting.of(obj=plant)['number_of_shifts'] = num

        # overriding number of shifts for furnace plant
        reports_furn = Journal.objects.get(plant__name='furnace',
                                           name='reports_furnace_area')
        Setting.of(obj=reports_furn)['number_of_shifts'] = 3
Example #2
0
 def get_time(shift):
     if request.user.has_perm(EDIT_CELLS):
         assignment_time = shift.end_time - timedelta(
             **Setting.of(shift)['shift_assignment_time'])
         assignment_time = assignment_time.isoformat()
         not_assignment_time = shift.end_time + timedelta(
             **Setting.of(shift)['shift_edition_time'])
         not_assignment_time = not_assignment_time.isoformat()
         return {
             "editing_mode_closing": assignment_time,
             "shift_closing": not_assignment_time
         }
     else:
         return None
Example #3
0
    def process(self):
        page = self.data['page']
        position = self.data['employee'].position
        allowed_positions = Setting.of(page)["allowed_positions"]
        if position in allowed_positions and \
           page.responsibles.filter(position=position).count() < allowed_positions[position]:
            return True

        if self.data['employee'] in page.responsibles.all():
            return True

        return True  # СОСТАВ СМЕН
Example #4
0
    def process(self):
        page = get_or_none(Shift, id=self.cleaned_data['shift_id'])

        if page and page.closed == True:
            Setting.of(page)['limited_access_employee_id_list'] = self.data[
                'emp_id_list']

            end_time = timezone.localtime() + timedelta(**self.data['time'])
            end_of_limited_access.apply_async((page.id, ), eta=end_time)

            for min in (60, 40, 20):
                send_deferred_message.apply_async(
                    ('warning',
                     f'До конца ограниченного доступа осталось {min} минут'),
                    eta=end_time - timedelta(minutes=min))

            return page
Example #5
0
    def process(self):
        page = self.data['page']
        employee = self.data['employee']
        assignment_time = Setting.of(page)['shift_assignment_time']

        if timezone.localtime() > page.end_time - timedelta(**assignment_time) and \
                employee not in page.responsibles.all():
            return False

        if timezone.localtime() > page.end_time + timedelta(hours=12):
            return False

        # shift = get_or_none(Shift, date=page.date, order=int(page.order-1), journal=page.journal)
        # if shift and not shift.ended and employee not in page.responsibles.all():
        #     return False

        return True
Example #6
0
def check_mode_permissions(employee: Employee, page, page_mode: str) -> bool:
    is_valid = False

    if page_mode == "validate":
        is_valid = employee.user.has_perm(VALIDATE_CELLS)

    if page_mode == "edit":
        if page.journal.type == "shift" or page.journal.type == "equipment":
            is_valid = not page.closed and employee.user.has_perm(
                EDIT_CELLS) and not page.ended
            if page.closed:
                limited_emp_id_list = Setting.of(
                    page)["limited_access_employee_id_list"]
                if limited_emp_id_list and employee.id in limited_emp_id_list:
                    is_valid = True

    if page_mode == "view":
        is_valid = employee.user.has_perm(VIEW_CELLS)
    return is_valid
Example #7
0
    def get_permissions(self, request, group):
        def get_time(shift):
            if request.user.has_perm(EDIT_CELLS):
                assignment_time = shift.end_time - timedelta(
                    **Setting.of(shift)['shift_assignment_time'])
                assignment_time = assignment_time.isoformat()
                not_assignment_time = shift.end_time + timedelta(
                    **Setting.of(shift)['shift_edition_time'])
                not_assignment_time = not_assignment_time.isoformat()
                return {
                    "editing_mode_closing": assignment_time,
                    "shift_closing": not_assignment_time
                }
            else:
                return None

        PERMISSIONS = []
        APP = 'all_journals_app'
        VALIDATE_CELLS = APP + ".validate_cells"
        EDIT_CELLS = APP + ".edit_cells"
        PLANT_PERM = APP + ".modify_{plant}"

        user = request.user

        if user.is_superuser:
            PERMISSIONS = ["edit", "validate"]

        if group.journal.type == 'shift':
            shift = group

            if user.has_perm(PLANT_PERM.format(plant=shift.journal.plant.name)
                             ) and user.has_perm(VALIDATE_CELLS):
                PERMISSIONS.append("validate")
                if user.has_perm(EDIT_CELLS):
                    PERMISSIONS.append("edit")

            else:
                if shift.closed:
                    limited_emp_id_list = Setting.of(
                        shift)["limited_access_employee_id_list"]
                    if limited_emp_id_list and user.id in limited_emp_id_list:
                        PERMISSIONS = ["edit"]

                elif services.CheckRole.execute({"employee": user.employee, "page": shift}) and \
                        services.CheckTime.execute({"employee": user.employee, "page": shift}):

                    if user.has_perm(
                            PLANT_PERM.format(plant=shift.journal.plant.name)
                    ) and user.has_perm(EDIT_CELLS):
                        PERMISSIONS.append("edit")

            res = {
                "permissions": PERMISSIONS,
                "time": get_time(shift),
            }
        else:
            res = {
                "permissions": ["edit"] if user.has_perm(
                    PLANT_PERM.format(plant=group.journal.plant.name)) else [],
                "time":
                None,
            }

        return res
Example #8
0
 def get_field_description(self, obj):
     return Setting.of(obj)['field_description']
Example #9
0
def end_of_limited_access(page_id):
    page = get_or_none(Shift, id=page_id)
    if page:
        Setting.of(page)['limited_access_employee_id_list'] = None
Example #10
0
 def cached_number_of_shifts(obj):
     return Setting.of(obj)['number_of_shifts']