コード例 #1
0
    def post(self, request):
        try:
            company = Company.objects.filter(
                guid=get_user(request.data["session"]))[0]
            # Here we filter the employees only within one company:
            employee = Employee.objects.filter(guid=request.data["employee"],
                                               company=company)

            if not employee:
                return validate_response(
                    {
                        "status": "error",
                        "reason": "noEmployee"
                    }, res_schema)

            else:
                employee = employee[0]

            employee.delete()

            company.employees_count -= 1
            company.save()
            return validate_response({"status": "ok"}, res_schema)
        except:
            return server_error_response()
コード例 #2
0
    def post(self, request):
        try:
            telegram_id = request.data["telegram_id"]
            company_guid = request.data["company"]

            manager = Employee.objects.filter(telegram_id=telegram_id, company__guid=company_guid)[0]
            subordinates = ManagerToWorker.objects.filter(manager=manager, worker__company=manager.company)

            data = {"users": []}

            for subordinate in subordinates:
                last_data = HealthData.objects.filter(employee=subordinate.worker)

                if not last_data:
                    data["users"].append({"initials": subordinate.worker.initials,
                                          "last_temp": None
                                          })
                else:
                    last_data = last_data.last()
                    data["users"].append({
                        "initials": subordinate.worker.initials,
                        "last_temp": last_data.temperature,
                        "date": last_data.date.timestamp()
                    })

            return get_success_response(data)
        except:
            return server_error_response()
コード例 #3
0
    def post(self, request):
        try:
            company_name = request.data["companyName"]
            password = request.data["password"]
            company = Company.objects.filter(name=company_name)

            if not company:
                return validate_response({
                    "status": "error",
                    "reason": "wrongCompanyName"
                }, res_schema)

            else:
                company = company[0]

            if company.password != password:
                return validate_response({
                    "status": "error",
                    "reason": "wrongPassword"
                }, res_schema)

            else:
                return validate_response({
                    "status": "ok",
                    "session": authorize_user(company.guid)
                }, res_schema)
        except Exception as er:
            print(er)
            return server_error_response()
コード例 #4
0
    def post(self, request):
        try:
            data = request.data
            password = data["password"]
            username = data["username"]
            secret_key = data["secret_key"]

            if secret_key != config["Admin"]["secret_key"]:
                return server_error_response()

            admin = User.objects.create_superuser(password=password,
                                                  username=username)
            admin.save()
            return get_success_response()
        except Exception as er:
            print(er)
            return server_error_response()
    def post(self, request):
        try:
            employee_data = request.data["employeeData"]

            initials = employee_data["initials"]
            tg_username = employee_data["tgUsername"]
            role = employee_data["role"]

            company = Company.objects.filter(guid=get_user(request.data["session"]))[0]

            # Here we check the uniqueness of the tg_username only within one company:
            if Employee.objects.filter(tg_username=tg_username, company=company):
                return validate_response({
                    "status": "error",
                    "reason": "usedTgAccount"
                }, res_schema)

            manager = None

            if role == "worker":
                attached_manager_guid = employee_data["attachedManager"]

                if attached_manager_guid is not None:
                    manager = Employee.objects.filter(guid=attached_manager_guid, company=company)

                    if not manager:
                        return validate_response({
                            "status": "error",
                            "reason": "noEmployee"
                        }, res_schema)

                    manager = manager[0]

                    if manager.role != "manager":
                        return validate_response({
                            "status": "error",
                            "reason": "wrongRoles"
                        }, res_schema)

            employee = Employee.objects.create(
                guid=str(uuid.uuid4()),
                initials=initials,
                tg_username=tg_username,
                role=role,
                company=company)

            send_new_employees([employee])
            if role == "worker" and manager is not None:
                ManagerToWorker.objects.create(manager=manager, worker=employee)

            company.employees_count += 1
            company.save()
            return validate_response({"status": "ok"}, res_schema)
        except Exception as err:
            print(err)
            return server_error_response()
コード例 #6
0
    def post(self, request):
        try:
            session = request.data["session"]
            company = Company.objects.filter(guid=get_user(session))[0]

            return validate_response({
                "companyName": company.name,
                "licenceActive": get_active_licence_pack(company) is not None
            }, res_schema)
        except:
            return server_error_response()
