Organisasi intranet (otomatisasi produksi TI). Bagian 1 - Pengguna dan Email


Cepat atau lambat, setiap perusahaan IT (outsourcing atau toko bahan makanan) memiliki keinginan untuk mengatur ruangnya sendiri di mana Anda dapat menyimpan informasi tentang proyek, karyawan, dan penjualan. Pertahankan korespondensi kerja dan diskusikan tugas / strategi / dokumen. Paling sering, perusahaan semacam itu mulai mengkodekan semuanya sendiri atau melihat sesuatu untuk Bitrix24, dll. Dalam seri artikel ini saya akan berbicara tentang artikel kamisepeda- pengalaman dalam otomatisasi proses. Seperti yang diharapkan, hampir semua self-host, opensource dan coba lakukan hampir tanpa coding


Disclamer


Serangkaian artikel menggambarkan contoh implementasi infrastruktur, penulis tidak mendesak untuk mengulang dan tidak berpura-pura "benar" dalam pendekatan tersebut. Beberapa bagian dari sistem yang dijelaskan sebenarnya dan berhasil digunakan di beberapa organisasi selama 3 tahun. Penulis dengan senang hati menerima saran untuk meningkatkan sistem atau menyarankan solusi alternatif. Tolong jangan membuat diskusi seperti "siapa yang butuh ini" dan "kruk apa", siapa yang tidak butuh, jangan baca dan jangan campur dengan komentator

Jadi, apa yang diinginkan oleh perusahaan outsourcing rata-rata dari sistem yang serupa:


  1. Database karyawan dengan distribusi hak akses ke informasi
  2. GIT , , 1
  3. Chat-Server (Messenger ) 1
  4. , 1
  5. / HR
  6. -
  7. ( )

– . - , - .



, " GIT ?", " ?" . .


, . , , LDAP . LDAP , , . 3 LDAP OpenLDAP , , , .


, RESTapi. , LDAP .


, OpenSource ERP/CRM (Odoo, Axellor ), OpenProject . , . - PHP, .


, EspoCRM. , " " , . , , CMS, .


.


, Espo :


  1. HR
  2. -
  3. (CRM :))


PHP .


:



CRM. .
( , ).


-> -> User ().
. ( ) :



, Skype, Telegram, VK, Facebook . (, ), , , , , ( ).


, .
/ .


-> -> -> .


- :



, , . , .
, - " " .


EspoCRM, . , - , - .

, . .



— . , . , — email.


— self-hosted . , , . .. 1000 , web- RESTapi. , — .


.


, , espo.


, , Node-RED.


Node-RED


, , .
Node-RED , : , - . , , , , .


Node-RED . , , API ..


API Token.


"-" - " URL ".



, .


. Directory API, , , :



( )


- :



, . , .
https://oauth.yandex.ru/authorize?response_type=token&client_id=<ID>,



.


, , Node-RED.



global.set('YaConnectToken', 'AgAAAA......');
return msg;

global.get() .


Inject , Flow 1. , . ,


Node-RED + .


  • Flow : inject, function, http request

  • inject, , , JSON
    {
    "userName":"testuser",
    "firstName":"Test",
    "lastName":"User",
    "emailAddress":"testuser@mydomain.ru",
    "dob":"1988-01-01",
    "gender":"male",
    "passwordConfirm":"12345678Eiru",
    "isActive":true
    }

.


  • function :
    const TOKEN = global.get('YaConnectToken');
    const user = msg.payload; //       
    const body = {
    'department_id': 1, // ID   .,    1
    'is_admin': false, //    
    'nickname': user.userName,
    'name': {
    'first': user.firstName,
    'last': user.lastName
    },
    'birthday': user.dob, // 'YYYY-MM-DD',
    'gender': user.gender, //'male/female/null'
    'password': user.passwordConfirm,
    'is_dismissed': user.isActive,
    'position': user.title // 
    }
    return {
    headers: {
    'Authorization': 'OAuth ' + TOKEN,
    //'X-Org-ID': 1234 //       .  : https://wilix.org/l/wlwrtj
    },
    payload: body
    }

