diff --git a/data/SITreg.hdbdd b/data/SITreg.hdbdd index 9b55f9d..85752b7 100644 --- a/data/SITreg.hdbdd +++ b/data/SITreg.hdbdd @@ -163,15 +163,4 @@ context SITreg { PrintStatus : String(1) not null; // Q = queued, S = sent, P = printed History : HistoryT; }; - - entity RegisterAsOrganizerQueue { - key EventID : BusinessKey not null default 0; - key UserName : UserT; - Organizer : association to SITreg.Organizer {UserName}; - Status : String(1); // See enum RegisterAsOrganizerStatus // A = Accepted / R = Rejected / P = Pending - RequestTimeStamp : UTCTimestamp; - StatusSetTimeStamp : UTCTimestamp; - History : HistoryT; - }; - }; \ No newline at end of file diff --git a/odataorganizer/confirmOrganizer.xsjs b/odataorganizer/confirmOrganizer.xsjs new file mode 100644 index 0000000..262687f --- /dev/null +++ b/odataorganizer/confirmOrganizer.xsjs @@ -0,0 +1,58 @@ +/* + + Copyright 2016 Gregor Wolf + + Licensed 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. + +*/ + +var XSDS = $.import("sap.hana.xs.libs.dbutils", "xsds"); + +function confirmOrganizer() { + var body; + var conn; + $.response.status = $.net.http.OK; + $.response.contentType = "application/json"; + try { + var UserName = ""; + if($.request.method === $.net.http.GET) { + UserName = decodeURIComponent($.request.parameters.get("UserName")); + } else { + var content = $.request.body.asString(); + var postData = JSON.parse(content); + UserName = postData.UserName; + } + var Organizer = XSDS.$importEntity("com.sap.sapmentors.sitreg.data", "SITreg.Organizer", {}, { $schemaName: "SITREG" }); + var existingOrganizer = Organizer.$get({ UserName: UserName }); + existingOrganizer.Status = 'A'; + existingOrganizer.History.ChangedBy = $.session.getUsername(); + existingOrganizer.History.ChangedAt = new Date(); + existingOrganizer.$save(); + XSDS.Transaction.$commit(); + + conn = $.hdb.getConnection(); + var grantOrganizerRoleToUser = conn.loadProcedure("SITREG", "com.sap.sapmentors.sitreg.odataorganizer.procedures::GrantOrganizerRoleToUser"); + var grantOrganizerRoleToUserResult = grantOrganizerRoleToUser(UserName); + body = JSON.stringify(grantOrganizerRoleToUserResult); + } catch (e) { + $.response.contentType = "text/json"; + body = '{ "error": "' + e.toString() + '"}'; + $.response.status = $.net.http.BAD_REQUEST; + } + if (conn) { + conn.close(); + } + $.response.setBody( body ); +} + +confirmOrganizer(); \ No newline at end of file diff --git a/odataorganizer/service.xsodata b/odataorganizer/service.xsodata index 4d8b251..4da70f5 100644 --- a/odataorganizer/service.xsodata +++ b/odataorganizer/service.xsodata @@ -105,4 +105,9 @@ service { association "Participant_Ticket" principal "Participants"("ID") multiplicity "1" dependent "Ticket"("ParticipantID") multiplicity "1"; + + "com.sap.sapmentors.sitreg.data::SITreg.Organizer" as "Organizer" + create forbidden + update forbidden + delete forbidden; } \ No newline at end of file diff --git a/odataparticipant/procedures/RegisterAsOrganizerCreate.hdbprocedure b/odataparticipant/procedures/RegisterAsOrganizerCreate.hdbprocedure index 3f56516..02a704e 100644 --- a/odataparticipant/procedures/RegisterAsOrganizerCreate.hdbprocedure +++ b/odataparticipant/procedures/RegisterAsOrganizerCreate.hdbprocedure @@ -36,7 +36,6 @@ BEGIN DECLARE lv_CreatedAt string; DECLARE lv_ChangedBy string; DECLARE lv_ChangedAt string; - DECLARE lv_now string; SELECT * INTO lv_UserName, @@ -66,22 +65,20 @@ BEGIN lv_CreatedBy = lv_UserName; lv_ChangedBy = lv_UserName; - lv_now = CURRENT_TIMESTAMP; - INSERT INTO "com.sap.sapmentors.sitreg.data::SITreg.Organizer" VALUES( - UCASE( lv_UserName ), - lv_FirstName, - lv_LastName, - lv_Email, - lv_MobilePhone, - UCASE( lv_Status ), - CURRENT_TIMESTAMP, + UCASE( lv_UserName ), + lv_FirstName, + lv_LastName, + lv_Email, + lv_MobilePhone, + UCASE( lv_Status ), + CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, lv_CreatedBy, CURRENT_TIMESTAMP, lv_ChangedBy, - lv_now + CURRENT_TIMESTAMP ); IF 1 = 2 THEN error = SELECT 400 AS http_status_code, diff --git a/roles/admin.hdbrole b/roles/admin.hdbrole index ed82c9f..393a07a 100644 --- a/roles/admin.hdbrole +++ b/roles/admin.hdbrole @@ -9,7 +9,6 @@ role com.sap.sapmentors.sitreg.roles::admin { sql object com.sap.sapmentors.sitreg.data::SITreg.Ticket: SELECT, INSERT, UPDATE, DELETE; sql object com.sap.sapmentors.sitreg.data::SITreg.Organizer: SELECT, INSERT, UPDATE, DELETE; sql object com.sap.sapmentors.sitreg.data::SITreg.PrintQueue: SELECT, INSERT, UPDATE, DELETE; - sql object com.sap.sapmentors.sitreg.data::SITreg.RegisterAsOrganizerQueue: SELECT, INSERT, UPDATE, DELETE; sql object com.sap.sapmentors.sitreg.odataparticipant.procedures::TicketCreate: EXECUTE; sql object com.sap.sapmentors.sitreg.odataadmin.procedures::TicketCreateMissing: EXECUTE; sql object com.sap.sapmentors.sitreg.odataadmin.procedures::ParticipantUpdateWaitingList: EXECUTE; diff --git a/roles/organizer.hdbrole b/roles/organizer.hdbrole index 083a019..3fe88bf 100644 --- a/roles/organizer.hdbrole +++ b/roles/organizer.hdbrole @@ -26,6 +26,8 @@ role com.sap.sapmentors.sitreg.roles::organizer { sql object com.sap.sapmentors.sitreg.odataorganizer.procedures::ParticipantsRead: SELECT; sql object com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketRead: SELECT; sql object com.sap.sapmentors.sitreg.odataorganizer.procedures::UpdateWaitingList: EXECUTE; + // Organizer + sql object com.sap.sapmentors.sitreg.data::SITreg.Organizer: SELECT, UPDATE; application privilege: "com.sap.sapmentors.sitreg.odataorganizer::organizer"; } diff --git a/roles/participant.hdbrole b/roles/participant.hdbrole index 74ac306..dbc0046 100644 --- a/roles/participant.hdbrole +++ b/roles/participant.hdbrole @@ -33,7 +33,6 @@ role com.sap.sapmentors.sitreg.roles::participant { sql object com.sap.sapmentors.sitreg.odataparticipant.procedures::RegisterAsOrganizerCreate: EXECUTE; sql object com.sap.sapmentors.sitreg.odataparticipant.procedures::RegisterAsOrganizerRead: SELECT; - sql object com.sap.sapmentors.sitreg.data::SITreg.RegisterAsOrganizerQueue: INSERT, UPDATE; sql object com.sap.sapmentors.sitreg.data::SITreg.Organizer: INSERT, UPDATE; application privilege: "com.sap.sapmentors.sitreg.odataparticipant::participant"; diff --git a/test/060_CoOrganizerReadParticipantsTest.xsjslib b/test/060_CoOrganizerReadParticipantsTest.xsjslib index a12892d..990a504 100644 --- a/test/060_CoOrganizerReadParticipantsTest.xsjslib +++ b/test/060_CoOrganizerReadParticipantsTest.xsjslib @@ -6,6 +6,7 @@ var loginResult; var header; var eventUri; var eventID; +var UserName; describe("Co-Organizer", function() { @@ -43,6 +44,38 @@ describe("Co-Organizer", function() { expect(body.d.RSVP).toBe("N"); }); + it("should read participants that requested the organizer role", function() { + var url = parameters.odataOrganizer + "Organizer?$filter=Status eq 'P'"; + var response = jasmine.callHTTPService( + encodeURI(url), + $.net.http.GET, + undefined, + header, + loginResult.cookies + ); + var body = helper.getResponseBody(response); + // jasmine.log(JSON.stringify(body)); + expect(response.status).toBe(200); + UserName = body.d.results[0].UserName; + expect(UserName).not.toBe(null); + }); + + it("should confirm the participant that sent an organizer request", function() { + var check = { + "UserName": UserName + }; + var response = jasmine.callHTTPService( + "/com/sap/sapmentors/sitreg/odataorganizer/confirmOrganizer.xsjs", + $.net.http.POST, + JSON.stringify(check), + header, + loginResult.cookies + ); + expect(response.status).toBe($.net.http.OK); + var body = helper.getResponseBody(response); + // jasmine.log(JSON.stringify(body)); + }); + it("should logout", function() { helper.logout(loginResult.csrf, loginResult.cookies); helper.checkSession(); diff --git a/test/070_ParticipantConfirmedForSmallEventTest.xsjslib b/test/070_ParticipantConfirmedForSmallEventTest.xsjslib index 0d3d7c5..6dc8dc3 100644 --- a/test/070_ParticipantConfirmedForSmallEventTest.xsjslib +++ b/test/070_ParticipantConfirmedForSmallEventTest.xsjslib @@ -14,7 +14,7 @@ describe("Participant", function() { loginResult = helper.getCSRFtokenAndLogin(username, helper.newpwd); header = helper.prepareRequestHeader(loginResult.csrf); }); - + it("should read Small-Event and check for waiting status", function() { var response = jasmine.callHTTPService( parameters.readEventsServiceParticipant, @@ -64,6 +64,19 @@ describe("Participant", function() { expect(body.d.RSVP).toBe("Y"); }); + it("should try to read organizer OData service as he is now also an organizer", function() { + var eventUriOrganizer = eventUri.replace("odataparticipant", "odataorganizer"); + + var response = jasmine.callHTTPService( + eventUriOrganizer, + $.net.http.GET, + undefined, + header, + loginResult.cookies + ); + expect(response.status).toBe(200); + }); + it("should logout PARTICIPANT", function() { helper.logout(loginResult.csrf, loginResult.cookies); helper.checkSession(); diff --git a/test/090_ReceptionistTest.xsjslib b/test/090_ReceptionistTest.xsjslib index 387438d..3669c7a 100644 --- a/test/090_ReceptionistTest.xsjslib +++ b/test/090_ReceptionistTest.xsjslib @@ -20,7 +20,13 @@ describe("Participant", function() { }); it("should read the event ID", function() { - var response = jasmine.callHTTPService(parameters.readEventsServiceParticipant, $.net.http.GET, undefined, header, loginResult.cookies); + var response = jasmine.callHTTPService( + parameters.readEventsServiceParticipant, + $.net.http.GET, + undefined, + header, + loginResult.cookies + ); expect(response.status).toBe($.net.http.OK); var body = helper.getResponseBody(response); var smallEventIndex = body.d.results.length - 1; diff --git a/test/parameters.xsjslib b/test/parameters.xsjslib index 2935274..c76fb23 100644 --- a/test/parameters.xsjslib +++ b/test/parameters.xsjslib @@ -1,2 +1,3 @@ var readEventsService = encodeURI("/com/sap/sapmentors/sitreg/odataorganizer/service.xsodata/Events?$filter=History.CreatedBy eq 'ORGANIZER'"); -var readEventsServiceParticipant = encodeURI("/com/sap/sapmentors/sitreg/odataparticipant/service.xsodata/Events"); \ No newline at end of file +var readEventsServiceParticipant = encodeURI("/com/sap/sapmentors/sitreg/odataparticipant/service.xsodata/Events"); +var odataOrganizer = "/com/sap/sapmentors/sitreg/odataorganizer/service.xsodata/"; \ No newline at end of file diff --git a/test/procedures/setup.hdbprocedure b/test/procedures/setup.hdbprocedure index ee8a63e..8d3a2ff 100644 --- a/test/procedures/setup.hdbprocedure +++ b/test/procedures/setup.hdbprocedure @@ -41,8 +41,6 @@ BEGIN DELETE FROM "com.sap.sapmentors.sitreg.data::SITreg.Device" WHERE "History.CreatedBy" = 'ORGANIZER' OR "History.CreatedBy" = 'COORGANIZER'; - DELETE FROM "com.sap.sapmentors.sitreg.data::SITreg.RegisterAsOrganizerQueue" - WHERE "History.CreatedBy" = 'PARTICIPANT'; DELETE FROM "com.sap.sapmentors.sitreg.data::SITreg.Organizer" WHERE "History.CreatedBy" = 'PARTICIPANT';