power automate – Adding newly create site to “Site Permissions” section ( XXX/_layouts/15/user.aspx )

Hope you are all doing well.

I managed to use Power Automate to create SP groups and add users to them using the HTTP request action.

The problem i have is the newly created groups are created at the “root” (in People and Groups section) level but not in the site in the “Site Permissions” section so user that i add to the group still do not have access to the site.

I created a flow that adds the group(s) to “site Pages” , “Site assets” and to the specific libraries but they don’t have access to the site itself since the groups are not in “Site Permissions”.

Does anyone know how to add a newly created group to “Site Permissions” ?

Thanks a lot in advance !!

c# – Replace string based on multiple rules, don’t replace same section twice

Given a 2-column CSV dictionary file that contains translation of certain words, this c# code needs to replace the first occurrence of a word in the dictionary.

  • Once a segment of string has been replaced, it cannot be matched or overwritten by a new dictionary word.

This sounded like a fairly simple task but the code I came up with runs horribly slow and I’m looking for ways to improve it.

All the offending code is in the TestReplace function, I build up a hashset that keeps track of what character Ids in the string have been touched. When you apply a rule that changes the lenght of the string, all the character ids switch around so they have to be recalculated and I believe it costs a lot of performance. Wish there was a simpler way to do this !

Here is a super simple case of what the code tries to do :

Dictionary file:

hello >>> hi

hi >>> goodbye

Input: hello, world!

First rule is applied so string becomes -> hi, world. The word hi is now locked.

Second rule is applied but the string does not become goodbye, world since this part is locked.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace stringReplacer
{
    class Program
    {
        public static Dictionary<string, string> ReplacementRules = new Dictionary<string, string>()
        {
            {"John","Freddy" },
            {"John walks","Freddy runs" },
            {"brown dog","gray dog" },
            {"dog","cat" },
            {"- not -", "(not)" },
            {"(","" },
            {")","" },
            {"whenever",  "sometimes, when"},
            {"raining", "snowing" },
            {"his", "many" }
        };

        static void Main(string() args)
        {
            string Input = "John walks his brown dog whenever it's - not - raining";
            string ExpectedOutput = "Freddy walks many gray dog sometimes, when it's (not) snowing";

            string TestReplaceOutput = TestReplace(Input, ReplacementRules);
            ValidateReplacement("TestReplace", TestReplaceOutput, ExpectedOutput);
        }
        public static string TestReplace(string input, Dictionary<string, string> ReplacementRules)
        {
            HashSet<int> LockedStringSegment = new HashSet<int>();

            foreach (var rule in ReplacementRules)
            {
                string from = Regex.Escape(rule.Key);
                string to = rule.Value;
                var match = Regex.Match(input, from);
                if (match.Success)
                {
                    List<int> AffectedCharacterPositions = Enumerable.Range(match.Index, match.Length).ToList();

                    if (!AffectedCharacterPositions.Any(x => LockedStringSegment.Contains(x)))
                    {
                        input = Regex.Replace(input, from, to);
                        int LengthDelta = to.Length - rule.Key.Length;

                        LockedStringSegment
                            .Where(x => x > match.Index + rule.Key.Length).OrderByDescending(x => x).ToList()
                            .ForEach(x =>
                            {
                                //We shuffle the locked character's place depending on the replacement delta.
                                LockedStringSegment.Remove(x);
                                LockedStringSegment.Add(x + LengthDelta);
                            });

                        //Add all the new locked character's position to the hashset.
                        Enumerable.Range(match.Index, to.Length).ToList().ForEach(x => LockedStringSegment.Add(x));

                    }
                }
            }

            return input;
        }
        public static void ValidateReplacement(string MethodName, string Actual, string Expected)
        {
            Console.Write($"{MethodName} : ");

            if (Expected != Actual)
                Console.WriteLine("String replacement doesn't work");
            else
                Console.WriteLine("It works");

            Console.WriteLine($"Expected : {Expected}");
            Console.WriteLine($"Actual   : {Actual} nn");

        }

    }

}

magento2.4 – Custom address attribute is causing error in admin customer address section

I am adding two custom address attribute as mobile and country_code.

InstallData.php as below,

<?php

namespace OcraCustomerMobileSetup;