.


  • http request, POST, url https://api.directory.yandex.net/v6/users/


  • Deploy inject ( JSON inject function )


  • , http request , msg statusCode 200 201 payload:



! !


EspoCRM Node-RED


( CRM) Node-RED .
PHP, .
UserSaved.php EspoCRM custom/Espo/Custom/Hooks/User :


<?php
namespace Espo\Custom\Hooks\User;

use Espo\ORM\Entity;

class UserSaved extends \Espo\Core\Hooks\Base {
  public function afterSave(Entity $entity, array $options = []) {
    $entityValues = $entity->getValues();
    unset($entityValues['password']);
    $entityValues['isNew'] = $entity->isNew();
    $data = array(
      'event' => 'afterSave',
      'entity' => $entityValues,
    );
    $this->_callRed($data);
  }

  public function afterRemove(Entity $entity, array $options = []) {
    $entityValues = $entity->getValues();
    unset($entityValues['password']);
    $data = array(
      'event' => 'afterRemove',
      'entity' => $entityValues
    );
    $this->_callRed($data);
  }

  private function _callRed($data) {
    $data_string = json_encode($data);
    $ch = curl_init('__NODE_RED_ENDPOINT__');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string))
    );
    $response = curl_exec($ch);
    curl_close($ch);
    return $response;
  }
}

Hook . ( ) , - // Espo, Node-RED. , Node-RED EspoCRM ( ) , localhost .
NODE_RED_ENDPOINT — .


  • Node-RED : http in, http response, debug
  • http in

  • UserSaved.php NODE_RED_ENDPOINT _NODE_RED/user-event
  • Deploy Node-RED
  • EspoCRM ->
  • EspoCRM, ""
  • , Node-RED ( ) JSON
    {
    id: "5e430b3c59783cb41"
    name: "User Test"
    deleted: false
    isAdmin: false
    userName: "usertest"
    type: "regular"
    password: "GVhrB......"
    passwordConfirm: "oRM1..."
    authMethod: null
    salutationName: "Mr."
    firstName: "User"
    lastName: "Test"
    isActive: true
    isPortalUser: false
    isSuperAdmin: false
    title: "Frontend developer"
    emailAddress: null
    phoneNumber: null
    sendAccessInfo: false
    gender: "Male"
    createdAt: "2020-02-11 20:14:52"
    modifiedAt: "2020-02-11 20:14:52"
    dob: null
    inn: null
    emailAddressIsOptedOut: null
    phoneNumberIsOptedOut: null
    emailAddressData: array[0]
    phoneNumberData: array[0]
    defaultTeamId: null
    defaultTeamName: null
    teamsIds: array[0]
    teamsNames: object
    teamsColumns: object
    rolesIds: array[0]
    rolesNames: object
    portalsIds: array[0]
    portalsNames: object
    portalRolesIds: array[0]
    portalRolesNames: object
    createdById: "1"
    isNew: true
    }

isNew ,
passwordConfirm , .
, .


:


  • ( 2 )
  • function 2
    const user = msg.payload.entity;
    if (msg.payload.event != 'afterSave') { //      ,   
    return null
    }
  • Deploy
  • Espo ( )
  • , Node-RED JSON
  • :)


Node-RED. , . Flow, . ( ).


EspoCRM , , , .


:


  • self-hosted GIT ( GitLab :))
  • self-hosted Slack
  • HR .
  • .

FAQ:
T: Mengapa Node-RED sama sekali, jika permintaan dapat dibuat langsung dari PHP ke Yandex?
A: Memiliki integrasi di sisi Node-RED, kita dapat mengubah konfigurasi, menambahkan layanan dan kait baru, ke perubahan pengguna, tanpa pengkodean tambahan (tidak termasuk fungsi kecil pada Node-RED). Proses penggelaran pembaruan turun ke satu tombol.

Source: https://habr.com/ru/post/undefined/


All Articles