コード例 #7
0
    def post(self, request):
        try:
            company = Company.objects.filter(guid=get_user(request.data["session"]))[0]

            # Here we get the employees from the database:
            employees = []

            if request.data.get("employees") is None:
                employees = Employee.objects.filter(company=company)

            else:
                employees_guids = request.data["employees"]

                for employee_guid in employees_guids:
                    employee = Employee.objects.filter(guid=employee_guid, company=company)

                    if employee:
                        employees.append(employee[0])

            # Here we process the database output and pack the employees data:
            employees_data = []

            for employee in employees:
                attached_manager = None

                if employee.role == "worker":
                    manager = ManagerToWorker.objects.filter(worker=employee)

                    if manager:
                        attached_manager = manager[0].manager.guid

                employee_data = {
                    "initials": employee.initials,
                    "tgUsername": employee.tg_username,
                    "role": employee.role
                }

                if employee.role == "worker":
                    employee_data.update({"attachedManager": attached_manager})

                employees_data.append({
                    "employee": employee.guid,
                    "employeeData": employee_data
                })

            return validate_response({
                "status": "ok",
                "employeesData": employees_data
            }, res_schema)
        except:
            return server_error_response()
    def post(self, request):
        try:
            data = request.data

            employees = data["employees"]

            guid_list = list(employees.keys())

            employees_bd = Employee.objects.filter(guid__in=guid_list)

            for employee in employees_bd:
                employee.telegram_id = employees[employee.guid]
                employee.save()
            return get_success_response()
        except:
            return server_error_response()
    def post(self, request):
        try:
            company = Company.objects.filter(guid=get_user(request.data["session"]))[0]
            employees_guids = Employee.objects.filter(company=company)

            employees = []

            for employee in employees_guids:
                employees.append(employee.guid)

            return validate_response({
                "status": "ok",
                "employees": employees
            }, res_schema)
        except:
            return server_error_response()
コード例 #10
0
    def post(self, request):
        try:
            telegram_id = request.data["telegram_id"]
            users = Employee.objects.filter(telegram_id=telegram_id)

            companies = []

            for user in users:
                companies.append({
                    "guid": user.company.guid,
                    "name": user.company.name
                })

            return get_success_response({"companies": companies})
        except:
            return server_error_response()
コード例 #11
0
    def post(self, request):
        try:
            token = request.data["token"]
            company_name = request.data["companyName"]
            password = request.data["password"]

            admin_panel_licence = AdminPanelLicence.objects.filter(token=token)

            if not admin_panel_licence:
                return validate_response(
                    {
                        "status": "error",
                        "reason": "invalidToken"
                    }, res_schema)

            else:
                admin_panel_licence = admin_panel_licence[0]

            if admin_panel_licence.activated:
                return validate_response(
                    {
                        "status": "error",
                        "reason": "activatedToken"
                    }, res_schema)

            if Company.objects.filter(name=company_name):
                return validate_response(
                    {
                        "status": "error",
                        "reason": "usedCompanyName"
                    }, res_schema)

            company = Company.objects.create(guid=uuid.uuid4(),
                                             name=company_name,
                                             password=password,
                                             employees_count=0)

            admin_panel_licence.company = company
            admin_panel_licence.activated = True
            admin_panel_licence.save()

            return validate_response({"status": "ok"}, res_schema)
        except:
            return server_error_response()
コード例 #12
0
    def post(self, request):
        # Todo:Настроить почтовый сервис https://tproger.ru/translations/email-functionality-django/
        try:
            data = request.data

            message = data["message"]
            rating = data["rating"]
            email = data["email"]
            name = data["name"]

            send_mail(
                'Subject here',
                'Here is the message.',
                '*****@*****.**',
                ['*****@*****.**'],
                fail_silently=False,
            )
        except Exception as err:
            print(err)
            return server_error_response()
