Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 5CC35200CEC for ; Mon, 21 Aug 2017 14:15:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5BAFF1650F4; Mon, 21 Aug 2017 12:15:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 54F081650F3 for ; Mon, 21 Aug 2017 14:15:13 +0200 (CEST) Received: (qmail 56218 invoked by uid 500); 21 Aug 2017 12:15:11 -0000 Mailing-List: contact commits-help@fineract.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@fineract.apache.org Delivered-To: mailing list commits@fineract.apache.org Received: (qmail 56209 invoked by uid 99); 21 Aug 2017 12:15:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Aug 2017 12:15:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 732ADDFBFF; Mon, 21 Aug 2017 12:15:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: nazeer1100126@apache.org To: commits@fineract.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: fineract git commit: Self user role and report access Date: Mon, 21 Aug 2017 12:15:11 +0000 (UTC) archived-at: Mon, 21 Aug 2017 12:15:14 -0000 Repository: fineract Updated Branches: refs/heads/develop 6e95f88d7 -> df16dc3ca Self user role and report access Project: http://git-wip-us.apache.org/repos/asf/fineract/repo Commit: http://git-wip-us.apache.org/repos/asf/fineract/commit/df16dc3c Tree: http://git-wip-us.apache.org/repos/asf/fineract/tree/df16dc3c Diff: http://git-wip-us.apache.org/repos/asf/fineract/diff/df16dc3c Branch: refs/heads/develop Commit: df16dc3cadb35f0552395d2741b63382701b6f3f Parents: 6e95f88 Author: Nazeer Hussain Shaik Authored: Mon Aug 21 17:42:19 2017 +0530 Committer: Nazeer Hussain Shaik Committed: Mon Aug 21 17:42:19 2017 +0530 ---------------------------------------------------------------------- .../registration/SelfServiceApiConstants.java | 1 + ...iceRegistrationWritePlatformServiceImpl.java | 12 +++- .../runreport/SelfRunReportApiResource.java | 60 ++++++++++++++++++++ .../domain/RoleRepository.java | 3 + .../exception/RoleNotFoundException.java | 4 ++ .../core_db/V335__self_service_user_role.sql | 20 +++++++ 6 files changed, 99 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/fineract/blob/df16dc3c/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/SelfServiceApiConstants.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/SelfServiceApiConstants.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/SelfServiceApiConstants.java index 2362523..966211b 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/SelfServiceApiConstants.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/SelfServiceApiConstants.java @@ -44,5 +44,6 @@ public class SelfServiceApiConstants { authenticationTokenParamName)); public static final Object[] SUPPORTED_AUTHENTICATION_MODE_PARAMETERS = new Object[] {emailModeParamName, mobileModeParamName}; + public static final String SELF_SERVICE_USER_ROLE = "Self Service User"; } http://git-wip-us.apache.org/repos/asf/fineract/blob/df16dc3c/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/service/SelfServiceRegistrationWritePlatformServiceImpl.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/service/SelfServiceRegistrationWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/service/SelfServiceRegistrationWritePlatformServiceImpl.java index 7797b2f..9952dcf 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/service/SelfServiceRegistrationWritePlatformServiceImpl.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/registration/service/SelfServiceRegistrationWritePlatformServiceImpl.java @@ -58,7 +58,9 @@ import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.PasswordValidationPolicy; import org.apache.fineract.useradministration.domain.PasswordValidationPolicyRepository; import org.apache.fineract.useradministration.domain.Role; +import org.apache.fineract.useradministration.domain.RoleRepository; import org.apache.fineract.useradministration.domain.UserDomainService; +import org.apache.fineract.useradministration.exception.RoleNotFoundException; import org.apache.fineract.useradministration.service.AppUserReadPlatformService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataIntegrityViolationException; @@ -85,6 +87,7 @@ public class SelfServiceRegistrationWritePlatformServiceImpl implements SelfServ private SmsMessageScheduledJobService smsMessageScheduledJobService; private final SmsCampaignDropdownReadPlatformService smsCampaignDropdownReadPlatformService; private final AppUserReadPlatformService appUserReadPlatformService; + private final RoleRepository roleRepository; @Autowired public SelfServiceRegistrationWritePlatformServiceImpl(final SelfServiceRegistrationRepository selfServiceRegistrationRepository, @@ -94,7 +97,7 @@ public class SelfServiceRegistrationWritePlatformServiceImpl implements SelfServ final UserDomainService userDomainService, final GmailBackedPlatformEmailService gmailBackedPlatformEmailService, final SmsMessageRepository smsMessageRepository, SmsMessageScheduledJobService smsMessageScheduledJobService, final SmsCampaignDropdownReadPlatformService smsCampaignDropdownReadPlatformService, - final AppUserReadPlatformService appUserReadPlatformService) { + final AppUserReadPlatformService appUserReadPlatformService,final RoleRepository roleRepository) { this.selfServiceRegistrationRepository = selfServiceRegistrationRepository; this.fromApiJsonHelper = fromApiJsonHelper; this.selfServiceRegistrationReadPlatformService = selfServiceRegistrationReadPlatformService; @@ -106,6 +109,7 @@ public class SelfServiceRegistrationWritePlatformServiceImpl implements SelfServ this.smsMessageScheduledJobService = smsMessageScheduledJobService; this.smsCampaignDropdownReadPlatformService = smsCampaignDropdownReadPlatformService; this.appUserReadPlatformService = appUserReadPlatformService; + this.roleRepository = roleRepository; } @Override @@ -262,6 +266,12 @@ public class SelfServiceRegistrationWritePlatformServiceImpl implements SelfServ final Collection authorities = new ArrayList<>(); authorities.add(new SimpleGrantedAuthority("DUMMY_ROLE_NOT_USED_OR_PERSISTED_TO_AVOID_EXCEPTION")); final Set allRoles = new HashSet<>(); + Role role = this.roleRepository.getRoleByName(SelfServiceApiConstants.SELF_SERVICE_USER_ROLE); + if(role != null){ + allRoles.add(role); + }else{ + throw new RoleNotFoundException(SelfServiceApiConstants.SELF_SERVICE_USER_ROLE); + } List clients = new ArrayList<>(Arrays.asList(client)); User user = new User(selfServiceRegistration.getUsername(), selfServiceRegistration.getPassword(), authorities); AppUser appUser = new AppUser(client.getOffice(), user, allRoles, selfServiceRegistration.getEmail(), client.getFirstname(), http://git-wip-us.apache.org/repos/asf/fineract/blob/df16dc3c/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/runreport/SelfRunReportApiResource.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/runreport/SelfRunReportApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/runreport/SelfRunReportApiResource.java new file mode 100644 index 0000000..b86d176 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/runreport/SelfRunReportApiResource.java @@ -0,0 +1,60 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.fineract.portfolio.self.runreport; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; + +import org.apache.fineract.infrastructure.dataqueries.api.RunreportsApiResource; +import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Path("/self/runreports") +@Component +@Scope("singleton") +public class SelfRunReportApiResource { + + private final PlatformSecurityContext context; + private final RunreportsApiResource runreportsApiResource; + + @Autowired + public SelfRunReportApiResource(final PlatformSecurityContext context, final RunreportsApiResource runreportsApiResource) { + this.context = context; + this.runreportsApiResource = runreportsApiResource; + } + + @GET + @Path("{reportName}") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON, "text/csv", "application/vnd.ms-excel", "application/pdf", "text/html" }) + public Response runReport(@PathParam("reportName") final String reportName, @Context final UriInfo uriInfo) { + this.context.authenticatedUser(); + return this.runreportsApiResource.runReport(reportName, uriInfo); + } + +} http://git-wip-us.apache.org/repos/asf/fineract/blob/df16dc3c/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/RoleRepository.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/RoleRepository.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/RoleRepository.java index 07e8305..dd2c1c9 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/RoleRepository.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/domain/RoleRepository.java @@ -27,5 +27,8 @@ public interface RoleRepository extends JpaRepository, JpaSpecificat @Query("SELECT COUNT(a) FROM AppUser a JOIN a.roles r WHERE r.id = :roleId AND a.deleted = false") Integer getCountOfRolesAssociatedWithUsers(@Param("roleId") Long roleId); + + @Query("SELECT role FROM Role role WHERE role.name = :name") + Role getRoleByName(@Param("name") String name); } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/fineract/blob/df16dc3c/fineract-provider/src/main/java/org/apache/fineract/useradministration/exception/RoleNotFoundException.java ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/java/org/apache/fineract/useradministration/exception/RoleNotFoundException.java b/fineract-provider/src/main/java/org/apache/fineract/useradministration/exception/RoleNotFoundException.java index e0b867c..1635311 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/useradministration/exception/RoleNotFoundException.java +++ b/fineract-provider/src/main/java/org/apache/fineract/useradministration/exception/RoleNotFoundException.java @@ -28,4 +28,8 @@ public class RoleNotFoundException extends AbstractPlatformResourceNotFoundExcep public RoleNotFoundException(final Long id) { super("error.msg.role.id.invalid", "Role with identifier " + id + " does not exist", id); } + + public RoleNotFoundException(final String name) { + super("error.msg.role.name.invalid", "Role with name " + name + " does not exist", name); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/fineract/blob/df16dc3c/fineract-provider/src/main/resources/sql/migrations/core_db/V335__self_service_user_role.sql ---------------------------------------------------------------------- diff --git a/fineract-provider/src/main/resources/sql/migrations/core_db/V335__self_service_user_role.sql b/fineract-provider/src/main/resources/sql/migrations/core_db/V335__self_service_user_role.sql new file mode 100644 index 0000000..029789a --- /dev/null +++ b/fineract-provider/src/main/resources/sql/migrations/core_db/V335__self_service_user_role.sql @@ -0,0 +1,20 @@ +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you under the Apache License, Version 2.0 (the +-- "License"); you may not use this file except in compliance +-- with the License. You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, +-- software distributed under the License is distributed on an +-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +-- KIND, either express or implied. See the License for the +-- specific language governing permissions and limitations +-- under the License. +-- + +INSERT INTO `m_role` (`name`, `description`, `is_disabled`) VALUES ('Self Service User', 'self service user role', 1); \ No newline at end of file