I have a working Groovy script provided by app vendor. I need help modify it a little so it will send an email to our DL with the list of accounts it process.
I don't have any knowledge of Groovy.
Can some one please assist? Groovy provided below:
package examples
{{{{{
import com.atlassian.confluence.security.login.LoginManager
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.user.GroupManager
import com.atlassian.confluence.user.ConfluenceUser
import com.onresolve.scriptrunner.parameters.annotation.GroupPicker
import com.onresolve.scriptrunner.parameters.annotation.NumberInput
#NumberInput(label = 'Maximum users', description = 'The maximum number of users to allow in Confluence')
Integer maximumUsers
#GroupPicker(label = 'User group', description = 'The group of users to check (e.g. "confluence-users")')
Group selectedUserGroup
#GroupPicker(label = 'Deactivated user group', description = 'The group to add the deactivated users to (e.g. "deactivated-users"')
Group selectedDeactivatedGroup
def groupManager = ComponentLocator.getComponent(GroupManager)
def loginManager = ComponentLocator.getComponent(LoginManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)
// Set defaults in case the fields are not filled out
maximumUsers = maximumUsers ?: 500
def userGroup = selectedUserGroup ? groupManager.getGroup(selectedUserGroup.name) : groupManager.getGroup('confluence-users')
def deactivatedGroup = selectedDeactivatedGroup ? groupManager.getGroup(selectedDeactivatedGroup.name) : groupManager.getGroup('deactivated-users') ?: groupManager.createGroup('deactivated-users')
// Get all users from the selected user group
def users = userAccessor.getMembers(userGroup).asList()
// For the users found in the selected group, sort the users by last login date
Map<ConfluenceUser, Date> userWithLoginDate =
users.collectEntries {
[(it): (loginManager.getLoginInfo(it)?.lastSuccessfulLoginDate)]
}.sort { it -> it.value }
// Get all user keys
def sortedUsers = userWithLoginDate*.key
// Deactivate user accounts and add them to the deactivated group if the user list size is more than the allowed amount
if (sortedUsers.size() > maximumUsers) {
def deactivated = sortedUsers.subList(0, sortedUsers.size() - maximumUsers)
deactivated.each { user ->
groupManager.removeMembership(userGroup, user)
groupManager.addMembership(deactivatedGroup, user)
userAccessor.deactivateUser(user)
}
}
//Good to Know
//
// If you want this listener to run when a new user is added, you must also add the UserCreateEvent in the 'Events' field.
// When you add this as a listener, you need to provide a value for the 'Maximum users' field to define the maximum number of users you want to allow on your instance.
// The script uses the 'User group' field to search for users to deactivate. You will likely want to select the 'confluence-users' group, but you are free to select use any group.
// You will need to create a group for the deactivated users to be added to and then select that group for the 'Deactivated user group' field.
}}}}}
This Groovy script will be inserted into Script Runner which is installed in Atlassian Confluence.
I have the groovy and **I need help with it working to parse users that have not logged in for 90days and up.
Then send an email with the list.**
Script will auto disable those accounts.
I have no knowledge of Groovy/java.
Related
I'm trying to create calendar events in sheets using Google App Script (I'm very new to this). The sheet contains details of the event (date, time, event title, and guest list) as well as the calendar ID (this is a training calendar). I want to make it simple for the end-user to fill in the information on the sheet, click 'schedule now' and the script run and send the events out to all email addresses mentioned in the guest list.
Here is an example of the sheet:
Here is a copy of the code (I found this on the Google Developer website and tried to adapt it to add guests but haven't been able to get it working and really not sure where to go with this. Ideally, I'd like the guest list to come from the sheet and not be written into the code as an option.
function scheduleTraining() {
var spreadsheet = SpreadsheetApp.getActiveSheet();
var calendarId = spreadsheet.getRange("C3").getValue();
var eventCal = CalendarApp.getCalendarById(calendarId);
Logger.log(eventCal)
var signups = spreadsheet.getRange("A5:C20").getValues();
for (x=0; x<signups.length; x++) {
var shift = signups[x];
var startTime = shift[0]
var endTime = shift[1]
var title = shift[2]
eventCal.createEvent(title, startTime, endTime, {
location: 'remote',
description: 'snacks provided',
})
}
}
function onOpen(e) {
SpreadsheetApp.getUi()
.createMenu('Schedule Training')
.addItem('Schedule Now', 'scheduleTraining')
.addToUi();
}
If anyone can help with this or has any ideas on how to do this better, I'm all ears!
Thanks!
Issues:
The dates in your spreadsheet file are strings/texts. You can verify that if you do =isDate(A7). If the latter returns FALSE then you don't have a valid date object. If you see the official documentation you need to pass date objects and not date texts.
Another remark I have is that your range is "A5:C20" but you should start from A7. Row 5 and 6 don't contain the information required, according to your screenshot.
Question based on your comment:
how I can include inviting the guests when it's run
Again according to the documentation, you can add guests using the advanced parameters options and in particular guests:
eventCal.createEvent(title, startTime, endTime, {
location: 'remote',
description: 'snacks provided',
guests: 'test1#gmail.com,test2#gmail.com'
})
guests is a type of string that contains a comma-separated list of email addresses
that should be added as guests.
I have a table of role which contains role name and its priority..
id role_name priority
1 SuperAdmin 1
2 User 2
... so on
The condition is that whenever user does any create or update operation on any entity it has to follow the hierarchy like SuperAdmin can create User but User cannot create SuperAdmin
I have created a function checkHierarchy and import it to different modules wherever required and explicitly checked it like this
commonfile.ts
function checkHierarchy(rolePriority1, rolePriority2) {
return true // if can create
return false // cannot create
}
Another file user.ts
import checkHierarchy from common
function createUser() {
const status = checkHierarchy(rp1 , rp2)
if(!status) throw err(Dont have permission to create)
userRepository.create(user)
}
I want to know is there any technique in nest js so that i can perform operation like this
this.checkHierarchy().userRepository.create(User)
#if checkHierarchy method return false then entire operation fails.
I'm trying to create a Prestashop Module which when a user is created, I can get all his information automatically using ActionCustomerAccountAdd, this event return ($params), but I don't know the structure of the object params for getting the data needed
I tried to create hookActionCustomerAccountAdd which get params, I was able to get just the email of the customer $params['newCustomer']->email, but I can't get the first name and last name and the password
// Will be executed each times actionCustomerAccountAdd is triggered
public function hookActionCustomerAccountAdd($params)
{
// $params is an array set by PrestaShop which contains the
// hook data (here, the customer details
$this->CustomerAdd($params['newCustomer']->email);
/* $json_output = json_decode($params,true);
var_dump($json_output) ;
echo "Works";
*/
}
public function CustomerAdd($mail){
$myObj->userx->UserID = 0;
$myObj->userx->Username = "NameUser";
$myObj->userx->Password ="Password";
$myObj->userx->Fname ="Fname";
$myObj->userx->Lname= "Lname";
$myObj->userx->Mail= $mail;
$myObj->username= "evdokimosk";
$myObj->password="123425";
}
I expect to get all data I need like first name, last name but I don't know what is inside the $params
$params['newCustomer'] is the object of the client, so you can retrieve customer information: :
$firstname = $params['newCustomer']->firstname;
$lastname = $params['newCustomer']->lastname;
....
Regards
I have to loop through all Rows in a table that contain a user field. I have to retrieve those users and do nasty stuff with them:
private void GetUsrInfo(FieldUserValue user, ClientContext clientContext) {
int id=user.LookupId;
Web web = clientContext.Web;
User spuser = web.GetUserById(id);
clientContext.Load(spuser);
clientContext.ExecuteQuery();
Mail = spuser.Email;
}
This works. However these are "old" entries and a lot of these persons do not even exist anymore. The user-field still contains the data of that now abandoned user, but when I try to retrieve the userdata by GetUserById() I retrieve the following exception:
Microsoft.SharePoint.Client.ServerException: User cannot be found.
at
Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream
responseStream) at
Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
Currently I just catch these Exceptions and proceed to the next user.
But this is bad and very slow.
Is there a more smart way? Anything like "if web.UserExists(id)..."?
EDIT
One possible way to check whether or not the user exists, without throwing an error or creating a new user (as result of the web.EnsureUser(#"domain\username") method) is to load the complete collection of users locally and use a LINQ statement to lookup the user by Id.
For example:
UserCollection collUser = ctx.Web.SiteUsers;
ctx.Load(collUser);
ctx.ExecuteQuery();
var user = collUser.Cast<User>().FirstOrDefault(u => u.Id == 1);
if (null != user)
{
Console.WriteLine("User: {0} Login name: {1} Email: {2}",
user.Title, user.LoginName, user.Email);
}
If there is a record where the ID == 1, it will be returned, if not the return value will be null.
Depending on the number of users in the site, this may have performance concerns, however, based on the number of exceptions you expect to generate checking the user ID, this solution may be feasible.
Reference: Csom or rest to verify user
I'm building a custom workflow where all users that are members of a specific role will receive email notifications depending on certain state changes. I've begun fleshing out e-mail templates via Sitecore items with replaceable tokens, but I'm struggling to find a way to allow the setting of the recipient role in Sitecore. I'd like to avoid having users enter a string representation of the role, so a droplink would be ideal if there were a way to populate it with the various roles defined in sitecore. Bonus points if I can filter the roles that populate the droplink.
I'm aware that users/roles/domains aren't defined as items in the content tree, so how exactly does one go about configuring this droplink?
Sitecore 6.5.
I'm not sure if there is a module for this already made, but you can use this technique: http://newguid.net/sitecore/2013/coded-field-datasources-in-sitecore/
It explains how you can use a class as data source. So you could create a class that lists all user roles.
You might want to take a look at http://sitecorejunkie.com/2012/12/28/have-a-field-day-with-custom-sitecore-fields/ which presents a multilist to allow you to select a list of users.
Also take a look at the Workflow Escaltor Module form which you can borrow the AccountSelector control which allows you to select either individual person or roles.
This is the module I previously used to do this exact thing. The following code gets all the unique email addresses of users and only for those users that have read access to the item (it was a multisite implementation, the roles were restricted to each site but the workflow was shared).
protected override List<string> GetRecipientList(WorkflowPipelineArgs args, Item workflowItem)
{
Field recipientsField = workflowItem.Fields["To"];
Error.Assert((recipientsField != null || !string.IsNullOrEmpty(recipientsField.Value)), "The 'To' field is not specified in the mail action item: " + workflowItem.Paths.FullPath);
List<string> recepients = GetEmailsForUsersAndRoles(recipientsField, args);
if (recepients.Count == 0)
Log.Info("There are no users with valid email addresses to notify for item submission: " + workflowItem.Paths.FullPath);
return recepients;
}
//Returns unique email addresses of users that correspond to the selected list of users/roles
private List<string> GetEmailsForUsersAndRoles(Field field, WorkflowPipelineArgs args)
{
List<string> emails = new List<string>();
List<User> allUsers = new List<User>();
AccountSelectorField accountSelectorField = new AccountSelectorField(field);
List<Account> selectedRoles = accountSelectorField.GetSelectedAccountsByType(AccountType.Role);
List<Account> selectedUsers = accountSelectorField.GetSelectedAccountsByType(AccountType.User);
foreach (var role in selectedRoles)
{
var users = RolesInRolesManager.GetUsersInRole(Role.FromName(role.Name), true).ToList();
if (users.Any())
allUsers.AddRange(users);
}
selectedUsers.ForEach(i => allUsers.Add(Sitecore.Security.Accounts.User.FromName(i.Name, false)));
foreach (var user in allUsers)
{
if (user == null || !args.DataItem.Security.CanRead(user)) continue; //move on if user does not have access to item
if (!emails.Contains(user.Profile.Email.ToLower()))
{
if(user.Profile.Email != null && !string.IsNullOrEmpty(user.Profile.Email.Trim()))
emails.Add(user.Profile.Email.ToLower());
else
Log.Error("No email address setup for user: " + user.Name);
}
}
return emails;
}