use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoEavModelConfig;
use MagentoCustomerModelCustomer;
use MagentoCustomerSetupCustomerSetupFactory;
use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;

class InstallData implements InstallDataInterface
{
    private $eavSetupFactory;
    private $attributeSetFactory;
    private $customerSetupFactory;

    public function __construct(
        AttributeSetFactory $attributeSetFactory,
        CustomerSetupFactory $customerSetupFactory,
        EavSetupFactory $eavSetupFactory,
        Config $eavConfig
        )
    {
        $this->customerSetupFactory = $customerSetupFactory;
        $this->attributeSetFactory = $attributeSetFactory;
        $this->eavSetupFactory = $eavSetupFactory;
        $this->eavConfig       = $eavConfig;
    }

    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $customerSetup = $this->customerSetupFactory->create(('setup' => $setup));

        $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
        $attributeSetId = $customerEntity->getDefaultAttributeSetId();
        $attributeSet = $this->attributeSetFactory->create();
        $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

        $customerSetup->addAttribute(
            MagentoCustomerModelCustomer::ENTITY,
            'country_code',
            (
                'type'         => 'varchar',
                'label'        => 'Country Code',
                'input'        => 'text',
                'required'     => false,
                'visible'      => true,
                'user_defined' => true,
                'position'     => 1000,
                'system'       => 0,
            )
        );

        $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'country_code')
        ->addData((
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => (
                    'adminhtml_customer',
                    'adminhtml_checkout',
                    'customer_account_create',
                    'customer_account_edit',
                    'checkout_register',
                )
        ));
        $attribute->save();

        $customerSetup->addAttribute(
            MagentoCustomerModelCustomer::ENTITY,
            'mobile',
            (
                'type'         => 'varchar',
                'label'        => 'Mobile',
                'input'        => 'text',
                'required'     => false,
                'visible'      => true,
                'user_defined' => true,
                'position'     => 1001,
                'system'       => 0,
            )
        );

        $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'mobile')
        ->addData((
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => (
                    'adminhtml_customer',
                    'adminhtml_checkout',
                    'customer_account_create',
                    'customer_account_edit',
                    'checkout_register',
                )
        ));
        $attribute->save();


        $customerSetup->addAttribute(
            MagentoCustomerModelCustomer::ENTITY,
            'is_mobile_verified',
            (
                'type'         => 'int',
                'label'        => 'Is Mobile Verified?',
                'input'        => 'select',
                'source' => 'OcraCustomerMobileModelConfigSourceOption',
                'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
                'required'     => false,
                'visible'      => true,
                'user_defined' => true,
                'position'     => 1002,
                'system'       => 0,
                'default' => 2
            )
        );

        $attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'is_mobile_verified')
        ->addData((
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => (
                    'adminhtml_customer',
                    'adminhtml_checkout',
                    'customer_account_create',
                    'customer_account_edit',
                    'checkout_register',
                )
        ));
        $attribute->save();

        $customerSetup->addAttribute('customer_address', 'country_code', (
               'label' => 'Country Code',
               'input' => 'varchar',
               'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
               'source' => '',
               'required' => false,
               'position' => 90,
               'visible' => true,
               'system' => false,
               'is_used_in_grid' => false,
               'is_visible_in_grid' => false,
               'is_filterable_in_grid' => false,
               'is_searchable_in_grid' => false,
               'frontend_input' => 'hidden',
               'backend' => ''
           ));

        $attribute=$customerSetup->getEavConfig()
                ->getAttribute('customer_address','country_code')                                  
                ->addData((
                        'attribute_set_id' => $attributeSetId,
                        'attribute_group_id' => $attributeGroupId,
                        'used_in_forms' => (
                           'adminhtml_customer_address',
                           'adminhtml_customer',
                           'customer_address_edit',
                           'customer_register_address',
                           'customer_address',
                        )
                ));
        $attribute->save();

        $customerSetup->addAttribute('customer_address', 'mobile', (
               'label' => 'Mobile',
               'input' => 'varchar',
               'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
               'source' => '',
               'required' => false,
               'position' => 90,
               'visible' => true,
               'system' => false,
               'is_used_in_grid' => false,
               'is_visible_in_grid' => false,
               'is_filterable_in_grid' => false,
               'is_searchable_in_grid' => false,
               'frontend_input' => 'hidden',
               'backend' => ''
           ));

        $attribute=$customerSetup->getEavConfig()
                ->getAttribute('customer_address','mobile')                                  
                ->addData((
                        'attribute_set_id' => $attributeSetId,
                        'attribute_group_id' => $attributeGroupId,
                        'used_in_forms' => (
                           'adminhtml_customer_address',
                           'adminhtml_customer',
                           'customer_address_edit',
                           'customer_register_address',
                           'customer_address',
                        )
                ));
        $attribute->save();
    }
}

