I am using SAP Commerce Cloud 19.05 in my B2C project.We have certain custom itemtypes like:
XYZCompanyProduct(extends Product)
XYZLaptopProduct(extends XYZCompanyProduct)
XYZMobileProduct(extends Product)
Now in the explorer tree, we have three nodes corresponding to the above nodes. We want certain users to have access to XYZLaptopProduct and Orders and Consignment nodes and other nodes to be hidden when the user logs in.
We tried several ways of achieving this like:
We created a Backoffice role for the laptop product users and a corresponding group to it(say laptopGroups).
In the groups section of laptopGroups we gave it access to backofficeproductmanagergroup and the above role.
The above step caused it to have access to multiple other product nodes, as well(like XYZCompanyProduct and XYZMobileProduct) which is unwanted behaviour.
I tried removing the nodes by:
<context component="explorer-tree" merge-by="principal" principal="laptopGroups">
<!-- other nodes... -->
<navigation-node id="Restricted" merge-mode="remove"/>
</context>
These steps seem to be all failing. Where am I going wrong? Should I approach this in a different way?
To achieve your objective, you can use permission in backoffice framework. Using that, you can restrict specific ItemType or it's specific attributes access to any particular user/groups in backoffice.
You can achieve the same by 2 ways :
From backoffice directly --> backoffice > go to user groups >> click on key symbol (permissions) >> select your item type >> give required permissions
Or using impex (sample as below)
$START_USERRIGHTS; ; ; ; ; ; ; ; ;
Type ; UID ; Target ; read ; change ; create ; remove ;
UserGruop ; laptopGroups ; XYZLaptopProduct ; + ; - ; - ; - ;
$END_USERRIGHTS; ; ; ; ;
Refer following for more details on above 2 approaches :
https://help.sap.com/viewer/5c9ea0c629214e42b727bf08800d8dfa/1905/en-US/8c282d8686691014b54f95ffbf322a6b.html
https://help.sap.com/viewer/d0224eca81e249cb821f2cdf45a82ace/1905/en-US/8be36d438669101497eeed8ff7b712fe.html
Hope it helps!
Related
Original question:
I want to limit the number of users from a particular domain that can register into my Gitlab instance. I noticed that I could set a "user cap", but it wasn't specific to a domain.
For example:
I want to limit the number of users registered from these domains. 20 users from testdomain1.com and 30 users from testdomain2.com are allowed to sign up. So, if there are already 20 users registered sucessfully from testdomain1.com, new user from testdomain1.com will not be allowed to sign up.
What should I do for it?
2021.11.18 Edited:
I added a validate to the User model:
# gitlab/app/models/user.rb
class User < ApplicationRecord
# ...
validate :email_domain, :ensure_user_email_count
# ...
def email_domain
email_domain = /\#.*?$/.match(email)[0]
email_domain
end
def ensure_user_email_count
# select count(*) from users where email like '%#test.com';
if User.where("email LIKE ?", "%#{email_domain}" ).count >= 30
errors.add(email_domain, _('already has 30 registered email.'))
end
end
end
This validate can set "user cap = 30" for each domain but it's still not able to set a "User cap" for a particular domain.
Since the related issue post did not get any response yet. I'm tring to implement it by myself. And it seems like that I need to extend the UI of the Admin Settings page and add some related tables to database to set different "user cap" for different email domain.
The GitLab user cap seems to be per GitLab instance.
So if both your domains are reference the same GitLab instance, you would have only one user cap possible.
But if each of your domain redirects to one autonomous GitLab instance (per domain), then you should be able to set user cap per domain.
The OP Ann Lin has created the issue 345557 to follow that feature request.
TRhe OP reports:
A particular table is needed to store the caps.
But I don’t have enough time now to modify the UI so I found a simple way to do this:
The Allowed domains for sign-ups which called domain_allowlist in database is a text:
gitlabhq_production=# \d application_settings
...
domain_allowlist | text | | |
...
gitlabhq_production=# select domain_allowlist from >application_settings;
domain_allowlist
-------------------
--- +
- testdomain1.com+
- testdomain2.com+
(1 row)
I can modify the testdomain1.com to testdomain1.com#30 to store the user cap and use Regex to get the number 30.
I will modify the UI and add the database table later. And I’ll create a pull request on Gitlab when I’m done.
SAP Commerce 1811
Impex -
INSERT_UPDATE Calendar ; code[unique=true] ; name[lang=en] ; year ; active[default=false]
; 10001 ; 2021 Public Holiday ; 2021 ; true
; 10002 ; 2021 Holiday ; 2021 ; true
I have created one validate interceptor which will make sure that only one calendar can be active at a time. It means we can't make more than two Calendar active for the same year.
final CalendarModel cal = calendarService.getActiveCalendar(calendar.getYear());
if (cal != null && !cal.equals(calendar))
{
throw new InterceptorException(
String.format("Only one Calendar can be active at a time for year %s", calendar.getYear()));
}
In this Impex, I am inserting two Calendars with active=true, and expecting to give validation exception for one of the entry.
Since in this use case, one entry depends on other, it won't work in case of multi threading (because order will not defined).
If Max. threads is set to more than 1, and I run the impex, validation is not working. I tried importing this impex with 1 thread, then only validation is working.
Is there any way to solve this issue ?
You cannot solve this problem with an Interceptor. Interceptors are simply not threadsafe. They are not built to validate if an object already exists or not. The interceptors are meant to validate the object that will be saved, independently of other objects.
This is a problem that needs to be fixed on the database, not in your code. You need to add an SQL constraint (more specifically an SQL CHECK Constraint) on the table of your CalendarModel. This constraint should validate your requirement on 1 active item per year.
How to write that constraint will depend on your database. To add it, you can either add the constraint directly in the database, though an update system might remove it again (I did not validate this, but it occurs for indexes). Alternativly, you can run an alter table statement during initialization to create the constraint.
With this constraint, a database error will be thrown on the illegal item. This will be visibile in the result when running the impex
I have 1 database and inside there are maybe say 3 tables, users, user_profile, user_stats. I would like to ask is it possible to have these 3 tables in 1 model file? If user were to visit User A profile, it will show all the User A records from these 3 tables. I can't find it anywhere whether is it possible in CI4. Hope someone here can guide me on this. Thanks in advance guys!
You will need to override the find method. I have done it for findAll and haven't tried for find a method. So you may need to improvise on the following logic. There are three places where based on the condition we are fetching the rows, one check for the array, another for a single row, and last is the default one. So you will need to modify this behavior.
Replace :
$row = $builder
With your custom builder query such as following:
$row = $builder->select("users.*");
$builder->join('user_profile', 'user_profile.id = users.id','inner');
$builder->join('user_stats', 'user_stats.id = users.id','inner');
->whereIn($this->table . '.' . $this->primaryKey, $id)
->get();
You will need to replace the last query according to the conditions in find method and also instead of mentioning users explicitly you should use $this->table and similar for the primary key instead of id, you should use $this->primaryKey.
Does anybody knows how create an impex in order to add a new row in media item in hybris without creating or using MediaContainer?
Do you mean mime type? if yes, you create media like below
$catalog-id=testCatalog
$catalog-version=Online
$catalogversion=catalogversion(catalog(id),version)[unique=true,default=$catalog-id:$catalog-version]
INSERT_UPDATE Media ; $catalogversion[unique=true] ; code[unique=true] ; realfilename ; #media[translator=de.hybris.platform.impex.jalo.media.MediaDataTranslator] ; mime[default='text/plain']
; ; siteMapMedia ; sitemap.vm ; jar:de.hybris.platform.acceleratorservices.constants.AcceleratorServicesConstants&/acceleratorservices/test/sitemap.vm ;
You shod try something like this:
INSERT_UPDATE Media;code[unique=true];#media[translator=de.hybris.platform.impex.jalo.media.MediaDataTranslator];mime[default='image/jpeg'];$catalogVersion
;imgName;$siteResource/96Wx96H/imgName.jpg;;
Does somebody know how I can import all members of one group into another in GitLab, rather than doing it manually one by one?
The only native feature which comes close is in lib/tasks/gitlab/bulk_add_permission.rake, which is mentioned in "User management"
# omnibus-gitlab
sudo gitlab-rake gitlab:import:all_users_to_all_groups
# installation from source
bundle exec rake gitlab:import:all_users_to_all_groups RAILS_ENV=production
You could take that as a model to develop our own task.
I am not aware of such a feature. But you can script it with the API. We use it here to add all users to one single group (all users to all groups is not feasible for our case).
Helpful documentation: http://doc.gitlab.com/ce/api/README.html, http://doc.gitlab.com/ce/api/users.html and http://doc.gitlab.com/ce/api/groups.html
There is also a respond to another question that might be helpful and lists also various modules for various programming languages: Is there a way to add users automatically into gitlab?
I was looking for a solution to Assign all Gitlab users to one particular group.
Here's the solution:
Create this file:
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/finder_import.rake
With this content:
namespace :gitlab do namespace :finder do
desc "GitLab | Add all users to group Colaboradores (admin users are added as owners)"
task importall: :environment do |t, args|
user_ids = User.where(admin: false).pluck(:id)
admin_ids = User.where(admin: true).pluck(:id)
groups = Group.where(name: "Colaboradores")
puts "Importing #{user_ids.size} users into #{groups.size} groups"
puts "Importing #{admin_ids.size} admins into #{groups.size} groups"
groups.each do |group|
puts "Importing into #{group.name}"
group.add_users(user_ids, GroupMember::DEVELOPER)
group.add_users(admin_ids, GroupMember::OWNER)
end
end
end end
Run this command:
gitlab-rake gitlab:finder:importall