コード例 #13
0
    def post(self, request):
        try:
            session = request.data["session"]
            company = Company.objects.filter(guid=get_user(session))[0]
            licences_packs = Licence.objects.filter(company=company)

            active_licence_pack = get_active_licence_pack(company)

            if active_licence_pack:
                active_licence_pack = active_licence_pack.guid

            licence_packs_data = []

            for licence_pack in licences_packs:
                licence_pack_guid = licence_pack.guid
                start_time = unix_time_millis(
                    datetime.datetime.utcfromtimestamp(
                        licence_pack.start_time.timestamp()))
                end_time = unix_time_millis(
                    datetime.datetime.utcfromtimestamp(
                        licence_pack.end_time.timestamp()))
                licence_packs_data.append({
                    "licencePack":
                    str(licence_pack_guid),
                    "startTime":
                    start_time,
                    "endTime":
                    end_time,
                    "employeesCount":
                    licence_pack.employees_count
                })

            return validate_response(
                {
                    "serverTime": unix_time_millis(datetime.datetime.utcnow()),
                    "activeLicencePack": active_licence_pack,
                    "licencePacksData": licence_packs_data
                }, res_schema)
        except:
            return server_error_response()
    def post(self, request):
        try:
            telegram_id = request.data["telegram_id"]
            company_guid = request.data["company"]

            manager = Employee.objects.filter(telegram_id=telegram_id,
                                              company__guid=company_guid)[0]
            subordinates = ManagerToWorker.objects.filter(
                manager=manager, worker__company=manager.company)

            data = {"users": []}
            for subordinate in subordinates:
                data["users"].append({
                    "initials":
                    subordinate.worker.initials,
                    "tg_username":
                    subordinate.worker.tg_username,
                    "telegram_id":
                    subordinate.worker.telegram_id
                })

            return get_success_response(data)
        except:
            return server_error_response()
 def get(self, request):
     try:
         synchronize_data()
         return get_success_response()
     except:
         return server_error_response()
コード例 #16
0
 def post(self, request):
     try:
         company = Company.objects.filter(guid=get_user(request.data["session"]))[0]
         return validate_response({"employeesCount": company.employees_count}, res_schema)
     except:
         return server_error_response()
    def post(self, request):
        try:
            employee_guid = request.data["employee"]
            employee_data = request.data["employeeData"]
            initials = employee_data["initials"]
            tg_username = employee_data["tgUsername"]
            role = employee_data["role"]

            company = Company.objects.filter(guid=get_user(request.data["session"]))[0]
            # Here we filter the employees only within one company:
            employee = Employee.objects.filter(guid=employee_guid, company=company)

            if not employee:
                return validate_response({
                    "status": "error",
                    "reason": "noEmployee"
                }, res_schema)

            else:
                employee = employee[0]

            employee_with_same_tg_username = \
                Employee.objects.filter(tg_username=tg_username, company=company)

            if employee_with_same_tg_username and employee_with_same_tg_username[0].guid != employee.guid:
                return validate_response({
                    "status": "error",
                    "reason": "usedTgAccount"
                }, res_schema)

            # processing change employee role: manager -> worker
            if employee.role == "manager" and role == "worker":
                attached_workers = ManagerToWorker.objects.filter(manager=employee)

                if attached_workers:
                    for worker in attached_workers:
                        worker.delete()

            # processing change employee role: worker -> manager
            if employee.role == "worker" and role == "manager":
                attached_managers = ManagerToWorker.objects.filter(worker=employee)

                # Here we expect only one manager.
                if attached_managers:
                    for manager in attached_managers:
                        manager.delete()

            employee.initials = initials
            employee.tg_username = tg_username
            employee.role = role

            # reattaching worker to the manager:
            if role == "worker":
                attached_manager_guid = employee_data["attachedManager"]
                manager = None

                if attached_manager_guid is not None:
                    manager = Employee.objects.filter(guid=attached_manager_guid)

                    if not manager:
                        return validate_response({
                            "status": "error",
                            "reason": "noEmployee"
                        }, res_schema)

                    manager = manager[0]

                    if manager.role != "manager":
                        return validate_response({
                            "status": "error",
                            "reason": "wrongRoles"
                        }, res_schema)

                attached_managers = ManagerToWorker.objects.filter(worker=employee)

                for attached_manager in attached_managers:
                    attached_manager.delete()

                if manager is not None:
                    ManagerToWorker.objects.create(manager=manager, worker=employee)

            employee.save()
            send_new_employees([employee])
            return validate_response({"status": "ok"}, res_schema)
        except:
            return server_error_response()