After this, if I open New Address from admin customer edit screen or new customer screen, address form is not loading instead error is created in debug.log and system.log as below,

(2021-01-13 11:55:16) main.CRITICAL: TypeError: Argument 2 passed to
MagentoFrameworkViewElementUiComponentFactory::argumentsResolver()
must be of the type array, null given, called in
D:wamp_newwwwmagento_2_4vendormagentoframeworkViewElementUiComponentFactory.php
on line 235 and defined in
D:wamp_newwwwmagento_2_4vendormagentoframeworkViewElementUiComponentFactory.php:183
Stack trace:
#0 D:wamp_newwwwmagento_2_4vendormagentoframeworkViewElementUiComponentFactory.php(235):
MagentoFrameworkViewElementUiComponentFactory->argumentsResolver(‘country_code’,
NULL)
#1 D:wamp_newwwwmagento_2_4vendormagentomodule-uiComponentFormField.php(85):
MagentoFrameworkViewElementUiComponentFactory->create(‘country_code’,
‘varchar’, Array)
#2 D:wamp_newwwwmagento_2_4vendormagentoframeworkViewLayoutGeneratorUiComponent.php(164):

Error on the screen as below,

enter image description here

Where is it going wrong.

c++ – Allow one thread to execute section while others wait and resume

I have a requirement that is summarized below.

void update()
{
  |   |   |   |
  |   |   |   |
  |   |   |   |
 |  |  |  |
  =============
      meat           <--- Only one thread must execute here, the rest should skip it.
  =============
  |   |   |   |  <--- Other threads wait here until the "first" thread is done w/ "meat"
  |   |   |   |
  |   |   |   |
  |/  |/  |/  |/
}

From an outsider perspective, “meat” should be executed just once (by the first thread that encounters it)

This post is similar but differs in that it also requires other threads to execute the meat code block one at a time.

// testExecutive.cpp
#include <atomic>
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <thread>

struct Target {
  int nhits = 0;
  inline void hit() { ++nhits; }
};

struct Executive {
  Executive() = delete;
  Executive(int _Id, Target &_Tgt) : m_Id(_Id), m_Ready(false), m_Tgt(_Tgt) {}
  void update() {
    { // only one thread can execute this
      std::scoped_lock<std::mutex> lk(m_Mtx);
      // std::cout << "++Acquired lk " << m_Id << " | tid: " <<
      // std::this_thread::get_id() << "++n";
      if (!m_Ready.load()) {
        // std::cout << "==Updating" << m_Id << " | tid: " <<
        // std::this_thread::get_id() << "==n";
        m_Ready.store(true);
        m_Tgt.hit();
        m_Cv.notify_all();
      }
      // std::cout << "++Releasing lk " << m_Id << " | tid: " <<
      // std::this_thread::get_id() << "++n";
    }

    // the rest should wait here
    std::mutex wait_mtx;
    std::unique_lock<std::mutex> lk(wait_mtx);
    m_Cv.wait(lk, (&)() -> bool { return m_Ready.load(); });
  }
  inline void reset() { m_Ready.store(false); }

private:
  int m_Id;
  Target &m_Tgt;
  std::condition_variable m_Cv;
  std::mutex m_Mtx;
  std::atomic_bool m_Ready;
};

int main(int argc, char *argv()) {
  int n(2);
  if (argc >= 2) {
    n = atoi(argv(1));
  }
  Target tgt;
  Executive e(1, tgt);
  auto updFn = (&e)() { e.update(); };

  // update same executive from 3 threads. Repeat n times.
  int i(n);
  while (i > 0) {
    e.reset();
    {
      std::thread t1(updFn), t2(updFn), t3(updFn);
      t1.join();
      t2.join();
      t3.join();
    }
    --i;
  }
  std::cout << (n == tgt.nhits ? "(OK)" : "(ERR)") << " Updates: " << n << " | "
            << "Hits: " << tgt.nhits << "n";
  return 0;
}

