1. Sebastian Sebastian
  2. scm-manager
  3. Issues

Issues

Issue #294 new

Notification email addresses

Stefanos Kalantzis
created an issue

Hi!

First of all thanks for this project, and congrats for the s/w design :)

I would like to suggest a more "formal" way for the contact list of the notification settings.

Instead of adding email-addresses, to add usernames (like it's done on the Permissions tab of a repository configuration). Then send the email to the mail field of each user.

Also a check-button to enable sending to all users that have permissions would be very useful (instead of adding them again on the notification tab).

I could help to write the changes, but I looked at the notify-plugin, and I don't know how to get the users. Didn't spend much time though.. considering someone here could inform me.

Best regards, Stefanos

Comments (1)

  1. Sebastian Sebastian repo owner

    Hi, I've not much time at the moment, so it would be great if you could do some work for this.

    Collect users which has permissions to a repository is a little bit difficult. Here is a sample:

    public class NotifyHook extends PostReceiveRepositoryHook
    {
      private AdministrationContext adminContext;
      private UserManager userManager;
      private GroupManager groupManager;
    
      @Inject
      public NotifyHook(AdministrationContext adminContext, UserManager userManager,
        GroupManager groupManager)
      {
        this.adminContext = adminContext;
        this.userManager = userManager;
        this.groupManager = groupManager;
      }
    
      @Override
      public void onEvent(RepositoryHookEvent event)
      {
        MailAddressCollector collector = new MailAddressCollector(userManager,
          groupManager, event.getRepository());
        adminContext.runAsAdmin(collector);
        Set<String> addresses = collector.getAddresses();
        // send mail
      }
    }
    
    public class MailAddressCollector implements PrivilegedAction
    {
      private Set<String> addresses = Sets.newHashSet();
      private UserManager userManager;
      private GroupManager groupManager;
      private Repository repository;
    
      public MailAddressCollector(UserManager userManager, GroupManager groupManager,
        Repository repository)
      {
        this.userManager = userManager;
        this.groupManager = groupManager;
        this.repository = repository;
      }
    
      @Override
      public void run()
      {
        List<Permission> permissions = repository.getPermissions();
        for ( Permission p : permissions ){
          String name = p.getName();
          if (p.isGroupPermission()){
            collectGroupAddresses(name);
          } else {
            collectUserAddress(name);
          }
        }
      }
    
      private void collectUserAddress(String name){
        User user = userManager.get(name);
        if ( user != null && user.isActive() && ! Strings.isNullOrEmpty(user.getMail()) ){
          addresses.add(user.getMail());
        }
      }
    
      private void collectGroupAddresses(String name){
        Group group = groupManager.get(name);
        if ( group != null ){
          for ( String member : group ){
            collectUserAddress(member);
          }
        }
      }
    
      Set<String> getAddresses()
      {
        return addresses;
      }
    }
    

    Note you have to collect the addresses in an administrative context, because it is possible that the user who makes the push has not enough permissions to read users or groups. This sample does not collect users from external groups such as ldap, pam and so on.

  2. Log in to comment