I setup a simple method to verify that exactly one out of three threads executes the desired code. The method hit() is called in Executive::Update. Compile and test like so.

jaswant@HAL9000:~$ g++ testExecutive.cpp -lpthread --std=c++17
jaswant@HAL9000:~$ ./a.out 2
(OK) Updates: 2 | Hits: 2
jaswant@HAL9000:~$ ./a.out 100
(OK) Updates: 100 | Hits: 100
jaswant@HAL9000:~$ ./a.out 2
(OK) Updates: 2 | Hits: 2
jaswant@HAL9000:~$ ./a.out 4
(OK) Updates: 4 | Hits: 4
jaswant@HAL9000:~$ ./a.out 8
(OK) Updates: 8 | Hits: 8
jaswant@HAL9000:~$ ./a.out 16
(OK) Updates: 16 | Hits: 16
jaswant@HAL9000:~$ ./a.out 256
(OK) Updates: 256 | Hits: 256
jaswant@HAL9000:~$ ./a.out 1024
(OK) Updates: 1024 | Hits: 1024
jaswant@HAL9000:~$ ./a.out 8192
(OK) Updates: 8192 | Hits: 8192
jaswant@HAL9000:~$ ./a.out 100000
(OK) Updates: 100000 | Hits: 100000

So, it works. Can anyone please point out bad usage of mutex/condition variables/locks and perhaps a way to do this w/o an atomic variable in the predicate?

Exim: Can there be multiple authenticators in the “Begin Authenticators” Section, one for each smtp relay?

My exim relays all its incoming email to third-party smtp relays. They use smtp authentication (username/password).

It seems I can only define ONE username/password in the begin authenticators section of the Exim config. I want to route certain email through one relay (with its own username/password auth), and other email through a second relay (its username/password auth is different than the first).

Here’s much of my config. The begin routers relays domains in the +local_domains list to smtp-relay-1 and the rest relays to smtp-relay-2.

begin routers

my_domains_relay:
  debug_print = "R: my_domains_relay for $local_part@$domain"
  driver = manualroute
  domains = +local_domains
  transport = remote_smtp_smarthost
  route_list = * "<+ smtp-relay-1.example.com:465"
  host_find_failed = defer
  no_more

smart_host_relay:
  debug_print = "R: smart_host_relay for $local_part@$domain"
  driver = manualroute
  transport = remote_smtp_smarthost
  route_list = * "<+ smtp-relay-2.example.net:465"
  host_find_failed = defer
  no_more

begin transports

remote_smtp_smarthost:
  debug_print = "T: remote_smtp_smarthost for $local_part@$domain"
  driver = smtp
  port = 465
  hosts_require_tls = *
  hosts_require_auth = *
  protocol = smtps

begin authenticators

login:
  driver = plaintext
  public_name = PLAIN
  client_send = ^my-username^top-secret-password

What I want is to define separate username/password auth in the begin authenticators section, and assign each to a single router/transport. Right now, the username/password auth is global and used for all relays.

8 – How to update the layout builder’s section component configuration?

How to update a component in the node’s layout builder? I have used the following code.

$node = DrupalnodeEntityNode::load($nid);
$layout = $node->get('layout_builder__layout');
$sections = $layout->getSections();
foreach ($sections as $key => $section) {
      $components = $section->getComponents();
      foreach ($components as $component) {
        if ($component instanceof SectionComponent && $component->getPluginId() === 'myplugin_id') {
          $configurations = $component->get('configuration');
          $configurations('label_display') = "0";
          $component->setConfiguration($configurations);
        }
      }
}

But now I don’t know how to update the section and layout of the node.

Because $section->setComponent($component) is a protected method.

views – Drupal rendered Section 1 overlay section 2

I have the following html code and css style:

html code:

<section class="intro" id="section1" data-speed="5" data-type="background" style="background-position: 50% 0px;">
    <div class="overlay">
    <div class="headline">
      {{ page.headline }}
    </div>
  </div>
    <a href="#" id="goto-section2" class="arrow-down">Get started</a>
</section>
<main role="main" class="main">
  <div class="layout-content">
    <section id="section2" class="section">
      <div class="container">
          {{ page.before_content }}
      </div>
    </section>
  </div>
</main>

#section1 {
  display: block;
  height: 100%;
  width: 100%;
}

.intro {
  height: 100%;
  width: 100%;
  background: url(../img/background.jpg) no-repeat center top fixed;
  -webkit-background-size: 100% auto;
  -moz-background-size: 100% auto;
  -o-background-size: 100% auto;
  background-size: 100% auto;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  display: block;
  background-attachment: fixed;
}

css style:

.overlay {
  display: block;
  position: absolute;
  top: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
}

.section {
  position: relative;
  padding: 40px 0 40px 0;
  display: block;
}

.headline {
  display: block;
  position: absolute;
  text-align: center;
  top: 48%;
  width: 100%;
  z-index: 111;
}

.headline div.flexslider {
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  display: block;
  text-align: center;
  width: 100%;
}

.flexslider {
  margin: 0 0 60px;
  background: #FFFFFF;
  border: 4px solid #FFFFFF;
  position: relative;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  -o-border-radius: 4px;
  border-radius: 4px;
  zoom: 1;
}

.arrow-down {
  position: absolute;
  bottom: 0;
  left: 50%;
  z-index: 11;
  height: 60px;
  width: 70px;
  margin-left: -35px;
  background: url(../img/bg-arrow-down.png) no-repeat 21px 26px rgba(0, 136, 204, 0.8);
  background-size: 28px 16px;
  text-indent: -9999px;
  display: block;
}

#section1 h2 {
  color: #FFFFFF;
  margin-bottom: 4px;
  font-size: 40px;
  line-height: 48px;
  text-transform: uppercase;
  font-weight: 700;
}

#section1 p {
  color: #FFFFFF;
}

Section 1 followed by section 2 rendered in pure html mock up, but in drupal (version 8.9.11) section 1 overlay section 2.

In Drupal section 1 contained in custom block and rendered by custom view. While section 2 is contained in custom block standard view.

Please help to get drupal rendering same as pure html.

theming – Drupal – Section 1 overlay section 2

I have the following html code and css style

<section class="intro" id="section1" data-speed="5" data-type="background" style="background-position: 50% 0px;">
    <div class="overlay">
    <div class="headline">
      {{ page.headline }}
    </div>
  </div>
    <a href="#" id="goto-section2" class="arrow-down">Get started</a>
</section>
<main role="main" class="main">
  <div class="layout-content">
    <section id="section2" class="section">
      <div class="container">
          {{ page.before_content }}
      </div>
    </section>
  </div>
</main>

#section1 {
  display: block;
  height: 100%;
  width: 100%;
}

.intro {
  height: 100%;
  width: 100%;
  background: url(../img/background.jpg) no-repeat center top fixed;
  -webkit-background-size: 100% auto;
  -moz-background-size: 100% auto;
  -o-background-size: 100% auto;
  background-size: 100% auto;
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  display: block;
  background-attachment: fixed;
}

.overlay {
  display: block;
  position: absolute;
  top: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.4);
}

.section {
  position: relative;
  padding: 40px 0 40px 0;
  display: block;
}

.headline {
  display: block;
  position: absolute;
  text-align: center;
  top: 48%;
  width: 100%;
  z-index: 111;
}

.headline div.flexslider {
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  display: block;
  text-align: center;
  width: 100%;
}

.flexslider {
  margin: 0 0 60px;
  background: #FFFFFF;
  border: 4px solid #FFFFFF;
  position: relative;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  -o-border-radius: 4px;
  border-radius: 4px;
  zoom: 1;
}

.arrow-down {
  position: absolute;
  bottom: 0;
  left: 50%;
  z-index: 11;
  height: 60px;
  width: 70px;
  margin-left: -35px;
  background: url(../img/bg-arrow-down.png) no-repeat 21px 26px rgba(0, 136, 204, 0.8);
  background-size: 28px 16px;
  text-indent: -9999px;
  display: block;
}

#section1 h2 {
  color: #FFFFFF;
  margin-bottom: 4px;
  font-size: 40px;
  line-height: 48px;
  text-transform: uppercase;
  font-weight: 700;
}

#section1 p {
  color: #FFFFFF;
}

Would expect section 1 followed by section 2, but section 1 overlay section 2.
Please help to get the expected